showing results for - "scroll to a input on button click react native"
Ariana
16 Oct 2020
1I cant gurantee this is the best approach.
2
3Add this.scroll.scrollTo({ x: calculatedStartPositionOfTheScreen}) to your button Press handler https://facebook.github.io/react-native/docs/scrollview#scrollto
4
5e.g
6
7<View>
8    ...
9    <View style={styles.ButtonContainer}>
10        <Button title="Screen 1" onPress={() => { this.scroll.scrollTo({ x: 0 }) }} />
11    </View>
12    <View style={styles.ButtonContainer}>
13        <Button title="Screen 2" onPress={() => { this.scroll.scrollTo({ x: screenWidth }) }} />
14    </View>
15    <View style={styles.ButtonContainer}>
16        <Button title="Screen 3" onPress={() => { this.scroll.scrollTo({ x: screenWidth * 2 }) }} />
17    </View>
18    ...
19    <ScrollView
20        horizontal={true}
21        pagingEnabled={true}
22        showsHorizontalScrollIndicator={false}
23        ref={(node) => this.scroll = node}
24    >
25    ...
26    </ScrollView>
27</View >