代码之家  ›  专栏  ›  技术社区  ›  Noitidart

检测<TextInput>中是否按下了<Text>元素(iOS)

  •  0
  • Noitidart  · 技术社区  · 3 年前

    在iOS上,为了使我的文本可选,我使用了 <TextInput> 像这样的孩子:

    const linkRef = useRef(null);
    
    const handlePressIn = e => {
      const pressedNodeHandle = e.nativeEvent.target;
      const linkNodeHandle = findNodeHandle(linkRef.current);
      const didPressLink = String(pressedNodeHandle) === String(linkNodeHandle);
      console.log({ pressedNodeHandle, linkNodeHandle, didPressLink });
    };
    
    return (
      <TextInput onPressIn={handlePressIn} multiline editable={false}>
        [<Text style={styles.blue} ref={linkRef}>lorem</Text>, 'and ipsum and foo and bar and qux and baz']
      </TextInput>
    )
    

    但是,即使按下 <Text> 我的 onPressIn 处理程序未检测到按下了正确的节点。有人知道怎么解决这个问题吗?

    0 回复  |  直到 3 年前
    推荐文章