mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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: e47484d4b3f0963ef0cc3d8aff8ce3e9051ddbae
This commit is contained in:
committed by
Facebook Github Bot
parent
ba56fa43f0
commit
a397d330a4
@@ -13,6 +13,7 @@
|
||||
const React = require('react');
|
||||
|
||||
const {Alert, Button, View, StyleSheet} = require('react-native');
|
||||
import {RNTesterThemeContext} from '../../components/RNTesterTheme';
|
||||
|
||||
function onButtonPress(buttonName) {
|
||||
Alert.alert(`${buttonName} has been pressed!`);
|
||||
@@ -31,12 +32,19 @@ exports.examples = [
|
||||
'everyone.': string),
|
||||
render: function(): React.Node {
|
||||
return (
|
||||
<Button
|
||||
onPress={() => onButtonPress('Simple')}
|
||||
testID="simple_button"
|
||||
title="Press Me"
|
||||
accessibilityLabel="See an informative alert"
|
||||
/>
|
||||
<RNTesterThemeContext.Consumer>
|
||||
{theme => {
|
||||
return (
|
||||
<Button
|
||||
onPress={() => onButtonPress('Simple')}
|
||||
testID="simple_button"
|
||||
color={theme.LinkColor}
|
||||
title="Press Me"
|
||||
accessibilityLabel="See an informative alert"
|
||||
/>
|
||||
);
|
||||
}}
|
||||
</RNTesterThemeContext.Consumer>
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -47,13 +55,19 @@ exports.examples = [
|
||||
'Android, the color adjusts the background color of the button.': string),
|
||||
render: function(): React.Node {
|
||||
return (
|
||||
<Button
|
||||
onPress={() => onButtonPress('Purple')}
|
||||
testID="purple_button"
|
||||
title="Press Purple"
|
||||
color="#841584"
|
||||
accessibilityLabel="Learn more about purple"
|
||||
/>
|
||||
<RNTesterThemeContext.Consumer>
|
||||
{theme => {
|
||||
return (
|
||||
<Button
|
||||
onPress={() => onButtonPress('Purple')}
|
||||
testID="purple_button"
|
||||
color={theme.SystemPurpleColor}
|
||||
title="Press Purple"
|
||||
accessibilityLabel="Learn more about purple"
|
||||
/>
|
||||
);
|
||||
}}
|
||||
</RNTesterThemeContext.Consumer>
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -63,21 +77,28 @@ exports.examples = [
|
||||
'the button': string),
|
||||
render: function(): React.Node {
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Button
|
||||
onPress={() => onButtonPress('Left')}
|
||||
testID="left_button"
|
||||
title="This looks great!"
|
||||
accessibilityLabel="This sounds great!"
|
||||
/>
|
||||
<Button
|
||||
onPress={() => onButtonPress('Right')}
|
||||
testID="right_button"
|
||||
title="Ok!"
|
||||
color="#841584"
|
||||
accessibilityLabel="Ok, Great!"
|
||||
/>
|
||||
</View>
|
||||
<RNTesterThemeContext.Consumer>
|
||||
{theme => {
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Button
|
||||
onPress={() => onButtonPress('Left')}
|
||||
testID="left_button"
|
||||
color={theme.LinkColor}
|
||||
title="This looks great!"
|
||||
accessibilityLabel="This sounds great!"
|
||||
/>
|
||||
<Button
|
||||
onPress={() => onButtonPress('Right')}
|
||||
testID="right_button"
|
||||
color={theme.SystemPurpleColor}
|
||||
title="Ok!"
|
||||
accessibilityLabel="Ok, Great!"
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}}
|
||||
</RNTesterThemeContext.Consumer>
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user