React Native 分享弹窗 ShareAlertDialog

ShareAlertDialog.js文件

/**
* 分享弹窗
*/
import React, {Component} from 'react';
import {View, TouchableOpacity, Alert, StyleSheet, Dimensions, Modal, Text, Image} from 'react-native'; const {width, height} = Dimensions.get('window');
const dialogH = ; export default class ShareAlertDialog extends Component { constructor(props) {
super(props);
this.state = {
isVisible: this.props.show,
};
} componentWillReceiveProps(nextProps) {
this.setState({isVisible: nextProps.show});
} closeModal() {
this.setState({
isVisible: false
});
this.props.closeModal(false);
} renderDialog() {
return (
<View style={styles.modalStyle}>
<Text style={styles.text}>分享到</Text> <View style={styles.divide}/> <View style={styles.optArea}>
<TouchableOpacity style={styles.item} onPress={() => Alert.alert('分享')}>
<Image resizeMode='contain' style={styles.image}
source={require('./icon_share_qq.png')}/>
<Text style={styles.itemText}>QQ好友</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.item}>
<Image resizeMode='contain' style={styles.image}
source={require('./icon_share_wxsession.png')}/>
<Text style={styles.itemText}>微信好友</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.item}>
<Image resizeMode='contain' style={styles.image}
source={require('./icon_share_wxtimeline.png')}/>
<Text style={styles.itemText}>朋友圈</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.item}>
<Image resizeMode='contain' style={styles.image}
source={require('./icon_share_qq.png')}/>
<Text style={styles.itemText}>复制链接</Text>
</TouchableOpacity> </View> <View style={styles.divide}/> <TouchableOpacity style={styles.cancel} onPress={() => this.closeModal()}>
<Text style={styles.cancelText}>取消</Text>
</TouchableOpacity>
</View>
)
} render() { return (
<View style={{flex: }}>
<Modal
transparent={true}
visible={this.state.isVisible}
animationType={'fade'}
onRequestClose={() => this.closeModal()}>
<TouchableOpacity style={styles.container} activeOpacity={}
onPress={() => this.closeModal()}>
{this.renderDialog()}
</TouchableOpacity>
</Modal>
</View>
);
}
} const styles = StyleSheet.create({
container: {
flex: ,
backgroundColor: 'rgba(0, 0, 0, 0.5)',
},
modalStyle: {
position: "absolute",
left: ,
bottom: ,
width: width,
flex: ,
flexDirection: "column",
backgroundColor: '#ffffff',
},
subView: {
width: width,
height: dialogH,
backgroundColor: '#ffffff'
},
text: {
flex: ,
fontSize: ,
paddingTop: ,
paddingBottom: ,
justifyContent: 'center',
alignItems: 'center',
alignSelf: 'center'
},
optArea: {
flex: ,
flexDirection: 'row',
marginTop: ,
marginBottom: ,
},
item: {
width: width / ,
alignItems: 'center',
},
itemText: {
fontSize: ,
},
cancel: {
width: width,
height: ,
marginTop: ,
alignItems: 'center',
backgroundColor: '#ffffff'
},
cancelText: {
fontSize: ,
},
image: {
width: ,
height: ,
marginBottom: ,
},
divide: {
width: width,
height: 0.5,
backgroundColor: "#ccc",
}
});

调用代码:

import React, {Component} from "react";
import {StyleSheet, Text, TouchableHighlight, View,} from 'react-native';
import ShareAlertDialog from "./ShareAlertDialog"; export default class TestShareModal extends Component {
constructor(props) {
super(props);
this.state = {
showSharePop: false,//分享弹窗,默认不显示
}
} _share() {
this.setState({showSharePop: !this.state.showSharePop})
} render() {
return (
<View style={{flex: }}> <TouchableHighlight onPress={() => this._share()} style={styles.button} underlayColor="#a5a5a5">
<Text>点击分享</Text>
</TouchableHighlight> <ShareAlertDialog show={this.state.showSharePop} closeModal={(show) => {
this.setState({
showSharePop: show
})
}}/>
</View>
); }
} const styles = StyleSheet.create({
button: {
margin: ,
backgroundColor: 'white',
padding: ,
borderBottomWidth: StyleSheet.hairlineWidth,
borderBottomColor: '#cdcdcd'
},
});

本博客地址: wukong1688

本文原文地址:https://www.cnblogs.com/wukong1688/p/10967254.html

转载请著名出处!谢谢~~

