[RN] React Native 分享弹窗 ShareAlertDialog
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的更多相关文章
- [RN] React Native 实现图片预览
[RN] React Native 实现图片预览 效果预览: 代码如下: 'use strict'; import React, {Component} from 'react'; import {I ...
- [RN] React Native 常见基本问题归纳总结
[RN] React Native 常见基本问题归纳总结 本问题总结涉及到版本为: "react": "16.8.3","react-native& ...
- [RN] React Native 关闭所有黄色警告
[RN] React Native 关闭所有黄色警告 console.ignoredYellowBox = ['Warning: BackAndroid is deprecated. Please u ...
- [RN] React Native 下实现底部标签(支持滑动切换)
上一篇文章 [RN] React Native 下实现底部标签(不支持滑动切换) 总结了不支持滑动切换的方法,此篇文章总结出 支持滑动 的方法 准备工作之类的,跟上文类似,大家可点击上文查看相关内容. ...
- [RN] React Native 幻灯片效果 Banner
[RN] React Native 幻灯片效果 Banner 1.定义Banner import React, {Component} from 'react'; import {Image, Scr ...
- [RN] React Native 常用命令行
[RN] React Native 常用命令行 1.查看当前版本 react-native --version 或 react-native -v 2.创建指定版本的React Native项目 1) ...
- [RN] React Native 实现 类似QQ 登陆页面
[RN] React Native 实现 类似QQ 登陆页面 一.主页index.js 项目目录下index.js /** * @format */ import {AppRegistry} from ...
- [RN] React Native 使用 阿里 ant-design
React Native 使用 阿里 ant-design 实例效果如图: 一.安装 npm install antd-mobile-rn --save npm install babel-plugi ...
- [RN] React Native 获取地理位置
React Native 获取地理位置 实现原理: 1.用 navigator.geolocation.getCurrentPosition 获取到坐标信息 2.调用 高德地图 接口,解析位置数据 ...
随机推荐
- drools -规则语法
文章结构 1. 基础api 2. FACT对象 3. 规则 4. 函数 1. 基础api 在 Drools 当中,规则的编译与运行要通过Drools 提供的各种API 来实现,这些API 总体来讲可以 ...
- Appium中app的元素定位
app定位方式,本文只讲Android手机的定位方式. 前提条件是adb连接到模拟器或者是手机(具体连接方式这里不再讲解),证明已连接到设备 adb devices app元素定位工具一:UI Aut ...
- ASP.NET SignalR 系列(八)之跨域推送
前面几章讲的都是同域下的推送和订阅.这种讲讲如何跨域 对于SignalR来说,默认是不允许跨域的,因为安全问题.虽如此,但同时提供了跨域方案. 两种跨域方式: 1:JSONP2:CORS JSONP的 ...
- js中 !==和 !=的区别是什么
1.比较结果上的区别 !=返回同类型值比较结果. !== 不同类型不比较,且无结果,同类型才比较. 2.比较过程上的区别 != 比较时,若类型不同,会偿试转换类型. !== 只有相同类型才会比较. 3 ...
- angular创建一个独立弹窗服务
1.说明: 这个服务用于创建一个modal(弹窗),通常下,这个弹窗会插入到body的底部,并且拥有自己的作用域($scope),也可以和外界通讯. 2.逻辑: (1).创建模版 (2).拿到模版里要 ...
- RxJS——可观察的对象(Observable)
可观察的(Observable) 可观察集合(Observables)是多值懒推送集合.它们填补了下面表格的空白: SINGLE MULTIPLE Pull Function Iterator Pus ...
- Golang: 读写之外的其他文件操作
在上一篇文章中,我们介绍了常用的文件读写操作,今天接着来研究一下,除了读写以外的其他常见文件操作. 一.创建目录: package main import ( "fmt" &quo ...
- 转:win10完美去除快捷方式小箭头
1.去掉小箭头 reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Ic ...
- Linux-crontab定时执行脚本配置
crontab是一个可以根据自己配置的命令定时执行脚本的服务 安装crontab(centos) yum install Vixie-cron yum install crontabs vixie-c ...
- 尾递归 递归函数中,递归调用是整个函数体中最后的语句,且它的返回值不属于表达式的一部分时,这个递归调用就是尾递归,空间复杂度是O(1)
什么是递归深度 递归深度就是递归函数在内存中,同时存在的最大次数. 例如下面这段求阶乘的代码: Java: int factorial(int n) { if (n == 1) { return 1; ...