Skip to content

Commit a8875b6

Browse files
committed
Add rn-tester ScrollViewIndicatorInsetsExample to demonstrate ScrollView.automaticallyAdjustsScrollIndicatorInsets
1 parent a0c4935 commit a8875b6

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
'use strict';
2+
3+
const React = require('react');
4+
5+
const {
6+
Button,
7+
Dimensions,
8+
Modal,
9+
ScrollView,
10+
StyleSheet,
11+
Switch,
12+
Text,
13+
View,
14+
} = require('react-native');
15+
16+
class ScrollViewIndicatorInsetsExample extends React.Component<
17+
{...},
18+
{|
19+
enableAutoIndicatorInsets: boolean,
20+
modalPresentationStyle: string,
21+
modalVisible: boolean,
22+
|},
23+
> {
24+
state = {
25+
enableAutoIndicatorInsets: true,
26+
modalPresentationStyle: null,
27+
modalVisible: false,
28+
};
29+
30+
_setModalVisible = (modalVisible, modalPresentationStyle) => {
31+
this.setState({
32+
enableAutoIndicatorInsets: true,
33+
modalVisible,
34+
modalPresentationStyle,
35+
});
36+
};
37+
38+
_setEnableAutoIndicatorInsets = enableAutoIndicatorInsets => {
39+
this.setState({
40+
enableAutoIndicatorInsets,
41+
});
42+
};
43+
44+
render() {
45+
const {height, width} = Dimensions.get('window');
46+
return (
47+
<View>
48+
<Modal
49+
animationType="slide"
50+
visible={this.state.modalVisible}
51+
onRequestClose={() => this._setModalVisible(false)}
52+
presentationStyle={this.state.modalPresentationStyle}
53+
statusBarTranslucent={false}
54+
supportedOrientations={['portrait', 'landscape']}>
55+
<View style={styles.modal}>
56+
<ScrollView
57+
contentContainerStyle={[
58+
styles.scrollViewContent,
59+
{
60+
height: (height * 1.2),
61+
width: (width * 1.2),
62+
},
63+
]}
64+
automaticallyAdjustsScrollIndicatorInsets={this.state.enableAutoIndicatorInsets}
65+
style={styles.scrollView}>
66+
<Text>automaticallyAdjustsScrollIndicatorInsets</Text>
67+
<Switch
68+
onValueChange={v => this._setEnableAutoIndicatorInsets(v)}
69+
value={this.state.enableAutoIndicatorInsets}
70+
style={styles.switch}/>
71+
<Button
72+
onPress={() => this._setModalVisible(false)}
73+
title="Close"/>
74+
</ScrollView>
75+
</View>
76+
</Modal>
77+
<Button
78+
onPress={() => this._setModalVisible(true, 'pageSheet')}
79+
title="Present Sheet Modal with ScrollView"/>
80+
<Button
81+
onPress={() => this._setModalVisible(true, 'fullscreen')}
82+
title="Present Fullscreen Modal with ScrollView"/>
83+
</View>
84+
);
85+
}
86+
}
87+
88+
const styles = StyleSheet.create({
89+
modal: {
90+
flex: 1,
91+
},
92+
scrollView: {
93+
flex: 1,
94+
height: 1000,
95+
},
96+
scrollViewContent: {
97+
alignItems: 'center',
98+
backgroundColor: '#ffaaaa',
99+
justifyContent: 'flex-start',
100+
paddingTop: 200,
101+
},
102+
switch: {
103+
marginBottom: 40,
104+
},
105+
});
106+
107+
exports.title = 'ScrollViewIndicatorInsets';
108+
exports.category = 'iOS';
109+
exports.description =
110+
'ScrollView automaticallyAdjustsScrollIndicatorInsets adjusts scroll indicator insets using OS-defined logic on iOS 13+.';
111+
exports.examples = [
112+
{
113+
title: '<ScrollView> automaticallyAdjustsScrollIndicatorInsets Example',
114+
render: (): React.Node => <ScrollViewIndicatorInsetsExample/>,
115+
},
116+
];

packages/rn-tester/js/utils/RNTesterList.ios.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ const ComponentExamples: Array<RNTesterExample> = [
118118
module: require('../examples/ScrollView/ScrollViewAnimatedExample'),
119119
supportsTVOS: true,
120120
},
121+
{
122+
key: 'ScrollViewIndicatorInsetsExample',
123+
module: require('../examples/ScrollView/ScrollViewIndicatorInsetsExample'),
124+
},
121125
{
122126
key: 'SectionList-inverted',
123127
module: require('../examples/SectionList/SectionList-inverted'),

0 commit comments

Comments
 (0)