当前位置: 首页 > news >正文

react native 手搓数字键盘

react native 手搓数字键盘

本文展示了一个React Native实现的数字键盘组件ModalKeyboard。该组件包含以下特点: 使用Modal容器实现从底部滑出的动画效果 键盘布局为3x4的网格结构,包含数字0-9、"重置"和"-"按钮 支持点击数字提交功能,通过onSubmit回调传递按键值 自定义样式包括圆角按钮、背景色和字体大小 "-"按钮使用图片替代文字显示 通过点击模态框外部区域关闭键盘 组件采用响应式设计,使用zero工具函数动态计算布局尺寸,适用于不同屏幕

	import React, { Component } from 'react';import { Modal, View, Text, TouchableOpacity, StyleSheet, Image } from 'react-native';class ModalKeyboard extends Component {constructor(props) {super(props);this.state = {visible: false,};}handlePress = (key) => {this.props.onSubmit(key);};closeKeyboard = () => {this.setState({ visible: false });}render() {const { visible } = this.state;const keys = [['1', '2', '3'],['4', '5', '6'],['7', '8', '9'],['重置', '0', '-'],];return (<ModalanimationType="slide"transparent={true}visible={visible}onRequestClose={() => {this.setState({ visible: false });}}><TouchableOpacity style={styles.centeredView} onPress={this.closeKeyboard}><TouchableOpacity style={styles.modalView} activeOpacity={1} > {keys.map((row, rowIndex) => (<View key={rowIndex} style={styles.row}>{row.map((key) => (key === '-' ?<TouchableOpacitykey={key}style={[styles.button,{backgroundColor:"#007FFF"}]}onPress={() => this.handlePress(key)}><Image resizeMode='center' source={require('./../res/jian.png')} style={styles.jian}></Image></TouchableOpacity>:<TouchableOpacitykey={key}style={styles.button}onPress={() => this.handlePress(key)}><Text style={[styles.buttonText, key == '重置'? { fontSize: zero.yFont(24) } : {}]}>{key}</Text></TouchableOpacity>))}</View>))}</TouchableOpacity></TouchableOpacity></Modal>);}}const styles = StyleSheet.create({centeredView: {flex: 1,justifyContent: "flex-end",alignItems: 'center',},modalView: {backgroundColor: '#333333',width: '100%',height: zero.yHeight(360),alignItems: 'center',elevation: 5,},row: {flexDirection: 'row',},cardContainer: {marginTop: zero.yHeight(10),marginRight: zero.yWidth(10),// marginHorizontal: zero.yWidth(10),width: zero.yWidth(120),height: zero.yHeight(70),borderRadius: zero.yWidth(10),},button: {marginTop: zero.yHeight(10),marginRight: zero.yWidth(10),width: zero.yWidth(120),height: zero.yHeight(70),alignItems: 'center',justifyContent: 'center',borderRadius: zero.yWidth(10),backgroundColor: '#666',},buttonText: {color: "#fff",fontSize: zero.yFont(40),},jian: {width: zero.yWidth(36),}});
export default ModalKeyboard;
http://www.dtcms.com/a/585131.html

相关文章:

  • 算法复杂度解析:时间与空间的衡量
  • 开源鸿蒙SIG-Qt技术沙龙成都站成功举办,产品方案展示
  • 2025年渗透测试面试题总结-235(题目+回答)
  • C语言进阶:深入理解函数
  • 计算机图形学·11 变换(Transformations)
  • Rust编程学习 - 如何利用代数类型系统做错误处理的另外一大好处是可组合性(composability)
  • LocalAI:一个免费开源的AI替代方案,让创意更自由!
  • 深入理解Ext2:Linux文件系统的基石与它的设计哲学
  • 泉州网站的建设html网页制作我的家乡
  • PHP 魔术常量
  • 【iOS】音频与视频播放
  • php通过身份证号码计算年龄
  • 基于PHP+Vue+小程序快递比价寄件系统
  • Next.js、NestJS、Nuxt.js 是 **Node.js 生态中针对不同场景的框架**
  • 牛客周赛 Round 114 Java题解
  • PostgreSQL 中数据库、用户、对象关系、表、连接及管理概述
  • 樟树市城乡规划建设局网站爱站攻略
  • Gitblit 迁移指南
  • Git分支管理核心:git fetch与git checkout创建分支完全指南
  • LRU 缓存的设计与实现
  • Linux -- 线程互斥
  • 2.2 Transformer 架构详解:从理论到实践
  • 《Docker+New Relic+Jenkins:开发全链路的工具赋能指南》
  • 2025最新修复的豪门足球风云-修复验证问题-修复注册问题实现地注册-架设教程【豪门足球本地验证】
  • 【Linux笔记】网络部分——数据链路层mac-arp
  • 深圳网站设计公司专业吗外国网站分享代码
  • VB.Net 常用函数
  • 成都哪家做网站wordpress 主题课堂
  • 智慧随访管理系统源码,基于Java+Spring Boot+Vue的随访系统源码,支持二次开发,支持患者信息管理、多类型随访、三级回访机制、问卷模板
  • MQL5 自学路线图:从入门到实战