react-native titleBar
来源:互联网 发布:java电脑版安装包多大 编辑:程序博客网 时间:2024/06/16 12:38
import React, {Component} from 'react';import { Image, StyleSheet, Text, View, Dimensions, TouchableOpacity} from 'react-native';import PropType from "prop-types";/** * Created by yunpeng on * Desc: */export default class TitleBar extends Component { constructor(props) { super(props) } //设置参数类型 static propTypes = { //左边按钮,不设置就不显示 leftIco: PropType.PropTypes.number, //右边按钮 rightIco: PropType.PropTypes.number, //右边标题 rightTitle: PropType.PropTypes.string, //中间标题 titleText: PropType.PropTypes.string, //左边点击事件 leftIcoPress: PropType.PropTypes.func, //右边点击事件 rightIcoPress: PropType.PropTypes.func, //传入navigation用于返回事件 navigation:PropType.PropTypes.object, }; static defaultProps = { titleText: "这是标题", }; render() { return ( <View style={style.contentStyle}> <View > {this._renderLeft()} </View> <Text //设置文本缩略格式 tail clip ellipsizeMode="tail" //文本行数限制 numberOfLines={1} style={style.centerTitleStyle} onPress={() => { }}>{this.props.titleText}</Text> <View > {this._returnRight()} </View> </View> ) } /** * 左边返回按钮 * @returns {XML} * @private */ _renderLeft(){ if(!this.props.leftIco){ } else if(this.props.navigation){ return( <ImageButton style={style.imageStyle} source={this.props.leftIco} onPress={()=>this.props.navigation.goBack()} /> ) }else if(this.props.leftIcoPress) { return( <ImageButton style={style.imageStyle} source={this.props.leftIco} onPress={this.props.leftIcoPress} /> ) } } /** * 返回右边按钮 * @returns {XML} * @private */ _returnRight() { if (this.props.rightIco) { return <Image style={style.imageStyle} source={this.props.rightIco} onPress={this.props.rightIcoPress}/>; } else if (this.props.rightTitle) { return <Text //设置文本缩略格式 tail clip ellipsizeMode="tail" //文本行数限制 numberOfLines={1} style={style.rightTitleStyle}>{this.props.rightTitle}</Text> } }}class ImageButton extends Component { render() { return ( <TouchableOpacity activeOpacity={0.9} onPress={this.props.onPress}> {this._renderImg()} </TouchableOpacity> ) } _renderImg(){ if(this.props.defaultSource){ return ( <Image style={this.props.style} source={this.props.defaultSource} > <Image style={this.props.style} source={this.props.source} > {this.props.children} </Image> </Image> ) }else { return ( <Image style={this.props.style} source={this.props.source} > {this.props.children} </Image> ) } }}const style = StyleSheet.create({ contentStyle: { backgroundColor: "#fff", flexDirection: "row", height: 40, alignItems: "center", paddingLeft: 10, paddingRight: 10, justifyContent: 'space-between', }, imageStyle: { width: 16, height: 16, }, centerTitleStyle: { position:"absolute", left:Dimensions.get("window").width/4, right:Dimensions.get("window").width/4, color: "#000", textAlign: "center", textAlignVertical: "center", }, rightTitleStyle: { alignSelf: "flex-end", color: "#000", textAlignVertical: "center" }});
阅读全文
0 0
- react-native titleBar
- react native
- React Native
- React Native
- React- Native
- react-native
- React Native
- React Native
- react native
- React Native
- react-native
- React Native
- react native
- React Native
- React Native
- React Native
- React Native
- react native
- Android 开发.gitgitgnore文件
- textField功能方法详解
- mac下eclipse安装svn插件
- MacAddressTool
- 持续部署的发展之路
- react-native titleBar
- iframe与主框架跨域相互访问方法
- Java去除字符串中的空格
- ajax获取后台图片数据流如何处理?
- springMVC JSON的使用
- win10 系统下本地 IIS 管理器 MIME 类型添加
- 第十四节:单选框(radio)和复选框(checkbox)
- Jenkins进行git多分支的docker镜像构建
- Java集合之List遍历找到匹配元素删除方法总结