Skip to content

Commit 233fddb

Browse files
eliperkinsfacebook-github-bot
authored andcommitted
Polish new app screen component styling (#24783)
Summary: Related to #24760 and #24737 This simplifies some styling within the components used for the New App Screen to help advocate for best practices when styling with CSS-like styles in React Native, as well as using React Native's own unique components. There's a bit more detail in each commit. Let me know if you'd like me to pull that info out into the PR description here! [General] [Changed] - Polished up new app screen component styling Pull Request resolved: #24783 Differential Revision: D15284851 Pulled By: cpojer fbshipit-source-id: 954db00d39fc0082bbd4dc96afa7d38dfb7f67d5
1 parent 4e37d37 commit 233fddb

File tree

2 files changed

+56
-68
lines changed

2 files changed

+56
-68
lines changed

Libraries/NewAppScreen/components/Header.js

+20-21
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,38 @@
1111
'use strict';
1212

1313
import React from 'react';
14-
import {View, Text, StyleSheet, ImageBackground} from 'react-native';
14+
import {Text, StyleSheet, ImageBackground} from 'react-native';
1515
import Colors from './Colors';
1616

1717
const Header = () => (
18-
<View style={styles.container}>
19-
<ImageBackground
20-
accessibilityRole={'image'}
21-
source={require('./logo.png')}
22-
style={styles.backgroundLogo}
23-
/>
24-
18+
<ImageBackground
19+
accessibilityRole={'image'}
20+
source={require('./logo.png')}
21+
style={styles.background}
22+
imageStyle={styles.logo}>
2523
<Text style={styles.text}>Welcome to React Native</Text>
26-
</View>
24+
</ImageBackground>
2725
);
2826

2927
const styles = StyleSheet.create({
30-
container: {
31-
alignItems: 'center',
32-
justifyContent: 'center',
33-
paddingTop: 100,
28+
background: {
3429
paddingBottom: 40,
30+
paddingTop: 96,
3531
paddingHorizontal: 32,
3632
backgroundColor: Colors.lighter,
3733
},
38-
backgroundLogo: {
39-
position: 'absolute',
40-
top: -20,
41-
left: -200,
34+
logo: {
4235
opacity: 0.2,
43-
alignItems: 'center',
44-
justifyContent: 'center',
45-
height: 540,
46-
width: 540,
36+
overflow: 'visible',
37+
resizeMode: 'cover',
38+
/*
39+
* These negative margins allow the image to be offset similarly across screen sizes and component sizes.
40+
*
41+
* The source logo.png image is 512x512px, so as such, these margins attempt to be relative to the
42+
* source image's size.
43+
*/
44+
marginLeft: -128,
45+
marginBottom: -192,
4746
},
4847
text: {
4948
fontSize: 40,

Libraries/NewAppScreen/index.js

+36-47
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
Text,
1919
Platform,
2020
StatusBar,
21-
SafeAreaView,
2221
} from 'react-native';
2322

2423
import Header from './components/Header';
@@ -51,7 +50,7 @@ const DebugInstructions = () => {
5150
Native debug menu.
5251
</Text>
5352
) : (
54-
<Text>
53+
<Text style={styles.sectionDescription}>
5554
Press <Text style={styles.highlight}>menu button</Text> or
5655
<Text style={styles.highlight}>Shake</Text> your device to open the React
5756
Native debug menu.
@@ -62,64 +61,54 @@ const DebugInstructions = () => {
6261
const App = () => {
6362
return (
6463
<Fragment>
65-
<SafeAreaView style={styles.topSafeArea} />
66-
67-
<SafeAreaView style={styles.bottomSafeArea}>
68-
<StatusBar barStyle="dark-content" />
69-
<ScrollView>
70-
<Header />
71-
<View style={styles.body}>
72-
<Section>
73-
<Text style={styles.sectionTitle}>Step One</Text>
74-
<Text style={styles.sectionDescription}>
75-
Edit <Text style={styles.highlight}>App.js</Text> to change this
76-
screen and then come back to see your edits.
77-
</Text>
78-
</Section>
64+
<StatusBar barStyle="dark-content" />
65+
<ScrollView
66+
contentInsetAdjustmentBehavior="automatic"
67+
style={styles.scrollView}>
68+
<Header />
69+
<View style={styles.body}>
70+
<Section>
71+
<Text style={styles.sectionTitle}>Step One</Text>
72+
<Text style={styles.sectionDescription}>
73+
Edit <Text style={styles.highlight}>App.js</Text> to change this
74+
screen and then come back to see your edits.
75+
</Text>
76+
</Section>
7977

80-
<Section>
81-
<Text style={styles.sectionTitle}>See Your Changes</Text>
82-
<Text style={styles.sectionDescription}>
83-
<ReloadInstructions />
84-
</Text>
85-
</Section>
78+
<Section>
79+
<Text style={styles.sectionTitle}>See Your Changes</Text>
80+
<ReloadInstructions />
81+
</Section>
8682

87-
<Section>
88-
<Text style={styles.sectionTitle}>Debug</Text>
89-
<DebugInstructions />
90-
</Section>
83+
<Section>
84+
<Text style={styles.sectionTitle}>Debug</Text>
85+
<DebugInstructions />
86+
</Section>
9187

92-
<Section>
93-
<Text style={styles.sectionTitle}>Learn More</Text>
94-
<Text style={styles.sectionDescription}>
95-
Read the docs on what to do once seen how to work in React
96-
Native.
97-
</Text>
98-
</Section>
99-
<LearnMoreLinks />
100-
</View>
101-
</ScrollView>
102-
</SafeAreaView>
88+
<Section>
89+
<Text style={styles.sectionTitle}>Learn More</Text>
90+
<Text style={styles.sectionDescription}>
91+
Read the docs on what to do once seen how to work in React Native.
92+
</Text>
93+
</Section>
94+
<LearnMoreLinks />
95+
</View>
96+
</ScrollView>
10397
</Fragment>
10498
);
10599
};
106100

107101
const styles = StyleSheet.create({
108-
sectionContainer: {
109-
marginTop: 32,
110-
paddingHorizontal: 24,
111-
},
112-
topSafeArea: {
113-
flex: 0,
102+
scrollView: {
114103
backgroundColor: Colors.lighter,
115104
},
116-
bottomSafeArea: {
117-
flex: 1,
118-
backgroundColor: Colors.white,
119-
},
120105
body: {
121106
backgroundColor: Colors.white,
122107
},
108+
sectionContainer: {
109+
marginTop: 32,
110+
paddingHorizontal: 24,
111+
},
123112
sectionTitle: {
124113
fontSize: 24,
125114
fontWeight: '600',

0 commit comments

Comments
 (0)