React Native"interactive"keyboardDismissMode在拖动时抛出错误

TIM*_*MEX 8 react-native react-native-ios react-native-flatlist

错误是: RCTLayoutAnimationGroup expects timings to be in ms, not seconds

当我快速向下拖动键盘时会发生这种情况.有时候这种情况会发生; 有时它没有.

我在KeyboardAvoidingView中使用一个简单的TextInput组件

Luk*_*asz 5

向您的 ScrollView 添加反弹={false} 似乎解决了这个问题。

<ScrollView keyboardDismissMode="interactive" bounces={false}>
Run Code Online (Sandbox Code Playgroud)

它也稍微改变了行为,但是错误似乎不再出现。

我认为如果您希望保持 ScrollView 的“弹跳”行为,最好的方法是使“弹跳”依赖于键盘显示。显示键盘时,弹跳设置为 false。看看我的示例组件:

export default class App extends Component<Props> {

constructor(){
  super();
  this.state = {
    bounces: true
  }
  this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide.bind(this));
  this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow.bind(this));
}

_keyboardDidShow(){
  this.setState({bounces: false});
}

_keyboardDidHide(){
  this.setState({bounces: true});
}

  render() {
    return (
      <KeyboardAvoidingView style={styles.container}  behavior="padding" enabled>
      <ScrollView keyboardDismissMode="interactive" bounces={this.state.bounces}>
      <TextInput
        style={{height: 40, width: 150, borderColor: 'gray', borderWidth: 1}}
      />
      </ScrollView>

      </KeyboardAvoidingView>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

编辑:

当持续时间小于 10(ms) 时,RNT hack 将覆盖持续时间。对你来说应该改变:node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js 方法:scheduleLayoutAnimation改变:

const {duration, easing, endCoordinates} = event;
Run Code Online (Sandbox Code Playgroud)

到:

let {duration, easing, endCoordinates} = event;
Run Code Online (Sandbox Code Playgroud)

并添加:

if(duration < 10){
    duration = 10;
}
Run Code Online (Sandbox Code Playgroud)

if (duration && easing)条件中。

这将确保最短的持续时间是 1ms 并且永远不会更少,因此不会再抛出持续时间。

我的KeyboardAvoidingView.js_onKeyboardChange方法看起来像这样:

_onKeyboardChange = (event: ?KeyboardEvent) => {
    if (event == null) {
      this.setState({bottom: 0});
      return;
    }

    let {duration, easing, endCoordinates} = event;
    const height = this._relativeKeyboardHeight(endCoordinates);

    if (this.state.bottom === height) {
      return;
    }

    if (duration && easing) {
      if(duration < 10){
        duration = 10;
    }
      LayoutAnimation.configureNext({
        duration: duration,
        update: {
          duration: duration,
          type: LayoutAnimation.Types[easing] || 'keyboard',
        },
      });
    }
    this.setState({bottom: height});
  };
Run Code Online (Sandbox Code Playgroud)

编辑2:

我向RNT团队提交了一个问题,并向他们打开了一个PR:https : //github.com/facebook/react-native/pull/21858

编辑 3: 该修复程序已合并以响应本机大师:https : //github.com/facebook/react-native/commit/87b65339379362f9db77ae3f5c9fa8934da34b25