colors[theme]을 못읽는 이유
import React, {ReactNode} from 'react';
import {
Pressable,
StyleSheet,
Text,
PressableProps,
Dimensions,
View,
StyleProp,
ViewStyle,
TextStyle,
} from 'react-native';
import {colors} from '../../constants';
import useThemeStore from '@/store/useThemeStore';
import {ThemeMode} from '@/types/common';
interface CustomButtonProps extends PressableProps {
label: string;
variant?: 'filled' | 'outlined';
size?: 'large' | 'medium';
inValid?: boolean;
style?: StyleProp<ViewStyle>;
textStyle?: StyleProp<TextStyle>;
icon?: ReactNode;
}
const deviceHeight = Dimensions.get('screen').height;
function CustomButton({
label,
variant = 'filled',
size = 'large',
inValid = false,
style = null,
textStyle = null,
icon = null,
...props
}: CustomButtonProps) {
const {theme} = useThemeStore();
const styles = styling(theme);
// 여기서는 제대로 출력이 됩니다. 값이 제대로 읽힙니다.
console.log(colors[theme].PINK_700);
return (
<Pressable
disabled={inValid}
style={({pressed}) => [
styles.container,
pressed ? styles[`${variant}Pressed`] : styles[variant],
inValid && styles.inValid,
style,
]}
{...props}>
<View style={styles[size]}>
{icon}
<Text style={[styles.text, styles[`${variant}Text`], textStyle]}>
{label}
</Text>
</View>
</Pressable>
);
}
const styling = (theme: ThemeMode) =>
StyleSheet.create({
container: {
borderRadius: 3,
justifyContent: 'center',
flexDirection: 'row',
},
inValid: {
opacity: 0.5,
},
filled: {
backgroundColor: colors[theme].PINK_700,
},
outlined: {
borderColor: colors[theme].PINK_700,
borderWidth: 1,
},
filledPressed: {
backgroundColor: colors[theme].PINK_500,
},
outlinedPressed: {
borderColor: colors[theme].PINK_700,
borderWidth: 1,
opacity: 0.5,
},
large: {
width: '100%',
paddingVertical: deviceHeight > 700 ? 15 : 10,
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'row',
gap: 5,
},
medium: {
width: '50%',
paddingVertical: deviceHeight > 700 ? 12 : 8,
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'row',
gap: 5,
},
text: {
fontSize: 16,
fontWeight: '700',
},
filledText: {
color: colors[theme].WHITE,
},
outlinedText: {
color: colors[theme].PINK_700,
},
});
export default CustomButton;
console.log(colors[theme].PINK_700); 이렇게 출력할 경우, 제대로 아래와 같이 출력이 됩니다만 스타일은 제대로 읽어오지 않습니다. 이 부분에 대해서 알고 싶습니다.
BUNDLE ./index.js
LOG Running "MatzipApp" with {"rootTag":171,"initialProps":{"concurrentRoot":false}}
LOG light
LOG #C63B64
LOG #C63B64
LOG #C63B64
ERROR TypeError: Cannot read property 'PINK_700' of undefined
This error is located at:
in CustomButton (created by ErrorBoundary)
in RCTView (created by View)
in View (created by ErrorBoundary)
in ErrorBoundary (created by RetryErrorBoundary)
in RetryErrorBoundary (created by RootNavigator)
in RootNavigator (created by App)
in EnsureSingleNavigator
in BaseNavigationContainer
in ThemeProvider
in NavigationContainerInner (created by App)
in _QueryClientProvider (created by App)
in App
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in MatzipApp(RootComponent), js engine: hermes
ERROR TypeError: Cannot read property 'WHITE' of undefined
This error is located at:
in RetryErrorBoundary (created by RootNavigator)
in RootNavigator (created by App)
in EnsureSingleNavigator
in BaseNavigationContainer
in ThemeProvider
in NavigationContainerInner (created by App)
in _QueryClientProvider (created by App)
in App
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in MatzipApp(RootComponent), js engine: hermes
ERROR TypeError: Cannot read property 'WHITE' of undefined
This error is located at:
in RetryErrorBoundary (created by RootNavigator)
in RootNavigator (created by App)
in EnsureSingleNavigator
in BaseNavigationContainer
in ThemeProvider
in NavigationContainerInner (created by App)
in _QueryClientProvider (created by App)
in App
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in MatzipApp(RootComponent), js engine: hermes
ERROR TypeError: Cannot read property 'WHITE' of undefined
https://github.com/dydals3440/MatZip
좀더 정확히 판단을 위하여 제가 커밋한 레포 남겨드립니다!!!
react-native-screens 버전 호환 문제
2
153
1
안드로이드 실행 중 Drawer네비게이션과 MapView 성능 문제
0
103
2
해당 강의 부분은 실제 활용하기에 부족해 제가 해결한 방법입니다.
0
96
1
소스코드가 강의 순서랑 다른가요?
0
72
2
현재 Windows에서 VsCode로 작업 중인데 추후에 IOS도 가능하게 하려면
0
115
2
react-native-fast-image는 react 19 버전에서 설치가 안되나요?
0
209
2
SQL Shell의 역할이 무엇인가요?
0
91
1
혹시 해당 강의에서invalidateQueries를 사용한 이유가 있을까요?
0
79
2
빠르게 실행해보고싶습니다.
0
82
1
강의 수강 순서 관련
0
70
1
애뮬레이터 실행 방법
0
99
2
무료 Apple ID로 실기기 테스트 가능한가요?
0
90
2
ios 실기기 연결
0
70
2
npm run ios에러
0
74
1
10월 삭제 예정인 강의는 이유를 알 수 있을까요?
0
101
1
캘린더 개발 후에 navigation 에 대해서 궁금한 점이 있습니다.
0
51
1
안드로이드 위치 권한 이슈 2가지 문의
0
71
1
지도가 보이려면 음.. 작성해주신 스타일과 다르게
0
74
0
제대로 설치한거같은데 안드로이드랑 ios 둘다 앱실행이 안되는것같아요
0
83
3
강의 내용을 보면 전체적으로 function 함수 키워드를 사용하시는데
0
69
2
강의 3-9 에서 useGetRefreshToken 훅 안에 즉시 함수로 처리하는 이유가 궁금합니다!
0
82
2
사내에서 figma.com 업로드 안되나요?
0
96
1
AWS EC2 + RDS 설정
0
85
2
안드로이드 안켜집니다.
0
91
2





