반응형
    
    
    
  
														Notice
														
												
											
												
												
													Recent Posts
													
											
												
												
													Recent Comments
													
											
												
												
													Link
													
											
									| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | 
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 
| 23 | 24 | 25 | 26 | 27 | 28 | 29 | 
| 30 | 
													Tags
													
											
												
												- 사이드프로젝트
 - ReactNative
 - Instagrame clone
 - 전국국밥
 - 클론코딩
 - clone coding
 - 조코딩
 - Reinforcement Learning
 - selenium
 - Ros
 - 딥러닝
 - 카트폴
 - App
 - 강화학습 기초
 - 데이터분석
 - 리액트네이티브
 - 강화학습
 - JavaScript
 - GYM
 - kaggle
 - TeachagleMachine
 - FirebaseV9
 - pandas
 - coding
 - React
 - redux
 - expo
 - 앱개발
 - python
 - 머신러닝
 
													Archives
													
											
												
												- Today
 
- Total
 
qcoding
[ReactNative_study_6]Theme Provider 사용하기 본문
반응형
    
    
    
  - Theme를 변경하기 위해 기본적으로 background color / text color들을 변경한다.
이걸 위해서 $(props=>props.lgiht?: "light":"dark") 이런 식으로 매번 모든 컴포넌트에서 사용하면 코드가 복잡해지고
헷갈리게 된다. 이를 위해서 <ThemeProvider>를 App.js에서 전체를 묶어줘서 어디에서나 받을 수 있게 사용한다.
1) styled 되어있는 theme js를 만든다.
export const lightTheme={
  BgColor:"=",
  textColor:"",
}
export const darkTheme={
  BgColor:"#",
  textColor:"#",
}
2) App.js에서 받아온다.
import { lightTheme,darkTheme } from './styled';
// hook을 이용하여 현재 theme를 받아온다.
 
 const isLight=useColorScheme()==="Light";
// 그리고 return에서 ThemeProvider를 사용한다.
  return (
    <ThemeProvider theme={isLight  ?  lightTheme  :  darkTheme}>
      <NavigationContainer>
        <Root></Root>
      </NavigationContainer>
    </ThemeProvider>
  );
3) 이제 App.js 내부에 있는 어디서든 theme 를 pros로 받아 올수 있다.
const Title =styled.Text`
    color:${props=>props.theme.textColor};
`;
위와 같이 하면 한번만 theme를 불러오고 그 아래 컴포넌트에서는 theme 별로 다르게 다 사용할 수 있다.
반응형
    
    
    
  'ReactNative' 카테고리의 다른 글
| [ReactNative_study_8]ScrollView / Flat List (0) | 2021.11.28 | 
|---|---|
| [ReactNative_study_7]Scroll View 사용 (0) | 2021.11.24 | 
| [ReactNative_study_5]Stack / Tab navigator 결합 (0) | 2021.11.23 | 
| [ReactNative_study_4]Stack Navigator (0) | 2021.11.23 | 
| [ReactNative_study_3] Navigator_Tabs / Color mode (0) | 2021.11.23 | 
			  Comments