componentWillUnmount() { this.keyboardDidShowListener.remove(); this.keyboardDidHideListener.remove();} componentWillMount() { this.keyboardDidShowListener = Keyboard.addListener(‘keyboardDidShow‘, this._keyboardDidShow.bind(this)); this.keyboardDidHideListener = Keyboard.addListener(‘keyboardDidHide‘, this._keyboardDidHide.bind(this));} _keyboardDidShow(e) { async function run(self) { await self.setState({ keyboardHeight: e.endCoordinates.height }); self.refs.scroll.scrollTo({ x: 0, y: self.state.keyboardHeight, animated: true }) } run(this);} _keyboardDidHide(e) { this.setState({ keyboardHeight: 0 })}
时间: 2024-11-10 02:34:01