Skip to content

Commit a999f0d

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Cleanup RNTesterExampleFilter/RNTesterPage/RNTesterBlock Spacers
Summary: Right now RNTestePage either adds a large spacer to the end of content, unless `noSpacer` is added. But with `noSpacer`, scrolling content may not be reachable because we are putting padding on the wrong container. This fixes that and removes a few cases where we had multi hundred px empty space in favor of uniformly taking up the parent, and a 10px padding. This also moves the constant margin at the top of RNTesterBlock to the container, so that in the E2E container we can save the 30px. Changelog: [Internal] Reviewed By: javache Differential Revision: D44197303 fbshipit-source-id: 8dc67f3588bc28316e2fee8d25a0bc59995f1728
1 parent 9f948fc commit a999f0d

12 files changed

+68
-86
lines changed

packages/rn-tester/js/components/RNTesterBlock.js

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ const styles = StyleSheet.create({
5454
container: {
5555
borderRadius: 0,
5656
borderWidth: 1,
57-
marginTop: 30,
5857
marginHorizontal: 20,
5958
},
6059
titleText: {

packages/rn-tester/js/components/RNTesterExampleFilter.js

-5
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,6 @@ class RNTesterExampleFilter<T> extends React.Component<Props<T>, State> {
9292
keyboardShouldPersistTaps="handled"
9393
keyboardDismissMode="interactive">
9494
{this.props.render({filteredSections})}
95-
{/**
96-
* This is a fake list item. It is needed to provide the ScrollView some bottom padding.
97-
* The height of this item is basically ScreenHeight - the height of (Header + bottom navbar)
98-
* */}
99-
<View style={{height: 350}} />
10095
</ScrollView>
10196
);
10297
} else {

packages/rn-tester/js/components/RNTesterModuleContainer.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ export default function RNTesterModuleContainer(props: Props): React.Node {
107107
sections={sections}
108108
filter={filter}
109109
render={({filteredSections}) =>
110-
filteredSections[0].data.map(renderExample)
110+
module.showIndividualExamples === true ? (
111+
filteredSections[0].data.map(renderExample)
112+
) : (
113+
<View style={styles.sectionContainer}>
114+
{filteredSections[0].data.map(renderExample)}
115+
</View>
116+
)
111117
}
112118
/>
113119
</View>
@@ -160,4 +166,8 @@ const styles = StyleSheet.create({
160166
}),
161167
marginHorizontal: 15,
162168
},
169+
sectionContainer: {
170+
rowGap: 30,
171+
paddingVertical: 30,
172+
},
163173
});

packages/rn-tester/js/components/RNTesterPage.js

+35-46
Original file line numberDiff line numberDiff line change
@@ -12,66 +12,55 @@ const RNTesterTitle = require('./RNTesterTitle');
1212
const React = require('react');
1313
const {SafeAreaView, ScrollView, StyleSheet, View} = require('react-native');
1414
import {RNTesterThemeContext} from './RNTesterTheme';
15+
import {useContext} from 'react';
1516

1617
type Props = $ReadOnly<{|
1718
children?: React.Node,
1819
title?: ?string,
1920
noScroll?: ?boolean,
20-
noSpacer?: ?boolean,
2121
|}>;
2222

23-
class RNTesterPage extends React.Component<Props> {
24-
render(): React.Node {
25-
let ContentWrapper;
26-
let wrapperProps: {
27-
automaticallyAdjustContentInsets?: boolean,
28-
keyboardShouldPersistTaps?: string,
29-
keyboardDismissMode?: string,
30-
} = {};
31-
if (this.props.noScroll) {
32-
ContentWrapper = ((View: any): React.ComponentType<any>);
33-
} else {
34-
ContentWrapper = (ScrollView: React.ComponentType<any>);
35-
wrapperProps.automaticallyAdjustContentInsets = !this.props.title;
36-
wrapperProps.keyboardShouldPersistTaps = 'handled';
37-
wrapperProps.keyboardDismissMode = 'interactive';
38-
}
39-
const title = this.props.title ? (
40-
<RNTesterTitle title={this.props.title} />
41-
) : null;
42-
const spacer = this.props.noSpacer ? null : <View style={styles.spacer} />;
43-
return (
44-
<RNTesterThemeContext.Consumer>
45-
{theme => {
46-
return (
47-
<SafeAreaView
48-
style={[
49-
styles.container,
50-
{backgroundColor: theme.SecondarySystemBackgroundColor},
51-
]}>
52-
{title}
53-
<ContentWrapper style={styles.wrapper} {...wrapperProps}>
54-
{this.props.children}
55-
{spacer}
56-
</ContentWrapper>
57-
</SafeAreaView>
58-
);
59-
}}
60-
</RNTesterThemeContext.Consumer>
61-
);
62-
}
23+
function RNTesterPage({children, title, noScroll}: Props): React.Node {
24+
const theme = useContext(RNTesterThemeContext);
25+
26+
return (
27+
<SafeAreaView
28+
style={[
29+
styles.background,
30+
{backgroundColor: theme.SecondarySystemBackgroundColor},
31+
]}>
32+
{title && <RNTesterTitle title={title} />}
33+
{noScroll ? (
34+
<View style={styles.noscrollWrapper}>{children}</View>
35+
) : (
36+
<ScrollView
37+
automaticallyAdjustContentInsets={!title}
38+
contentContainerStyle={styles.scrollWrapperContentContainer}
39+
keyboardDismissMode="interactive"
40+
keyboardShouldPersistTaps="handled"
41+
style={styles.scrollWrapper}>
42+
{children}
43+
</ScrollView>
44+
)}
45+
</SafeAreaView>
46+
);
6347
}
6448

6549
const styles = StyleSheet.create({
66-
container: {
50+
background: {
6751
flex: 1,
6852
},
69-
spacer: {
70-
height: 270,
53+
noscrollWrapper: {
54+
flex: 1,
55+
paddingVertical: 10,
56+
rowGap: 30,
7157
},
72-
wrapper: {
58+
scrollWrapper: {
7359
flex: 1,
74-
paddingTop: 10,
60+
},
61+
scrollWrapperContentContainer: {
62+
paddingVertical: 10,
63+
rowGap: 30,
7564
},
7665
});
7766

packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ const mixedCheckboxImageSource = require('./mixed.png');
4040
const {createRef} = require('react');
4141

4242
const styles = StyleSheet.create({
43+
sectionContainer: {
44+
rowGap: 20,
45+
},
4346
default: {
4447
borderWidth: StyleSheet.hairlineWidth,
4548
borderColor: '#0f0f0f',
@@ -103,7 +106,7 @@ const styles = StyleSheet.create({
103106
class AccessibilityExample extends React.Component<{}> {
104107
render(): React.Node {
105108
return (
106-
<View>
109+
<View style={styles.sectionContainer}>
107110
<RNTesterBlock title="TextView without label">
108111
<Text>
109112
Text's accessibilityLabel is the raw text itself unless it is set
@@ -284,7 +287,7 @@ class AccessibilityExample extends React.Component<{}> {
284287
class AutomaticContentGrouping extends React.Component<{}> {
285288
render(): React.Node {
286289
return (
287-
<View>
290+
<View style={styles.sectionContainer}>
288291
<RNTesterBlock title="The parent and the children have a different role">
289292
<TouchableNativeFeedback accessible={true} accessibilityRole="button">
290293
<View accessible={false}>
@@ -731,7 +734,7 @@ class AccessibilityRoleAndStateExample extends React.Component<{}> {
731734
];
732735

733736
return (
734-
<>
737+
<View style={styles.sectionContainer}>
735738
<RNTesterBlock title="ScrollView with grid role">
736739
<ScrollView accessibilityRole="grid" style={styles.scrollView}>
737740
{content}
@@ -876,20 +879,19 @@ class AccessibilityRoleAndStateExample extends React.Component<{}> {
876879
</View>
877880
<ExpandableElementExample />
878881
<SelectionExample />
879-
<RNTesterBlock title="Nested checkbox with delayed state change">
880-
<NestedCheckBox />
881-
</RNTesterBlock>
882+
<Text>Nested checkbox with delayed state change</Text>
883+
<NestedCheckBox />
882884
</View>
883885
</RNTesterBlock>
884-
</>
886+
</View>
885887
);
886888
}
887889
}
888890

889891
class AccessibilityActionsExample extends React.Component<{}> {
890892
render(): React.Node {
891893
return (
892-
<View>
894+
<View style={styles.sectionContainer}>
893895
<RNTesterBlock title="Non-touchable with activate action">
894896
<View
895897
accessible={true}
@@ -1293,7 +1295,7 @@ function SetAccessibilityFocusExample(props: {}): React.Node {
12931295
class EnabledExamples extends React.Component<{}> {
12941296
render(): React.Node {
12951297
return (
1296-
<View>
1298+
<View style={styles.sectionContainer}>
12971299
{Platform.OS === 'ios' ? (
12981300
<>
12991301
<RNTesterBlock title="isBoldTextEnabled()">
@@ -1357,7 +1359,7 @@ class EnabledExamples extends React.Component<{}> {
13571359
class ImportantForAccessibilityExamples extends React.Component<{}> {
13581360
render(): React.Node {
13591361
return (
1360-
<View>
1362+
<View style={styles.sectionContainer}>
13611363
<RNTesterBlock title="ImageBackground with importantForAccessibility=no-hide-descendants">
13621364
<View style={styles.container}>
13631365
<ImageBackground
@@ -1546,11 +1548,10 @@ function DisplayOptionStatusExample({
15461548

15471549
function AccessibilityExpandedExample(): React.Node {
15481550
const [expand, setExpanded] = React.useState(false);
1549-
const [pressed, setPressed] = React.useState(false);
15501551
const expandAction = {name: 'expand'};
15511552
const collapseAction = {name: 'collapse'};
15521553
return (
1553-
<>
1554+
<View style={styles.sectionContainer}>
15541555
<RNTesterBlock title="Collapse/Expanded state change (Paper)">
15551556
<Text>
15561557
The following component announces expanded/collapsed state correctly
@@ -1592,7 +1593,7 @@ function AccessibilityExpandedExample(): React.Node {
15921593
</View>
15931594
</TouchableWithoutFeedback>
15941595
</RNTesterBlock>
1595-
</>
1596+
</View>
15961597
);
15971598
}
15981599

packages/rn-tester/js/examples/Accessibility/AccessibilityIOSExample.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313
const React = require('react');
1414
const {Text, View, Alert} = require('react-native');
1515

16-
const RNTesterBlock = require('../../components/RNTesterBlock');
17-
1816
type Props = $ReadOnly<{||}>;
1917
class AccessibilityIOSExample extends React.Component<Props> {
2018
render(): React.Node {
2119
return (
22-
<RNTesterBlock title="Accessibility iOS APIs">
20+
<>
2321
<View
2422
onAccessibilityAction={event => {
2523
if (event.nativeEvent.actionName === 'activate') {
@@ -58,7 +56,7 @@ class AccessibilityIOSExample extends React.Component<Props> {
5856
<View accessible={true} accessibilityLanguage="it-IT">
5957
<Text>This view's language should be `it-IT`</Text>
6058
</View>
61-
</RNTesterBlock>
59+
</>
6260
);
6361
}
6462
}

packages/rn-tester/js/examples/FlatList/FlatList-basic.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,7 @@ class FlatListExample extends React.PureComponent<Props, State> {
136136
const filteredData = this.state.data.filter(filter);
137137
const flatListItemRendererProps = this._renderItemComponent();
138138
return (
139-
<RNTesterPage
140-
noSpacer={true}
141-
noScroll={true}
142-
title="Simple list of items">
139+
<RNTesterPage noScroll={true} title="Simple list of items">
143140
<View style={styles.container}>
144141
<View style={styles.searchRow}>
145142
<View style={styles.options}>

packages/rn-tester/js/examples/FlatList/FlatList-multiColumn.js

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ class MultiColumnExample extends React.PureComponent<
7373
return (
7474
<RNTesterPage
7575
title={this.props.navigator ? null : '<FlatList> - MultiColumn'}
76-
noSpacer={true}
7776
noScroll={true}>
7877
<View style={styles.searchRow}>
7978
<View style={styles.row}>

packages/rn-tester/js/examples/FlatList/FlatList-nested.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function NestedListExample(): React.Node {
9797
);
9898

9999
return (
100-
<RNTesterPage noSpacer={true} noScroll={true}>
100+
<RNTesterPage noScroll={true}>
101101
<Text style={styles.debugText}>
102102
<Text style={styles.debugTextHeader}>Outer Viewable:{'\n'}</Text>
103103
{outerItems

packages/rn-tester/js/examples/PanResponder/PanResponderExample.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,7 @@ class PanResponderExample extends React.Component<Props, State> {
9999

100100
render(): React.Node {
101101
return (
102-
<RNTesterPage
103-
noSpacer={true}
104-
noScroll={true}
105-
title="Basic gesture handling">
102+
<RNTesterPage noScroll={true} title="Basic gesture handling">
106103
<View style={styles.container}>
107104
<View
108105
ref={circle => {

packages/rn-tester/js/examples/Performance/PerformanceApiExample.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function MemoryExample(): React.Node {
3232
setMemoryInfo(performance.memory);
3333
}, []);
3434
return (
35-
<RNTesterPage noSpacer={true} noScroll={true} title="performance.memory">
35+
<RNTesterPage noScroll={true} title="performance.memory">
3636
<View style={styles.container}>
3737
<Button onPress={onGetMemoryInfo} title="Click to update memory info" />
3838
<View>
@@ -63,10 +63,7 @@ function StartupTimingExample(): React.Node {
6363
setStartUpTiming(performance.reactNativeStartupTiming);
6464
}, []);
6565
return (
66-
<RNTesterPage
67-
noSpacer={true}
68-
noScroll={true}
69-
title="performance.reactNativeStartupTiming">
66+
<RNTesterPage noScroll={true} title="performance.reactNativeStartupTiming">
7067
<View style={styles.container}>
7168
<Button
7269
onPress={onGetStartupTiming}

packages/rn-tester/js/examples/SectionList/SectionList-scrollable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export function SectionList_scrollable(Props: {
232232
};
233233

234234
return (
235-
<RNTesterPage noSpacer={true} noScroll={true}>
235+
<RNTesterPage noScroll={true}>
236236
<View style={styles.searchRow}>
237237
<PlainInput
238238
onChangeText={text => setFilterText(text)}

0 commit comments

Comments
 (0)