【问题标题】:Animated view height when keyboardDismissMode is interactive [react-native]keyboardDismissMode 交互时的动画视图高度 [react-native]
【发布时间】:2016-05-22 22:48:58
【问题描述】:

我有一个View,当我点击输入时会显示键盘,但是当我向下拖动以隐藏键盘时,动画没有触发以调整视图大小。

动画视图

<Animated.View style={{ height: keyboardSpace }}>
  <ScrollView
    ref="addScrollView"
    keyboardShouldPersistTaps={ true }
    keyboardDismissMode="interactive"
  >
    {...}
  </ScrollView>
</Animated.View>

以及显示和隐藏键盘的功能

  _keyboardWillShow(e) {
    const { keyboardSpace } = this.state;
    const newHeight = (height - HEADER_HEIGHT) - e.endCoordinates.height;

    Animated.timing(this.state.keyboardSpace, {
      easing: Easing.inOut(Easing.ease),
      duration: 250,
      toValue: newHeight
    }).start();
  },

  _keyboardWillHide() {
    const { keyboardSpace } = this.state;

    Animated.timing(keyboardSpace, {
      easing: Easing.inOut(Easing.ease),
      duration: 250,
      toValue: height - HEADER_HEIGHT
    }).start();
  },

这里有一个小视频来说明这里的问题:https://vid.me/E3oU

你可以在这里找到源代码:https://github.com/statiks/statiks-react-native/blob/master/sources/add/index.js

【问题讨论】:

    标签: javascript ios keyboard react-native animated


    【解决方案1】:

    Keyboard 模块与keyboardDidShowkeyboardDidHide 事件一起使用:

    import {Keyboard} from 'react-native'
    
    //...
    
    componentDidMount() {
      Keyboard.addListener('keyboardDidShow', this.handleKeyboardShow)
      Keyboard.addListener('keyboardDidHide', this.handleKeyboardHide)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-13
      • 1970-01-01
      • 2020-06-09
      • 1970-01-01
      • 2021-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多