expo / react-native-appearance

Access operating system appearance information (currently only light/dark mode) on iOS, Android, and web
MIT License
337 stars 40 forks source link

Android restarts on theme switch within Expo environment #33

Open artyorsh opened 4 years ago

artyorsh commented 4 years ago

Hi 👋 Thanks for the great work on this library and Expo support.

I'm sorry if I've missed something, but is it correct that Android completely restarts an app on a system theme switch while iOS is not forced to do this?

Related code:

const createAppearanceTheme = (appearance: ColorSchemeName, initialTheme: Theme): ColorSchemeName => {
  if (appearance === 'no-preference') {
    return preferredTheme;
  }
  return appearance;
};

export const useTheming = (initialTheme?: ColorSchemeName = 'no-preference') => {
  const deviceAppearance: ColorSchemeName = Appearance.getColorScheme();
  const deviceAppearanceTheme = createAppearanceTheme(deviceAppearance, preferredTheme);

  const [currentTheme, setCurrentTheme] = React.useState(deviceAppearanceTheme);

  React.useEffect(() => {
    const subscription = Appearance.addChangeListener((preferences: AppearancePreferences): void => {
      const appearanceTheme: ColorSchemeName = createAppearanceTheme(preferences.colorScheme, initialTheme);
      setCurrentTheme(appearanceTheme);
    });

    return () => subscription.remove();
  }, []);
};

Also "userInterfaceStyle": "automatic" in app.json

Which is followed by default configuration of usage docs

Demo

DimitarNestorov commented 4 years ago

@artyorsh After completing the configuration section in the README the app should not restart anymore: https://github.com/expo/react-native-appearance#configuration

artyorsh commented 4 years ago

@dimitarnestorov Thanks. That was helpful for bare react-native project. Can it be somehow handled in expo environment?

DimitarNestorov commented 4 years ago

Is it not? You might want to reopen in this case.

artyorsh commented 4 years ago

This solved my use-case. I was able to switch to Bare expo application and modify AndroidManifest. However, am I right that this issue is actual for regular Expo applications?

summerkiflain commented 4 years ago

@artyorsh I can confirm that this is not resolved for expo environment, Can you please reopen this issue with probably Expo written in the tittle.

maitriyogin commented 4 years ago

Hi, I'm getting the same issue. I even tried removing appearance completely and went back to the barest of apps from an expo init ( sdk 37 ). App restarts on a dark mode switch, not sure if this is an appearance bug? /Stephen.

dacevedo12 commented 4 years ago

Can confirm this still happens on the manager workflow. Maybe the shell app needs to be updated?

Also noticed that the expo client app is also affected

anisimov74 commented 4 years ago

Same here