Last active
September 12, 2018 08:18
-
-
Save Visionchen/3f95cc8ce05f57b84076df140e1d9c76 to your computer and use it in GitHub Desktop.
标题栏简易封装
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### 使用teaset组件NavigationBar | |
| ```javascript | |
| import React from 'react'; | |
| import { withNavigation } from 'react-navigation'; | |
| import {NavigationBar,Toast} from "teaset" | |
| import observablemessagetime from '../../Mobx/messageTime' | |
| import ShopsCartStore from "../../Mobx/ShoppingCartStore" | |
| import observableOrder from '../../Mobx/ConfirmOrderStore' | |
| import {inject, observer} from "mobx-react"; | |
| @inject('rootStore') | |
| @observer | |
| class MyBackButton extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| backUrl:this.props.backUrl?this.props.backUrl:null, | |
| } | |
| } | |
| handleClick=(url)=>{ | |
| this.props.rootStore.infostore.updateInfo() | |
| this.props.navigation.goBack(null) | |
| if (this.props.endTime){ | |
| observablemessagetime.end(); | |
| } | |
| if (this.props.params){ | |
| console.log(this.props.params) | |
| ShopsCartStore.Updata_address(this.props.params.cart_id) | |
| observableOrder.reSetpayTypeList(); | |
| } | |
| } | |
| to_href=(url)=>{ | |
| if(url){ | |
| RouteUtils.to(url) | |
| }else { | |
| if (this.props.right_callback) { | |
| this.props.right_callback() | |
| } | |
| } | |
| } | |
| componentDidMount() { | |
| // this.props.rightView?<NavigationBar.IconButton icon={require('../icons/edit.png')} />:null | |
| } | |
| componentWillUnmount(){ | |
| } | |
| render() { | |
| const url=this.props.backTo?this.props.backTo:null | |
| const title=this.props.title||'标题' | |
| return <NavigationBar title={title} | |
| style={{backgroundColor: this.props.background?this.props.background:'#2CAEF0',zIndex:100000}} | |
| leftView={this.props.no_back ? null : <NavigationBar.BackButton title='返回' | |
| onPress={() => { this.handleClick(url) }}/>} | |
| rightView={this.props.right_view ?(this.props.right_icon ?<NavigationBar.IconButton icon={this.props.right_icon} onPress={() => {this.to_href(this.props.right_url||'')}}/>:<NavigationBar.LinkButton title={this.props.right_title || null} onPress={() => {this.to_href(this.props.right_url||'')}}/>):null }/> | |
| } | |
| } | |
| export default withNavigation(MyBackButton); | |
| ``` | |
| #### 组件使用 | |
| ```javascript | |
| <MyBackButton title={'标题'} right_view={true} right_title="重置" right_callback={( ) => this.call_back(0)}/> | |
| no_back={true} //不需要左边返回 | |
| right_icon={my.icon_news} //右侧为图标 | |
| right_url="MessageScreen" //点击右侧跳转url | |
| ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment