React Native 自定义 底部选择框 实现

效果如图所示:

实现方法:

一、组件封装

CustomAlertDialog.js
import React, {Component} from 'react';
import {Dimensions, Modal, StyleSheet, Text, TouchableOpacity, View} from 'react-native';const {width} = Dimensions.get('window');
export default class CustomAlertDialog extends Component {constructor(props) {super(props);this.state = {isVisible: this.props.show,};this.entityList = this.props.entityList;}componentWillReceiveProps(nextProps) {this.setState({isVisible: nextProps.show});}closeModal() {this.setState({isVisible: false});this.props.closeModal(false);}renderItem(item, i) {return (<TouchableOpacity key={i} onPress={this.choose.bind(this, i)} style={styles.item}><Text style={styles.itemText}>{item}</Text></TouchableOpacity>);}choose(i) {if (this.state.isVisible) {this.props.callback(i);this.closeModal();}}renderDialog() {return (<View style={styles.modalStyle}><View style={styles.optArea}>{this.entityList.map((item, i) => this.renderItem(item, i))}</View></View>)}render() {return (<View style={{flex: 1}}><Modaltransparent={true}visible={this.state.isVisible}animationType={'fade'}onRequestClose={() => this.closeModal()}><TouchableOpacity style={styles.container} activeOpacity={1}onPress={() => this.closeModal()}>{this.renderDialog()}</TouchableOpacity></Modal></View>);}
}const styles = StyleSheet.create({container: {flex: 1,backgroundColor: 'rgba(0, 0, 0, 0.5)',},modalStyle: {position: "absolute",left: 0,bottom: 0,width: width,flex: 1,flexDirection: "column",backgroundColor: '#ffffff',},optArea: {flex: 1,flexDirection: 'column',marginTop: 12,marginBottom: 12,},item: {width: width,height: 40,paddingLeft: 20,paddingRight: 20,alignItems: 'center',},itemText: {fontSize: 16,},cancel: {width: width,height: 30,marginTop: 12,alignItems: 'center',backgroundColor: '#ffffff'},
});

使用

TestCustomAlert.js

import React, {Component} from "react";
import {StyleSheet, Text, TouchableHighlight, View,} from 'react-native';
import CustomAlertDialog from "./CustomAlertDialog";const typeArr = ["不限", "男", "女"];export default class TestCustomAlert extends Component {constructor(props) {super(props);this.state = {typeName: '性别',type: 0,showTypePop: false,}}_openTypeDialog() {this.setState({showTypePop: !this.state.showTypePop})}render() {return (<View style={{flex: 1}}><TouchableHighlight onPress={() => this._openTypeDialog()} style={styles.button}underlayColor="#a5a5a5"><Text>{this.state.typeName}-{this.state.type}</Text></TouchableHighlight><CustomAlertDialog entityList={typeArr} callback={(i) => {this.setState({type: i,typeName: typeArr[i],})}} show={this.state.showTypePop} closeModal={(show) => {this.setState({showTypePop: show})}}/></View>);}
}const styles = StyleSheet.create({button: {margin: 3,backgroundColor: 'white',padding: 10,borderBottomWidth: StyleSheet.hairlineWidth,borderBottomColor: '#cdcdcd'},
});

本博客地址: wukong1688

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

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

转载于:https://www.cnblogs.com/wukong1688/p/11038382.html

