我必须使用哪种方法来调用自动关注 stream-chat-react-native 的 messageInput

Which method I have to use for call auto focus on messageInput of stream-chat-react-native

我将在打开频道屏幕时对 stream-chat-react-native 消息输入应用自动对焦。 但是我找不到匹配的功能。 开发工具包:https://github.com/GetStream/stream-chat-react-native 为了以编程方式应用焦点,我应该怎么做?

为您的 InputComponent 设置自动对焦。首先,您需要为此任务使用 Class 组件,因为使用功能组件您无法引用您的 InputComponent。例如:

class Header extends React.Component {
  editText = null;
  const getRef = input = > {
    this.editText = input;
  }
  
  render() {

    if (this.editText) {
      this.editText.focus();
    }

    return (
      <SomeInputComponent
        placeholder="Поиск"
        onChangeText={text => onChangeText(text)}
        onBlur={e => onBlur(false)}
        ref={ref => this.getRef(ref)}
      />
    )
  }
}

因此您的 InputComponent 将被聚焦 f