Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to detect system Light\Dark mode changes in react native? [duplicate]

$
0
0

I've tried using Appearence.addChangeListener withing an useEffect hook in React native to detect changes in system Light/Dark mode, but in Android the listener isn't called when I switch Light/Dark mode via system settings, but it works fine in IOS.

const listener = () => {    console.log('called appearence change');    dispatch(switchColorScheme())  };  useEffect(()=>{    Appearance.addChangeListener(listener)  },[])

How do I make my android app (Appearance API works fine in my IOS app) change color scheme dynamically as the Dark/Light mode is toggled in system settings

To reproduce the issue:

  1. Create a react native app with typescript template: npx react-native init MyApp --template react-native-template-typescript
  2. Call Appearance.AddChangeListener (() => {console.log ("Appearance changed")}) within an useEffect hook
  3. Running it in an android device will not log Appearance changed, but it will log the same in an IOS device

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>