[RN] React Native 自定义 底部 弹出 选择框 实现相关推荐

  1. Android底部弹出选择框PickerView的使用

    希望大家可以留个关注点赞,后续会有更多的技术分享 前言 本次主要介绍Android中底部弹出框的使用,使用两个案例来说明,首先是时间选择器,然后是自定义底部弹出框的选择器,以下来一一说明他们的使用方法 ...

  2. html自定义js程序,JS中微信小程序自定义底部弹出框

    实现微信小程序底部弹出框效果,代码分为html,css和js两部分,具体代码详情大家参考下本文. html CSS .commodity_screen { width: 100%; height: 1 ...

  3. android的底部弹出框炫酷的样式,Android自定义底部弹出框ButtomDialog

    本文实例为大家分享了Android自定义底部弹出框的具体代码,供大家参考,具体内容如下 先看看效果和你要的是否一样 一 .先来配置自定义控件需要的资源 1.在res文件夹下创建一个anim文件夹并创建 ...

  4. Android自定义底部弹出窗-dialog(2种实现分析+源码)

    Android自定义底部弹出窗-dialog(2种实现分析+源码) 上线项目功能抽取,在项目开发中,我们会在许多地方会用到底部自定义弹窗,比如设置:个人账户退出,切换,照片的拍照或者相册的调出,或者一 ...

  5. 微信小程序 -- 自定义底部弹出框(带动画--滑入滑出)

    实现这么一个功能,点击选项进行选择,效果是从底部弹出选项框(带滑出动画),选择了某项或者点击其他地方,隐藏(带滑出动画).效果图如下: 可适用于任何场景,如普通选项(如图)或者类似商城小程序选择商品属 ...

  6. JSP页面的日期控件可以弹出选择框选择日期

    JSP页面的日期控件可以弹出选择框选择日期 input框的如下 <input type="text" name="starttime" readonly= ...

  7. Android——完全自定义 底部弹出支付页面

    近期博主在网上随便搜了一番,发现很多实现 底部弹出支付页面的大多数都用的,自定义PopupWindow 去实现的,里面复杂的逻辑看得我不想看,很多对自定义不熟悉伙伴们,看到 自定义 这三个字就有种血脉 ...

  8. [RN] React Native 自定义导航栏随滚动渐变

    React Native 自定义导航栏随滚动渐变 实现效果预览: 代码实现: 1.定义导航栏 NavPage.js import React, {Component} from 'react'; im ...

  9. jQuery日期弹出选择框Datepicker效果

    无论你是一个机票在线预定网站设计师,还是一个工程任务管理者,抑或在你的注册表单上有个生日填写项目:本文即将提到的日历日期选择弹出窗口都将帮助你简化用户操作,提高网站的用户体验和易用性. 教程目标:教会 ...

最新文章

  1. hive 学习之异常篇
  2. Redis为什么使用单进程单线程方式也这么快
  3. java字符生成器_Java实现简单字符生成器代码例子
  4. SLAM到底解决的是什么问题?
  5. 为您详细解析防火墙的工作原理
  6. java基础—网络编程——TCP客户端与服务端交互
  7. django1.9的static文件配置
  8. java请求报错(原因:CORS 头缺少 ‘Access-Control-Allow-Origin‘)
  9. 如何判定耿耿数已经被bind过?
  10. Mysql 分组求和
  11. 单打打法类型及技、战术特点
  12. What is a computer?
  13. 《UnityAPI.Color颜色》(Yanlz+Unity+SteamVR+云技术+5G+AI+VR云游戏+Color+Lerp+RGBToHSV+gamma+linear+立钻哥哥++OK++)
  14. 微信点餐系统要服务器吗,微信点餐系统,钉钉点餐系统
  15. 3、核对单《数据收集工具与技术》
  16. [《南国雪下》闲笔记事集]2010年12月15日 记雪
  17. excel隔行显示不同颜色
  18. Unity游戏开发日记(一):独自开发2d横板游戏:Small man(MainMenu主界面)基本构建
  19. 攀爬机器人 蝎子_洛洛历险记中五种机器人的原型,一个是蝎子,有一个不是生物...
  20. 【调剂】陆军工程大学2020年硕士研究生调剂工作办法

热门文章

  1. Android 依赖注入: Dagger 2 实例解说(一)
  2. Windows UWP开发系列 – 3D变换
  3. makeMtk- user 版本编译
  4. SharePoint 2013的100个新功能之网站管理(二)
  5. Halcon_灰度直方图和特征直方图的使用
  6. python multi_python – 堆叠MultiIndex的所有级别
  7. es查询java代码如何排序_elasticsearch 查询聚合结果排序
  8. android 自定义图形,Android自定义View之图形图像(模仿360的刷新球自定
  9. python里什么叫子图_Python 如何构建多个子图表
  10. 加油站会员管理系统源码php_分享一下:关于一对一直播源码的重要组成部分