mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
763dc52387
Summary: This PR adds a `backgroundColor` prop to the `StatusBar` in the starter template so that Dark Mode is correctly demonstrated when running on Android. **Before** StatusBar in starter app on Android would remain the same color no matter what the current device color scheme was. <img width="300" alt="Screenshot 2022-04-04 at 09 30 54" src="https://user-images.githubusercontent.com/5814579/161505272-88b57e86-3ada-4bf5-beef-a1f5a1661eaa.png"><img width="300" alt="Screenshot 2022-04-04 at 09 31 12" src="https://user-images.githubusercontent.com/5814579/161505278-c2da0421-83ab-4e03-9f04-718f5503ed36.png"> **After** StatusBar in starter app on Android correctly reacts to the color scheme. <img width="300" alt="Screenshot 2022-04-04 at 09 29 41" src="https://user-images.githubusercontent.com/5814579/161505014-af3b255b-650b-435f-9e37-2f604d5f0310.png"><img width="300" alt="Screenshot 2022-04-04 at 09 29 22" src="https://user-images.githubusercontent.com/5814579/161505011-55ae4ffe-bfd0-449c-a6c1-0d2b8d3aee59.png"> ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Android] [Changed] - Demonstrating Dark Mode correctly in the `StatusBar` for the starter template App. Pull Request resolved: https://github.com/facebook/react-native/pull/33561 Test Plan: This was a very simple change that I was able to verify in a newly generated RN project by copying the `backgroundColor` prop across. See screenshots above. Reviewed By: christophpurrer Differential Revision: D36018771 Pulled By: kacieb fbshipit-source-id: c037cb19478affaa9c5485ebd9babf728cced1d6
116 lines
2.5 KiB
JavaScript
116 lines
2.5 KiB
JavaScript
/**
|
|
* Sample React Native App
|
|
* https://github.com/facebook/react-native
|
|
*
|
|
* @format
|
|
* @flow strict-local
|
|
*/
|
|
|
|
import React from 'react';
|
|
import type {Node} from 'react';
|
|
import {
|
|
SafeAreaView,
|
|
ScrollView,
|
|
StatusBar,
|
|
StyleSheet,
|
|
Text,
|
|
useColorScheme,
|
|
View,
|
|
} from 'react-native';
|
|
|
|
import {
|
|
Colors,
|
|
DebugInstructions,
|
|
Header,
|
|
LearnMoreLinks,
|
|
ReloadInstructions,
|
|
} from 'react-native/Libraries/NewAppScreen';
|
|
|
|
const Section = ({children, title}): Node => {
|
|
const isDarkMode = useColorScheme() === 'dark';
|
|
return (
|
|
<View style={styles.sectionContainer}>
|
|
<Text
|
|
style={[
|
|
styles.sectionTitle,
|
|
{
|
|
color: isDarkMode ? Colors.white : Colors.black,
|
|
},
|
|
]}>
|
|
{title}
|
|
</Text>
|
|
<Text
|
|
style={[
|
|
styles.sectionDescription,
|
|
{
|
|
color: isDarkMode ? Colors.light : Colors.dark,
|
|
},
|
|
]}>
|
|
{children}
|
|
</Text>
|
|
</View>
|
|
);
|
|
};
|
|
|
|
const App: () => Node = () => {
|
|
const isDarkMode = useColorScheme() === 'dark';
|
|
|
|
const backgroundStyle = {
|
|
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
|
|
};
|
|
|
|
return (
|
|
<SafeAreaView style={backgroundStyle}>
|
|
<StatusBar
|
|
barStyle={isDarkMode ? 'light-content' : 'dark-content'}
|
|
backgroundColor={backgroundStyle.backgroundColor}
|
|
/>
|
|
<ScrollView
|
|
contentInsetAdjustmentBehavior="automatic"
|
|
style={backgroundStyle}>
|
|
<Header />
|
|
<View
|
|
style={{
|
|
backgroundColor: isDarkMode ? Colors.black : Colors.white,
|
|
}}>
|
|
<Section title="Step One">
|
|
Edit <Text style={styles.highlight}>App.js</Text> to change this
|
|
screen and then come back to see your edits.
|
|
</Section>
|
|
<Section title="See Your Changes">
|
|
<ReloadInstructions />
|
|
</Section>
|
|
<Section title="Debug">
|
|
<DebugInstructions />
|
|
</Section>
|
|
<Section title="Learn More">
|
|
Read the docs to discover what to do next:
|
|
</Section>
|
|
<LearnMoreLinks />
|
|
</View>
|
|
</ScrollView>
|
|
</SafeAreaView>
|
|
);
|
|
};
|
|
|
|
const styles = StyleSheet.create({
|
|
sectionContainer: {
|
|
marginTop: 32,
|
|
paddingHorizontal: 24,
|
|
},
|
|
sectionTitle: {
|
|
fontSize: 24,
|
|
fontWeight: '600',
|
|
},
|
|
sectionDescription: {
|
|
marginTop: 8,
|
|
fontSize: 18,
|
|
fontWeight: '400',
|
|
},
|
|
highlight: {
|
|
fontWeight: '700',
|
|
},
|
|
});
|
|
|
|
export default App;
|