react-native - 在 TextInput 中启用粘贴和选择 - React Native

标签 react-native

我正在尝试在我的 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/

相关文章:

javascript - React Native 从外部源加载 JSX 并在运行时对其进行转换

reactjs - 我如何限制 FlatList 中的项目并添加更多负载?

javascript - 如何触发TouchableOpacity的onPress事件?

ios - 将图像与 https 一起使用

javascript - 在连接上下文中找不到 "store"

javascript - 是否有 LayoutAnimation.Types 和 LayoutAnimation.Properties 的可用选项列表?

javascript - 如果我的对象中有一个数组并且该对象位于一个大数组中,我该如何更新 React Native 状态?

react-native - 在 AsyncStorage 中 setItem 的正确方法

django - LoginRequiredMixin 失败但用户已通过身份验证

android - com.android.ddmlib.InstallException : Failed to install all