微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

currentFocusedField 正在被弃用,在 React Native

如何解决currentFocusedField 正在被弃用,在 React Native

下午好, 在我更改 react-navigation node_modules 中的 createKeyboardAwareNavigator.js 文件后,我得到 currentFocusedField 使用 FocusedInput。 我在我的项目目录中搜索了 currentFocusedField 的其他实例,但没有。我是否缺少在更改后重建 node_modules 的步骤?

import React from 'react';
import { TextInput } from 'react-native';

export default (Navigator,navigatorConfig) =>
  class KeyboardAwareNavigator extends React.Component {
    static router = Navigator.router;
    static navigationoptions = Navigator.navigationoptions;
    _prevIoUslyFocusedTextInput = null;

    _handleGestureBegin = () => {
      this._prevIoUslyFocusedTextInput = TextInput.State.currentlyFocusedinput();
      if (this._prevIoUslyFocusedTextInput) {
        TextInput.State.blurTextInput(this._prevIoUslyFocusedTextInput);
      }
      this.props.onGestureBegin && this.props.onGestureBegin();
    };

    _handleGestureCanceled = () => {
      if (this._prevIoUslyFocusedTextInput) {
        TextInput.State.focusTextInput(this._prevIoUslyFocusedTextInput);
      }
      this.props.onGestureCanceled && this.props.onGestureCanceled();
    };

    _handleGestureEnd = () => {
      this._prevIoUslyFocusedTextInput = null;
      this.props.onGestureFinish && this.props.onGestureFinish();
    };

    _handleTransitionStart = (transitionProps,prevTransitionProps) => {
      // Todo: We should not even have received the transition start event
      // in the case where the index did not change,I believe. We
      // should revisit this after 2.0 release.
      if (transitionProps.index !== prevTransitionProps.index) {
        const currentField = TextInput.State.currentlyFocusedinput();
        if (currentField) {
          TextInput.State.blurTextInput(currentField);
        }
      }

      const onTransitionStart =
        this.props.onTransitionStart || navigatorConfig.onTransitionStart;
      onTransitionStart &&
        onTransitionStart(transitionProps,prevTransitionProps);
    };

    render() {
      return (
        <Navigator
          {...this.props}
          onGestureBegin={this._handleGestureBegin}
          onGestureCanceled={this._handleGestureCanceled}
          onGestureEnd={this._handleGestureEnd}
          onTransitionStart={this._handleTransitionStart}
        />
      );
    }
  };

解决方法

问题是 VSCode 有一个奇怪的过滤器,它没有显示我正在搜索的函数的所有实例,但是一旦我更改了过滤器并更改了它工作的所有实例。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。