react native Back 按钮封装
2017-06-06 10:52
211 查看
项目中返回按钮出现的频率非常高,所以我们封装一个Back按钮,基本要求如下:
传入图片资源作为按钮图片
可以设置点击区域style和图片style
点击回调函数
传入react-navigation 的navigation,点击直接goBack
Touchable 是我封装的另一个控件,地址:http://blog.csdn.net/mengks1987/article/details/70242842
demo
传入图片资源作为按钮图片
可以设置点击区域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}/>
相关文章推荐
- React Native布局实践:开发京东客户端首页(四)——首页功能按钮及控件封装
- ReactNative学习笔记--下拉选择菜单的简单封装
- 《React-Native系列》13、 组件封装之Dialog(iOS和Android通用)
- react-native-vector-icons的简单使用,图片,按钮,标签视图,导航条
- 【react-native-0.31-iOS】封装原生组件并调用(02)
- React-native学习笔记之<BackAndroid>
- ReactNative:点击按钮添加view
- ReactNative之从HelloWorld中看环境搭建、组件封装、Props及State
- react native学习笔记25——Android原生模块的封装与调用
- react-native-vector-icons的简单使用,图片,按钮,标签视图,导航条
- react native RadioButton(单选按钮)
- React Native Touchable(按钮) onPress 事件系列总结
- React-Native 自封装原生模块
- React Native 自定义圆角button的封装
- React-Native封装一些模块
- React-Native 之 GD (九)POST 网络请求封装
- react-native 在android封装原生listView
- 点击Android按钮跳转到React-native指定界面
- react-native组件封装与传值
- react native button 按钮