[RN] React Native 分享弹窗 ShareAlertDialog的更多相关文章

  1. [RN] React Native 实现图片预览

    [RN] React Native 实现图片预览 效果预览: 代码如下: 'use strict'; import React, {Component} from 'react'; import {I ...

  2. [RN] React Native 常见基本问题归纳总结

    [RN] React Native  常见基本问题归纳总结 本问题总结涉及到版本为: "react": "16.8.3","react-native& ...

  3. [RN] React Native 关闭所有黄色警告

    [RN] React Native 关闭所有黄色警告 console.ignoredYellowBox = ['Warning: BackAndroid is deprecated. Please u ...

  4. [RN] React Native 下实现底部标签(支持滑动切换)

    上一篇文章 [RN] React Native 下实现底部标签(不支持滑动切换) 总结了不支持滑动切换的方法,此篇文章总结出 支持滑动 的方法 准备工作之类的,跟上文类似,大家可点击上文查看相关内容. ...

  5. [RN] React Native 幻灯片效果 Banner

    [RN] React Native 幻灯片效果 Banner 1.定义Banner import React, {Component} from 'react'; import {Image, Scr ...

  6. [RN] React Native 常用命令行

    [RN] React Native 常用命令行 1.查看当前版本 react-native --version 或 react-native -v 2.创建指定版本的React Native项目 1) ...

  7. [RN] React Native 实现 类似QQ 登陆页面

    [RN] React Native 实现 类似QQ 登陆页面 一.主页index.js 项目目录下index.js /** * @format */ import {AppRegistry} from ...

  8. [RN] React Native 使用 阿里 ant-design

    React Native 使用 阿里 ant-design 实例效果如图: 一.安装 npm install antd-mobile-rn --save npm install babel-plugi ...

  9. [RN] React Native 获取地理位置

    React Native 获取地理位置 实现原理: 1.用  navigator.geolocation.getCurrentPosition 获取到坐标信息 2.调用 高德地图 接口,解析位置数据 ...

随机推荐

  1. Java基础扫盲系列(-)—— String中的format

    Java基础扫盲系列(-)-- String中的format 以前大学学习C语言时,有函数printf,能够按照格式打印输出的内容.但是工作后使用Java,也没有遇到过格式打印的需求,今天遇到项目代码 ...

  2. -UI调试工具 SAK 布局 MD

    目录 目录 SwissArmyKnife 接入方式 自动初始化版本 支持的功能 可配置项 原理 自定义功能 Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndro ...

  3. Azkaban 3.x 编译及部署

    一.Azkaban 源码编译 1.1 下载并解压 Azkaban 在 3.0 版本之后就不提供对应的安装包,需要自己下载源码进行编译. 下载所需版本的源码,Azkaban 的源码托管在 GitHub ...

  4. 字符串格式连接sqlserver数据库的字段概念解释

    以连接sqlserver数据库举例说明如:“Provider=SQLOLEDB.1;Password=******;Persist Security Info=True;User ID=sa;Init ...

  5. java。JDK的API,版本1.6.0中文版下载

    转载自https://blog.csdn.net/xiao9469/article/details/87783561 链接: https://pan.baidu.com/s/1YqrbTD_msTmn ...

  6. Java自学-接口与继承 隐藏

    Java中的方法隐藏 与重写类似,方法的重写是子类覆盖父类的对象方法 隐藏,就是子类覆盖父类的类方法 步骤 1 : 父类 父类有一个类方法 :battleWin package charactor; ...

  7. Windows中常用工具

    护眼软件 f.lux https://justgetflux.com/ Typora https://www.typora.io/ Markdown工具,小巧,方便. Snipaste https:/ ...

  8. 量化金融策略开源框架:QUANTAXIS

    简介: QUANTAXIS量化金融策略框架,是一个面向中小型策略团队的量化分析解决方案,是一个从数据爬取.清洗存储.分析回测.可视化.交易复盘的本地一站式解决方案. QUANTAXIS量化金融策略框架 ...

  9. 利用 Docker 搭建 IPFS 私有网络

    利用 Docker 搭建 IPFS 私有网络 本文原始地址:https://sitoi.cn/posts/40630.html 下载项目 项目地址:https://github.com/Sitoi/p ...

  10. lavavel 定时任务 (command的第二个参数)

    之前好像没有写过,记录一下 $schedule->command()方法 第一个参数不用说,可以传纯字符串或者类::class,不过第二个参数确很少人提到 /** * Add a new Art ...