Skip to content

Commit

Permalink
Add rn-tester ScrollViewIndicatorInsetsExample to demonstrate ScrollV…
Browse files Browse the repository at this point in the history
…iew.automaticallyAdjustsScrollIndicatorInsets
  • Loading branch information
justinwh committed May 31, 2021
1 parent a0c4935 commit 1f51418
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
'use strict';

const React = require('react');

const {
Button,
Dimensions,
Modal,
ScrollView,
StyleSheet,
Switch,
Text,
View,
} = require('react-native');

class ScrollViewIndicatorInsetsExample extends React.Component<
{...},
{|
enableAutoIndicatorInsets: boolean,
modalPresentationStyle: string,
modalVisible: boolean,
|},
> {
state = {
enableAutoIndicatorInsets: true,
modalPresentationStyle: null,
modalVisible: false,
};

_setModalVisible = (modalVisible, modalPresentationStyle) => {
this.setState({
enableAutoIndicatorInsets: true,
modalVisible,
modalPresentationStyle,
});
};

_setEnableAutoIndicatorInsets = enableAutoIndicatorInsets => {
this.setState({
enableAutoIndicatorInsets,
});
};

render() {
const {height, width} = Dimensions.get('window');
return (
<View>
<Modal
animationType='slide'
visible={this.state.modalVisible}
onRequestClose={() => this._setModalVisible(false)}
presentationStyle={this.state.modalPresentationStyle}
statusBarTranslucent={false}
supportedOrientations={['portrait', 'landscape']}>
<View style={styles.modal}>
<ScrollView
contentContainerStyle={[
styles.scrollViewContent,
{
height: (height * 1.2),
width: (width * 1.2),
},
]}
automaticallyAdjustsScrollIndicatorInsets={this.state.enableAutoIndicatorInsets}
style={styles.scrollView}>
<Text>automaticallyAdjustsScrollIndicatorInsets</Text>
<Switch
onValueChange={v => this._setEnableAutoIndicatorInsets(v)}
value={this.state.enableAutoIndicatorInsets}
style={styles.switch}/>
<Button
onPress={() => this._setModalVisible(false)}
title='Close'/>
</ScrollView>
</View>
</Modal>
<Button
onPress={() => this._setModalVisible(true, 'pageSheet')}
title='Present Sheet Modal with ScrollView'/>
<Button
onPress={() => this._setModalVisible(true, 'fullscreen')}
title='Present Fullscreen Modal with ScrollView'/>
</View>
);
}
}

const styles = StyleSheet.create({
modal: {
flex: 1,
},
scrollView: {
flex: 1,
height: 1000,
},
scrollViewContent: {
alignItems: 'center',
backgroundColor: '#ffaaaa',
justifyContent: 'flex-start',
paddingTop: 200,
},
switch: {
marginBottom: 40,
},
});

exports.title = 'ScrollViewIndicatorInsets';
exports.category = 'iOS';
exports.description =
'ScrollView automaticallyAdjustsScrollIndicatorInsets adjusts scroll indicator insets using OS-defined logic on iOS 13+.';
exports.examples = [
{
title: '<ScrollView> automaticallyAdjustsScrollIndicatorInsets Example',
render: (): React.Node => <ScrollViewIndicatorInsetsExample/>,
},
];
4 changes: 4 additions & 0 deletions packages/rn-tester/js/utils/RNTesterList.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ const ComponentExamples: Array<RNTesterExample> = [
module: require('../examples/ScrollView/ScrollViewAnimatedExample'),
supportsTVOS: true,
},
{
key: 'ScrollViewIndicatorInsetsExample',
module: require('../examples/ScrollView/ScrollViewIndicatorInsetsExample'),
},
{
key: 'SectionList-inverted',
module: require('../examples/SectionList/SectionList-inverted'),
Expand Down

0 comments on commit 1f51418

Please sign in to comment.