|
| 1 | +/** |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +'use strict'; |
| 9 | + |
| 10 | +import * as React from 'react'; |
| 11 | + |
| 12 | +import { |
| 13 | + Button, |
| 14 | + Modal, |
| 15 | + ScrollView, |
| 16 | + StyleSheet, |
| 17 | + Switch, |
| 18 | + Text, |
| 19 | + View, |
| 20 | + useWindowDimensions, |
| 21 | +} from 'react-native'; |
| 22 | + |
| 23 | +export function ScrollViewIndicatorInsetsExample() { |
| 24 | + const [automaticallyAdjustsScrollIndicatorInsets, setAutomaticallyAdjustsScrollIndicatorInsets] = React.useState(true); |
| 25 | + const [modalVisible, setModalVisible] = React.useState(false); |
| 26 | + const { height, width } = useWindowDimensions(); |
| 27 | + |
| 28 | + return ( |
| 29 | + <View> |
| 30 | + <Modal |
| 31 | + animationType="slide" |
| 32 | + visible={modalVisible} |
| 33 | + onRequestClose={() => setModalVisible(false)} |
| 34 | + presentationStyle="fullScreen" |
| 35 | + statusBarTranslucent={false} |
| 36 | + supportedOrientations={['portrait', 'landscape']}> |
| 37 | + <View style={styles.modal}> |
| 38 | + <ScrollView |
| 39 | + contentContainerStyle={[ |
| 40 | + styles.scrollViewContent, |
| 41 | + { |
| 42 | + height: (height * 1.2), |
| 43 | + width: (width * 1.2), |
| 44 | + }, |
| 45 | + ]} |
| 46 | + automaticallyAdjustsScrollIndicatorInsets={automaticallyAdjustsScrollIndicatorInsets} |
| 47 | + style={styles.scrollView}> |
| 48 | + <View style={styles.description}> |
| 49 | + <Text>When <Text style={styles.code}>automaticallyAdjustsScrollIndicatorInsets</Text> is true, the scrollbar is inset to the status bar. When false, it reaches the edge of the modal.</Text> |
| 50 | + <Text>Check out the UIScrollView docs to learn more about <Text style={styles.code}>automaticallyAdjustsScrollIndicatorInsets</Text></Text> |
| 51 | + </View> |
| 52 | + <View style={styles.toggle}> |
| 53 | + <Text><Text style={styles.code}>automaticallyAdjustsScrollIndicatorInsets</Text> is {automaticallyAdjustsScrollIndicatorInsets + ''}</Text> |
| 54 | + <Switch |
| 55 | + onValueChange={v => setAutomaticallyAdjustsScrollIndicatorInsets(v)} |
| 56 | + value={automaticallyAdjustsScrollIndicatorInsets} |
| 57 | + style={styles.switch}/> |
| 58 | + </View> |
| 59 | + <Button |
| 60 | + onPress={() => setModalVisible(false)} |
| 61 | + title="Close"/> |
| 62 | + </ScrollView> |
| 63 | + </View> |
| 64 | + </Modal> |
| 65 | + <Text /> |
| 66 | + <Button |
| 67 | + onPress={() => setModalVisible(true)} |
| 68 | + title="Present Fullscreen Modal with ScrollView"/> |
| 69 | + </View> |
| 70 | + ); |
| 71 | + } |
| 72 | + |
| 73 | +const styles = StyleSheet.create({ |
| 74 | + modal: { |
| 75 | + flex: 1, |
| 76 | + }, |
| 77 | + scrollView: { |
| 78 | + flex: 1, |
| 79 | + height: 1000, |
| 80 | + }, |
| 81 | + scrollViewContent: { |
| 82 | + alignItems: 'center', |
| 83 | + backgroundColor: '#ffaaaa', |
| 84 | + justifyContent: 'flex-start', |
| 85 | + paddingTop: 200, |
| 86 | + }, |
| 87 | + switch: { |
| 88 | + marginBottom: 40, |
| 89 | + }, |
| 90 | + toggle:{ |
| 91 | + margin: 20, |
| 92 | + alignItems: 'center', |
| 93 | + }, |
| 94 | + description: { |
| 95 | + marginHorizontal: 80, |
| 96 | + }, |
| 97 | + code: { |
| 98 | + fontSize: 10, |
| 99 | + fontFamily: 'Courier', |
| 100 | + }, |
| 101 | +}); |
| 102 | + |
| 103 | +exports.title = 'ScrollViewIndicatorInsets'; |
| 104 | +exports.category = 'iOS'; |
| 105 | +exports.description = |
| 106 | + 'ScrollView automaticallyAdjustsScrollIndicatorInsets adjusts scroll indicator insets using OS-defined logic on iOS 13+.'; |
| 107 | +exports.examples = [ |
| 108 | + { |
| 109 | + title: '<ScrollView> automaticallyAdjustsScrollIndicatorInsets Example', |
| 110 | + render: (): React.Node => <ScrollViewIndicatorInsetsExample/>, |
| 111 | + }, |
| 112 | +]; |
0 commit comments