Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit f2d72f2

Browse files
committed
update example code
1 parent 5c47e5d commit f2d72f2

File tree

1 file changed

+56
-91
lines changed
  • RNResponsiveDimensionsExample

1 file changed

+56
-91
lines changed

RNResponsiveDimensionsExample/App.js

Lines changed: 56 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -7,107 +7,72 @@
77
*/
88

99
import React from 'react';
10+
import {SafeAreaView, StyleSheet, ScrollView, View, Text} from 'react-native';
1011
import {
11-
SafeAreaView,
12-
StyleSheet,
13-
ScrollView,
14-
View,
15-
Text,
16-
StatusBar,
17-
} from 'react-native';
12+
responsiveHeight,
13+
responsiveWidth,
14+
responsiveFontSize,
15+
useResponsiveHeight,
16+
useResponsiveWidth,
17+
useResponsiveFontSize,
18+
} from 'react-native-responsive-dimensions';
1819

19-
import {
20-
Header,
21-
LearnMoreLinks,
22-
Colors,
23-
DebugInstructions,
24-
ReloadInstructions,
25-
} from 'react-native/Libraries/NewAppScreen';
20+
const App = () => {
21+
const requiredHeight = useResponsiveHeight(25);
22+
const requiredWidth = useResponsiveWidth(100);
23+
const requiredFontSize = useResponsiveFontSize(3);
24+
25+
const responsiveStyles = {
26+
hooksResponsiveContainer: {
27+
height: requiredHeight,
28+
width: requiredWidth,
29+
backgroundColor: 'red',
30+
},
31+
hooksText: {
32+
color: 'white',
33+
fontSize: requiredFontSize,
34+
},
35+
};
2636

27-
const App: () => React$Node = () => {
2837
return (
29-
<>
30-
<StatusBar barStyle="dark-content" />
31-
<SafeAreaView>
32-
<ScrollView
33-
contentInsetAdjustmentBehavior="automatic"
34-
style={styles.scrollView}>
35-
<Header />
36-
{global.HermesInternal == null ? null : (
37-
<View style={styles.engine}>
38-
<Text style={styles.footer}>Engine: Hermes</Text>
39-
</View>
40-
)}
41-
<View style={styles.body}>
42-
<View style={styles.sectionContainer}>
43-
<Text style={styles.sectionTitle}>Step One</Text>
44-
<Text style={styles.sectionDescription}>
45-
Edit <Text style={styles.highlight}>App.js</Text> to change this
46-
screen and then come back to see your edits.
47-
</Text>
48-
</View>
49-
<View style={styles.sectionContainer}>
50-
<Text style={styles.sectionTitle}>See Your Changes</Text>
51-
<Text style={styles.sectionDescription}>
52-
<ReloadInstructions />
53-
</Text>
54-
</View>
55-
<View style={styles.sectionContainer}>
56-
<Text style={styles.sectionTitle}>Debug</Text>
57-
<Text style={styles.sectionDescription}>
58-
<DebugInstructions />
59-
</Text>
60-
</View>
61-
<View style={styles.sectionContainer}>
62-
<Text style={styles.sectionTitle}>Learn More</Text>
63-
<Text style={styles.sectionDescription}>
64-
Read the docs to discover what to do next:
65-
</Text>
66-
</View>
67-
<LearnMoreLinks />
68-
</View>
69-
</ScrollView>
70-
</SafeAreaView>
71-
</>
38+
<SafeAreaView style={styles.appContainer}>
39+
<ScrollView>
40+
<View style={styles.legacyResponsiveContainer}>
41+
<Text style={styles.legacyText}>Responsive Height: 25</Text>
42+
<Text style={styles.legacyText}>Responsive Width: 100</Text>
43+
<Text style={styles.legacyText}>Responsive Font Size: 3</Text>
44+
</View>
45+
46+
<View style={responsiveStyles.hooksResponsiveContainer}>
47+
<Text style={responsiveStyles.hooksText}>
48+
Responsive Hooks Height: 25
49+
</Text>
50+
<Text style={responsiveStyles.hooksText}>
51+
Responsive Hooks Width: 100
52+
</Text>
53+
<Text style={responsiveStyles.hooksText}>
54+
Responsive Hooks Font Size: 3
55+
</Text>
56+
</View>
57+
</ScrollView>
58+
</SafeAreaView>
7259
);
7360
};
7461

7562
const styles = StyleSheet.create({
76-
scrollView: {
77-
backgroundColor: Colors.lighter,
78-
},
79-
engine: {
80-
position: 'absolute',
81-
right: 0,
82-
},
83-
body: {
84-
backgroundColor: Colors.white,
85-
},
86-
sectionContainer: {
87-
marginTop: 32,
88-
paddingHorizontal: 24,
89-
},
90-
sectionTitle: {
91-
fontSize: 24,
92-
fontWeight: '600',
93-
color: Colors.black,
94-
},
95-
sectionDescription: {
96-
marginTop: 8,
97-
fontSize: 18,
98-
fontWeight: '400',
99-
color: Colors.dark,
63+
appContainer: {
64+
flex: 1,
65+
backgroundColor: 'yellow',
10066
},
101-
highlight: {
102-
fontWeight: '700',
67+
legacyResponsiveContainer: {
68+
height: responsiveHeight(25),
69+
width: responsiveWidth(100),
70+
backgroundColor: 'blue',
71+
justifyContent: 'flex-end',
10372
},
104-
footer: {
105-
color: Colors.dark,
106-
fontSize: 12,
107-
fontWeight: '600',
108-
padding: 4,
109-
paddingRight: 12,
110-
textAlign: 'right',
73+
legacyText: {
74+
color: 'white',
75+
fontSize: responsiveFontSize(3),
11176
},
11277
});
11378

0 commit comments

Comments
 (0)