React Native之Clipboard 复制文本

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/github_34402358/article/details/88568132
import React, { Component } from 'react';
import {
  Text,
  Clipboard,
  View,
  TouchableOpacity,
} from 'react-native';


export default class CopyContent extends Component {

  constructor(props) {
    super(props);
    this.state = {
      copyStr: '我是复制内容'
    }
  }

  async copyContent() {
    const { copyStr } = this.state;
    Clipboard.setString(copyStr);
    let str = await Clipboard.getString();
    console.warn(str);
  }

  render() {
    const { copyStr } = this.state;
    return (
      <View>
        <Text style={{ fontSize: 26 }}>{copyStr} </Text>
        <TouchableOpacity
            onPress={this.copyContent.bind(this)}
          >
        <Text style={{ fontSize: 26 }}>复制 </Text>
        </TouchableOpacity>
      </View>
    );
  }
}

练习项目

猜你喜欢

转载自blog.csdn.net/github_34402358/article/details/88568132