TIL: RN | Android 다크모드 차단 - 221223

Lumpen·2022년 12월 23일
0

TIL

목록 보기
213/242

다크모드 차단

android > app > src > main > res > values > styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
      	<!-- Light 를 DayNignt로 변경 시 다크모드 허용 - input text가 하얗게 변한다 -->
        <!-- Customize your theme here. -->
        <item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
        <item name="android:textColor">#000000</item> 
        <item name="android:forceDarkAllowed">false</item>
        <!-- 개발자가 작성한 text만 변경됨.. 사용자 입력은 여전히 white -->
    </style>

</resources>
export const useTheme = () => {
 const isDarkMode = useColorScheme() === 'dark';
 const forceDark = useSelector(state => state.application.force_dark);
 const themeStorage = useSelector(state => state.application.theme);
 const listTheme = ThemeSupport.filter(item => item.theme == themeStorage);
 const theme = listTheme.length > 0 ? listTheme[0] : DefaultTheme;

 if (forceDark) {
   return {theme: theme.dark, colors: theme.dark.colors}; <--- change here
 }
 if (forceDark === false) {
   return {theme: theme.light, colors: theme.light.colors};
 }
 return isDarkMode
   ? {theme: theme.dark, colors: theme.dark.colors} <----- change here
   : {theme: theme.light, colors: theme.light.colors};
};
profile
떠돌이 생활을 하는. 실업자는 아니지만, 부랑 생활을 하는

0개의 댓글