Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Preview: Appearance Native Module #26172

Closed
wants to merge 5 commits into from

Commits on Aug 23, 2019

  1. Add Appearance native module

    Summary:
    Implements the Appearance native module as discussed in react-native-community/discussions-and-proposals#126.
    
    The purpose of the Appearance native module is to expose the user's appearance preferences. Initial support includes exposing the user's preferred color scheme on iOS 13 devices, also known as Dark Mode.
    
    The name, "Appearance", was chosen purposefully to allow for future expansion to cover other appearance preferences such as reduced motion, reduced transparency, or high contrast modes.
    
    It should be noted that the current implementation exposes the main UIWindow's user interface style, while it is possible to have multiple RCTRootViews with distinct user interface styles (for example, one RCTRootView that uses the system user interface style, while a second RCTRootView has a parent that has been forced to always display with a dark appearance). This is intentional as the goal is to provide the user's preferred color scheme. The module is written in a way that allows for future expansion to expose individual RCTRootView traits.
    
    Changelog:
    
    [iOS] [Added] - The Appearance native module can be used to prepare your app for Dark Mode on iOS 13.
    
    Differential Revision: D16699954
    
    fbshipit-source-id: d6d78d808828931bde400c99986e6913877b1cee
    hramos authored and facebook-github-bot committed Aug 23, 2019
    Configuration menu
    Copy the full SHA
    6246c97 View commit details
    Browse the repository at this point in the history
  2. Support light and dark themes in RNTester

    Summary:
    Initial conversion of RNTester to support light and dark themes. Theming is implemented by providing the desired color theme via context. Example:
    
    ```
    const ThemedContainer = props => (
      <RNTesterThemeContext.Consumer>
        {theme => {
          return (
            <View
              style={{
                paddingHorizontal: 8,
                paddingVertical: 16,
                backgroundColor: theme.SystemBackgroundColor,
              }}>
              {props.children}
            </View>
          );
        }}
      </RNTesterThemeContext.Consumer>
    );
    ```
    
    As RNTester's design follows the base iOS system appearance, I've chosen light and dark themes based on the actual iOS 13 semantic colors. The themes are RNTester-specific, however, and we'd expect individual apps to build their own color palettes.
    
    ## Examples
    
    The new Appearance Examples screen demonstrates how context can be used to force a theme. It also displays the list of colors in each RNTester theme.
    
    https://pxl.cl/HmzW (screenshot: Appearance Examples screen on RNTester with Dark Mode enabled. Displays useColorScheme hook, and context examples.)
    https://pxl.cl/HmB3 (screenshot: Same screen, with light and dark RNTester themes visible)
    
    Theming support in this diff mostly focused on the main screen and the Dark Mode examples screen. This required updating the components used by most of the examples, as you can see in this Image example:
    https://pxl.cl/H0Hv (screenshot: Image Examples screen in Dark Mode theme)
    
    Note that I have yet to go through every single example screen to update it. There's individual cases, such as the FlatList example screen, that are not fully converted to use a dark theme when appropriate. This can be taken care later as it's non-blocking.
    
    Reviewed By: zackargyle
    
    Differential Revision: D16681909
    
    fbshipit-source-id: 1a5fff44b0dd00b8c3f439c81837d24771b28d94
    hramos authored and facebook-github-bot committed Aug 23, 2019
    Configuration menu
    Copy the full SHA
    bab28dc View commit details
    Browse the repository at this point in the history
  3. useColorScheme hook

    Summary:
    A new useColorScheme hook is provided as the preferred way of accessing the user's preferred color scheme (aka Dark Mode).
    
    Changelog:
    
    [General] [Added] - useColorScheme hook
    
    Differential Revision: D16860954
    
    fbshipit-source-id: a099b25681ec03b349826afedd89b1959c9fd6c6
    hramos authored and facebook-github-bot committed Aug 23, 2019
    Configuration menu
    Copy the full SHA
    d55bd1b View commit details
    Browse the repository at this point in the history
  4. Add Appearance module

    Summary:
    Android implementation of the Appearance native module. Exposes the user's preferred color scheme: "dark" for Night theme ON, "light" for Night theme OFF.
    
    Subscribing to events whenever Night theme is switched on or off is not yet supported.
    
    ### RNTester
    
    Adds the AppearanceExample to RNTester on Android.
    
    Changelog:
    
    [Android][Added] - New Appearance module exposes the user's current Night theme preference
    
    Differential Revision: D16942161
    
    fbshipit-source-id: b99b8c4e4148c380134a87c17b5cacadcacc8167
    hramos authored and facebook-github-bot committed Aug 23, 2019
    Configuration menu
    Copy the full SHA
    90635a7 View commit details
    Browse the repository at this point in the history
  5. Appearance: Emit appearance changed event when uiMode changes

    Summary:
    The AppearanceModule now emits a `appearanceChanged` event when the current uiMode configuration changes.
    
    To make your app handle Night mode changes, make sure to do the following:
    
    * Declare your Activity can handle uiMode configuration changes (https://developer.android.com/preview/features/darktheme#java):
    ```
    android:configChanges="uiMode"
    ```
    * Make sure to pass the configuration changed activity lifecycle callback from your ReactActivity:
    ```
    Override
    protected void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged();
    
        if (mReactInstanceManager != null) {
            mReactInstanceManager.onConfigurationChanged(newConfig);
        }
    }
    ```
    
    An example is now provided in the RNTester app.
    
    Differential Revision: D16985129
    
    fbshipit-source-id: 2c3eb3319158990bb4dd226c88ec5093c6acf147
    hramos authored and facebook-github-bot committed Aug 23, 2019
    Configuration menu
    Copy the full SHA
    92d34f1 View commit details
    Browse the repository at this point in the history