react-native-navigation-cus
react-native的导航组件,基于react-navigation@1.5.11,修改而成;<BR>
更好的页面导航封装,并且增加进入页面的方法回调(componentWillEnter)和退出页面的方法回调(componentWillExit)
完美的页面导航跳转返回;
每一个Tab页面组都有自己的返回逻辑,互不影响;
杜绝了传统的记住历史页面进行的返回;
避免从一个Tab页面组跳入到另一个Tab页面组,返回时返回到跳入之前的Tab页面组;
由于react-navigation在TabNavigator和DrawerNavigator下,页面打开过,就不更新了,也没有回调方法刷新页面,也无法准确返回页面,故再次修改封装此组件
安装组件:
npm i --save react-native-navigation-cus
使用 (此导航组件可查看react-navigation,或百度搜索react-navigation的使用与配置)
组件BaseComponent 方法参数请查看源文件里面有详细的注释,继承导航属性;这个组件中的方法都是"静态和动态"两种调用方式
this.goPage();
BaseComponent.goPage();
this.goBack();
BaseComponent.goBack();
this.setParams();
BaseComponent.setParams();
this.getPageParams();
BaseComponent.getPageParams();
this.setParams({
headerLeft:true,
headerRight:true,
headerLeftHandle:function(){},
headerRightHandle:function() {}
});
componentWillEnter(params,action,routeName);
componentWillExit();
示例
import React, {Component} from 'react';
import StyleSheetAdapt from "react-native-stylesheet-adapt";
import {
BaseComponent,
StackNavigator,
TabNavigator,
CardStackStyleInterpolator
} from "react-native-navigation-cus";
import {
Text,
View,
Text,
TouchableOpacity,
} from 'react-native';
type Props = {};
export default class PageLogin extends BaseComponent<Props> {
constructor(props) {
super(props);
let param = Tools.userConfig.userCutAccount
&& Tools.userConfig.userCutAccount.length > 0
? {
headerLeft:<ImageChange icon={require("images/role.png")}
onPressIn={()=>PageSearchRole.show(this)}
style={styles.hLeft}/>
}
: {
headerLeft:false
};
this.setParams(param);
}
componentWillEnter(params,action,routeName){
}
componentWillExit(){
}
render() {
return (
<View>
<BarcodeView ref={c=>this.barcodeView = c}
style={styles.testStyle}/>
<Text onPress={()=>this.barcodeView.startScan()}>
开始扫码
</Text>
<TouchableOpacity onPress={()=>this.goPage('PageMain')}>
<Text>
下一页
</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheetAdapt.create({
testStyle2:{
width:100,
height:200,
},
testStyle:{
transform:[
{rotateX:'180deg'}
],
},
});
const StackPages = {
PageLogin: {
screen: PageLogin,
navigationOptions:({navigation}) =>({
header:null,
})
},
PageMain: { screen: PageMain },
};
const App = StackNavigator(StackPages,{
navigationOptions:{
gesturesEnabled:false,
headerStyle:{
backgroundColor: '#FF6B01',
height:StyleSheetAdapt.getHeight(60),
},
headerTitleStyle:{
flex: 1,
textAlign: 'center',
fontSize:StyleSheetAdapt.getWidth(25),
},
headerBackTitleStyle:{
},
headerTintColor:'#FFFFFF',
headerBackTitle:null,
},
mode:'none',
transitionConfig:()=>({
screenInterpolator:CardStackStyleInterpolator.forHorizontal,
}),
});
module.exports = App;