codemotionapps/react-native-dark-mode

Setting the value of `mode` in` DarkModeProvider` has no effect.

Closed this issue · 3 comments

I set the value of mode in DarkModeProvider, it has no effect.

repo

Screen Recording 2020-03-01 at 7 03 30 AM
Are you sure? I just ran it and it seems to be working fine.

But the background color of the main page has not changed.

That's because you're using <DarkModeProvider> in the same place you're already calling hooks. You have two options:

  1. Extract anything but the <DarkModeProvider> and currentMode from the App component in a separate component and call the other hooks there
  2. Just use currentMode instead of the hooks like so:
const styles = dynamicStyleSheet[currentMode];
const source = logoUri[currentMode];
const modeSource = modeUri[currentMode];
const barSource = barStyle[currentMode];
const barBGSource = barBGStyle[currentMode];

Screen Recording 2020-03-01 at 5 57 59 PM

Hooks are going to work fine in child components either way.