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. Windwos利用批处理文件自动清理归档日志,计划任务

    首先在X盘根目录建立一个文档  cmd.txt 打开cmd.txt这个文本文件,在里面第一行写入 DELETE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-3'; ...

  2. JavaScript---正则使用,日期Date的使用,Math的使用,JS面向对象(工厂模式,元模型创建对象,Object添加方法)

    JavaScript---正则使用,日期Date的使用,Math的使用,JS面向对象(工厂模式,元模型创建对象,Object添加方法) 一丶正则的用法 创建正则对象: 方式一: var reg=new ...

  3. 为什么会有jQuery、Dojo、Ext、Prototype、YUI、Zepto这么多JS包?

    目前流行的JS框架很多Dojo .Scriptaculous .Prototype .yui-ext .Jquery .Mochikit.mootools .moo.fx 等.当然还有很多我都不熟悉的 ...

  4. 05-Vue组件

    定义Vue组件 什么是组件: 组件的出现,就是为了拆分Vue实例的代码量的,能够让我们以不同的组件,来划分不同的功能模块,将来我们需要什么样的功能,就可以去调用对应的组件即可: 组件化和模块化的不同: ...

  5. Python 列表推导式、矩阵、格式化输出

    列表推导式 列表推导式提供了从列表.元组创建列表的简单途径.语法: [表达式 for语句 if语句] 创建并返回一个列表.if语句可选. 示例: list1=[1,2,3,4] #使用元组也行 lis ...

  6. VS code key shortcuts for windows

    mac上的快捷键,尽量是选择像我用vs studio上靠近. ctrl+K+S: 显示快捷键列 ctrl+shift+p: 系统配置命令行 ctrl+p:项目中文件列表,选择文件 Alt+M:当前文件 ...

  7. git设置本地账户

    问题描述: git很方便,git本地如果记住账户信息 问题解决: vscode Git 全局设置: git config --global user.name "mvpbang" ...

  8. docker启动报错 docker: Error response from daemon: OCI runtime create failed: container_linux.go:348

    问题描述 doker启动时,报错:docker: Error response from daemon: OCI runtime create failed: container_linux.go:3 ...

  9. 洛谷 P1330 封锁阳光大学题解

    题目描述 曹是一只爱刷街的老曹,暑假期间,他每天都欢快地在阳光大学的校园里刷街.河蟹看到欢快的曹,感到不爽.河蟹决定封锁阳光大学,不让曹刷街. 阳光大学的校园是一张由N个点构成的无向图,N个点之间由M ...

  10. 算法——dfs 判断是否为BST

    95. 验证二叉查找树 中文English 给定一个二叉树,判断它是否是合法的二叉查找树(BST) 一棵BST定义为: 节点的左子树中的值要严格小于该节点的值. 节点的右子树中的值要严格大于该节点的值 ...