Skip to content
This repository was archived by the owner on Mar 3, 2021. It is now read-only.
This repository was archived by the owner on Mar 3, 2021. It is now read-only.

Android restarts on theme switch within Expo environment聽#33

Description

@artyorsh

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions