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 API之Ramdom--用代码模拟猜数小游戏

    常用Java API之Ramdom Ramdom类用来生成随机数字.使用起来也是三个步骤: 1.导包 import java.util.Random; 2.创建 Random r = new Rand ...

  2. switch/case/default中的雷区

    switch的语法如下: switch(表达式){ case常量表达式1: 语句1;break; case常量表达式2: 语句2;break; - case常量表达式n: 语句n;break; def ...

  3. Channel概述

    前言 前两篇文章介绍了NIO核心部分部分之一的缓冲区的相关内容,接下来我们继续学习NIO中另一个重要的核心部分--Channel(通道). 在学习这篇文章之前,先做下简单的说明,本文是一篇关于通道的概 ...

  4. 转Tasklist(windows)

    Windows 进程 Tasklist查看 与 Taskkill结束   转自https://blog.csdn.net/wangmx1993328/article/details/80923829 ...

  5. 当Windows操作系统关机时,不会执行Windows Service的OnStop方法(转载)

    Windows Service OnStop when computer shutdown 问: I'm writing a Windows Service in C#. I want to take ...

  6. Java自学-I/O File类

    Java 的File类,以及常用方法 文件和文件夹都是用File代表 步骤 1 : 创建一个文件对象 使用绝对路径或者相对路径创建File对象 package file; import java.io ...

  7. UIPath RPA 自动化脚本 机器人从入门到精通

    本文链接:https://blog.csdn.net/qq_27256783/article/details/93619818 一.UiPath介绍 UiPath 是RPA(Robotic Proce ...

  8. 92.vue---新手从本地项目开发到服务器线上运行爬坑。

    因为我做的是后台,所以不用做SEO 参考 本项目的定位是后台集成方案,不太适合当基础模板来进行二次开发.因为本项目集成了很多你可能用不到的功能,会造成不少的代码冗余.如果你的项目不关注这方面的问题,也 ...

  9. Vue Nginx反向代理配置 解决生产环境跨域

    Vue本地代理举例: module.exports = { publicPath: './', devServer: { proxy: { '/api': { target: 'https://mov ...

  10. 非root安装rpm时,mockbuild does not exist - using root

    1.现象 [fedora@k8s-cluster--ycmwlao4q5wz-minion- ~]$ [fedora@k8s-cluster--ycmwlao4q5wz-minion- ~]$ sud ...