Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react native, how to paste text from clipboard into text input

currently i am using native base and having this type of text input for search bar

<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>

I wanted to enable paste from clipboard, where user can copy some text from other places and paste it on this search input box. How can i do that?

like image 909
user1897151 Avatar asked May 21 '26 18:05

user1897151


2 Answers

You can use the clipboard API : https://facebook.github.io/react-native/docs/clipboard or Textinput property : selectTextOnFocus

<TextInput selectTextOnFocus={true} />
like image 52
Tushar Nikam Avatar answered May 24 '26 08:05

Tushar Nikam


You can use this community package which is suggested by the official docs

@react-native-clipboard/clipboard

import Clipboard from '@react-native-clipboard/clipboard'

You can easily access clipboard text by invoking an async function

const text = await Clipboard.getString()
like image 37
Anthony Artemiev Avatar answered May 24 '26 08:05

Anthony Artemiev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!