我正在尝试在我的 TextInput 中实现复制和粘贴,但似乎无法实现。当我长按 TextInput 时,我期待着一个工具提示,但没有任何 react 。
我了解剪贴板并知道如何实现它,但我似乎无法将粘贴选项弹出给用户。
我有什么想法可以实现这一目标吗?
<TextInput
maxLength={29}
autoCapitalize={'characters'}
numberOfLines={1}
keyboardType={'default'}
underlineColorAndroid='transparent'
autoCorrect={false}
value={IBAN.printFormat(this.state.ibanInput)}
returnKeyType={'next'}
onChangeText={iban => this.verifyIban(iban)}
style={[{ borderWidth: 1, borderRadius: 2, height: '100%', width: '100%', textAlign: 'center', fontSize: width/24 },
]}
/>
最佳答案
如果复制/粘贴不适用于 TextInput,这是答案 - React Native
步骤 1) 在构造函数中,将 testWidth 属性赋值为“99%”。
例如this.state = {testWidth: '99%' };
步骤 2) 在 componentDidMount 中更改 testWidth 值,如“100%”,在 setTimeout 内进行。
例如
setTimeout(() => {
this.setState({ testWidth: '100%' })
}, 100)
步骤 3) 在 TextInput 的 style 属性中添加我们在 Contractor 中声明的动态宽度,例如
<TextInput style={{ width: this.state.testWidth }} />
这是完整的代码:(只需复制并粘贴到 App.js 文件中)。
import React, { Component } from 'react';
import { TextInput, View } from 'react-native';
export class App extends Component {
constructor(props) {
super(props);
this.state = { text: '', testWidth: '99%' };
}
componentDidMount() {
setTimeout(() => {
this.setState({ testWidth: '100%' })
}, 100)
}
render() {
return (
<View style={{ marginTop: 50 }}>
<TextInput
style={{ width: this.state.testWidth }}
placeholder="Type here to translate!"
onChangeText={(text) => this.setState({ text })}
value={this.state.text}
/>
</View>
);
}
}
祝你好运
关于react-native - 在 TextInput 中启用粘贴和选择 - React Native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50655600/