使用 editable=true 和 dataDetectorTypes 响应 Native TextInput

ada*_*amF 6 textinput datadetectortypes react-native

我正在尝试创建一个可编辑且具有可点击网址的 TextInput 组件。根据 react native docs,仅当 editable={false} 时才支持 dataDetectorTypes 属性。

Determines the types of data converted to clickable URLs in the text input. Only valid if multiline={true} and editable={false}.
Run Code Online (Sandbox Code Playgroud)

有没有人找到解决这个限制的方法?好像应该是可以的。我想要的行为是...

  1. 点击 url 应该在浏览器中打开它
  2. 点击其他任何地方应该在该位置开始编辑
  3. 如果当 TextInput 当前具有焦点时链接不再可点击,那没关系

SKe*_*ney 1

我能想到的解决这个问题的唯一方法是将editable值存储在状态中,然后单击某个Edit按钮会将状态从状态更改editable为 true。

onBlur会将此状态切换回false

我之前没有尝试过,所以只是建议尝试解决方法或在两者之间找到一些中间立场。