This is crappy shooting to get ScrollView's built-in keyboard functionality. For my Android application, it works fine on one screen, which is almost identical to another, for which it does not work. And on iOS, it just doesn't work. This is what works for me:
import { Keyboard, ScrollView, StyleSheet, View } from 'react-native'; this.state = { filler: false, } componentWillMount() { this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow.bind(this)); this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide.bind(this)); } componentWillUnmount() { this.keyboardDidShowListener.remove(); this.keyboardDidHideListener.remove(); } _keyboardDidShow() { this.setState({filler: true}) setTimeout(() => this.vertical && this.vertical.scrollToEnd({animated: true}), 0); } _keyboardDidHide() { this.setState({filler: false}) } ... return ( <ScrollView ref={ref => this.vertical = ref}> <TextInput/> { this.state.filler ? <View style={styles.filler}/> : null } </ScrollView> ) styles.filler = { height: 'Keyboard Height' }
Note. This can only work if your <TextInput/> is at the bottom of the screen, which was in my case.
Progoogler Feb 15 '18 at 17:59 2018-02-15 17:59
source share