react native Back 按钮封装
来源:互联网 发布:淘宝奢侈品拍卖真假 编辑:程序博客网 时间:2024/06/04 17:55
项目中返回按钮出现的频率非常高,所以我们封装一个Back按钮,基本要求如下:
传入图片资源作为按钮图片
可以设置点击区域style和图片style
点击回调函数
传入react-navigation 的navigation,点击直接goBack
/** * Created by on 2017/3/27. */import React, {Component, PropTypes} from 'react';import { StyleSheet, Image,} from 'react-native';import Touchable from './Touchable';export default class Back extends Component { static propTypes = { //图片资源 source: PropTypes.oneOfType([ PropTypes.shape({ uri: PropTypes.string, headers: PropTypes.objectOf(PropTypes.string), }), // Opaque type returned by require('./image.jpg') PropTypes.number, // Multiple sources PropTypes.arrayOf( PropTypes.shape({ uri: PropTypes.string, width: PropTypes.number, height: PropTypes.number, })) ]), imageStyle: Image.style, onPress: PropTypes.func, } _onPress = () => { const {navigation} = this.props; if (navigation) { navigation.goBack(); } const {onPress} = this.props; if (onPress) { onPress(); } } render() { var props = Object.assign({}, this.props); props.imageStyle = [styles.image, props.imageStyle]; return ( <Touchable style={props.style} onPress={this._onPress}> <Image style={props.imageStyle} source={this.props.source}/> </Touchable> ); }}const styles = StyleSheet.create({ image: { }, })
Touchable 是我封装的另一个控件,地址:http://blog.csdn.net/mengks1987/article/details/70242842
demo
<Back style={{width:56,height:44}} imageStyle={{width:20,height:16}} source={require('../back.png')} navigation={this.props.navigation}/>
阅读全文
0 0
- react native Back 按钮封装
- react native button 按钮
- react -native 自定义按钮
- react native封装UI
- react native Toast封装
- react-native http封装
- react-native modal封装
- React Native 控件封装
- React Native TableViewCell封装
- React Native物理back键详解
- 【React Native】实现Navigator Back回退
- React-Native 安卓back键处理
- react-native 自定义倒计时按钮
- react native 多选按钮
- React Native的按钮详解
- React Native按钮的实现
- react-native 组件封装示例
- react-native--万能Button封装
- Ubuntu开机登录密码出现invalid password
- 测试通用测试用例
- Swing组件项目开发知识笔记
- codevs 1033 蚯蚓的游戏问题 费用流+拆点
- Kotlin基础教程-嵌套类
- react native Back 按钮封装
- 如果前后端分离的项目,前段的工程如testFront中的html页面,可以直接访问吗?
- java中检验字符串中包含某个字符或字段的方法
- ICRA的5篇最佳操作机械手论文逐个看 | ICRA 2017
- 算法题目-猜数字游戏
- Magenta
- android pm命令用法
- jstl 条件标签
- Hbase服务启动以及shell命令使用遇到的问题