反应本机,如何将剪贴板中的文本粘贴到文本输入中

时间:2018-08-31 05:49:05

标签: javascript react-native

当前我正在使用本机库,并在搜索栏中输入了此类文本

<Text>
   Card Name
</Text>
<Header searchBar rounded style={{ backgroundColor: '#E9E9EF'}}> 
   <Item style={{ backgroundColor: 'lightgray', borderRadius: 5 }}>
      <Icon name="ios-search" />
      <Input placeholder="Search" onChangeText={(searchText) => this.setState({searchText})} value={this.state.searchText} />
   </Item>
</Header>

我想启用从剪贴板粘贴的功能,用户可以在剪贴板上从其他位置复制一些文本并将其粘贴到此搜索输入框中。我该怎么办?

5 个答案:

答案 0 :(得分:0)

您可以使用剪贴板API:https://facebook.github.io/react-native/docs/clipboard 或Textinput属性:selectTextOnFocus

<TextInput selectTextOnFocus={true} />

答案 1 :(得分:0)

如果在本机中Text / Input的复制/粘贴不起作用。您可以按照以下代码进行操作。

    // C++ code
    extern "C" void f(int); // one way
    extern "C" {    // another way
        int g(double);
        double h();
    };
    void code(int i, double d)
    {
        f(i);
        int ii = g(d);
        double dd = h();
        // ...
    }  

答案 2 :(得分:0)

此Git答复中找到的解决方案对我来说效果更好:https://github.com/facebook/react-native/issues/18926#issuecomment-490541013

 <ScrollView
contentContainerStyle={Styles.contentContainerStyle}
keyboardShouldPersistTaps="handled"
removeClippedSubviews={false}>

 <KeyboardAvoidingView>

      <Text style={Styles.labelPageTitle}>
        {'bla bla bla'}
      </Text>
      <Text>
          {'bla bla bla'}
      </Text>
      <TextInput
        onChangeText={text => this.setState({ title: text })}
        style={Styles.textInput}
        value={title}
      />

</KeyboardAvoidingView>

答案 3 :(得分:0)

用户RN手势处理程序的TextInput,而不是React Native的 从'react-native-gesture-handler'导入{TextInput};

添加以下内容 selectTextOnFocus = {true} 到TexInput

答案 4 :(得分:-4)

这是TextInput secureTextEntry={true}中的参数