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

@artyorsh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions