zoukankan      html  css  js  c++  java
  • react native 中函数Share示例与说明

    /**
    * 函数Share(用于在Android设备上打开一个对话框来分享或发送文本内容)
    * */

    import React,{PureComponent} from 'react'
    import {View,Text,TouchableOpacity, Share} from 'react-native'

    class ShareFunction extends PureComponent {
    constructor(props) {
    super(props);
    this.state = {
    result: ''
    };
    }
    render() {
    return (
    <View>
    <TouchableOpacity onPress={()=>Share.share({
    message: '这个是百度的网址'
    },{
    dialogTitle: '分享和发送'})}
    style={{height:50,backgroundColor:'#0f0',borderRadius:30,marginTop:30,justifyContent:'center',alignItems:'center'}}
    >
    <View>
    <Text>简单</Text>
    <Text style={{textAlign:'center'}}>分享和发送(Share)</Text>
    </View>
    </TouchableOpacity>
    <TouchableOpacity onPress={this._shareMessage}
    style={{height:50,backgroundColor:'#0f0',borderRadius:30,marginTop:30,justifyContent:'center',alignItems:'center'}}
    >
    <View>
    <Text style={{textAlign:'center'}}>分享和发送URL(Share)</Text>
    </View>
    </TouchableOpacity>
    <TouchableOpacity onPress={this._shareText}
    style={{height:50,backgroundColor:'#0f0',borderRadius:30,marginTop:30,justifyContent:'center',alignItems:'center'}}
    >
    <View>
    <Text style={{textAlign:'center'}}>分享和发送(Share)</Text>
    </View>
    </TouchableOpacity>
    <Text style={{marginTop:50}}>{this.state.result}</Text>
    </View>
    );
    }
    _shareMessage=()=> {
    Share.share({
    message: '这个是百度的网址t'
    })
    .then(this._showResult)
    .catch((error) => this.setState({result: '错误提示: ' + error.message}));
    };

    _shareText=()=> {
    Share.share({
    message: '这个是百度的网址',
    url: 'https://www.baidu.com',
    title: '百度'
    }, {
    dialogTitle: '分享百度链接到',
    })
    .then(this._showResult)
    .catch((error) => this.setState({result: '错误提示: ' + error.message}));
    };
    //判断是否分享成功
    _showResult=(result)=> {
    if (result.action === Share.sharedAction) {
    if (result.activityType) {
    this.setState({result: 'shared with an activityType: ' + result.activityType});
    } else {
    this.setState({result: '分享成功'});
    }
    } else if (result.action === Share.dismissedAction) {
    this.setState({result: '分享拒绝'});
    }
    }
    }

    export default ShareFunction;

    /***
    static share(content, options)

    打开一个对话框来共享文本内容。

    在Android中,返回一个Promise,它始终使用Share.sharedAction操作来解决。

    Content
    message - 要分享的消息至少需要一个
    title - 消息的标题
    Options

    dialogTitle
    //对话框标题,默认为选择操作
    static sharedAction()

    内容已成功共享。.

    static dismissedAction()

    该对话框已被拒绝. @platform ios


    * ***/
  • 相关阅读:
    maven项目的导包问题,已经加载jar包了可是idea检测不到
    spark MLlib矩阵四则运算,线性代数
    maven spark Scala idea搭建maven项目的 pom.xml文件配置
    tensorflow2.0 numpy.ndarray 与tenor直接互转
    TensorFlow2.0矩阵与向量的加减乘
    Ubuntu14.04下Nginx反向代理Odoo域名
    Geforce experience报错:something went wrong try restarting geforce
    github的代码上传成功但是不显示绿格子(一直拖....心痛的教训.....)
    mapper文件提示:No data sources are configured to run this sql
    Pycharm中SQL语句提示SQL Dialect is Not Configured
  • 原文地址:https://www.cnblogs.com/zhuyupingit/p/7667934.html
Copyright © 2011-2022 走看看