react-navigation
安卓端React Navigation的TabNavigator选项卡与react-native-scrollable-tab-view、FlatList一起使用,只显示第一页的内容。
解决方案: 给TabNavigator增加lazy: true 属性,官方解释,whether to lazily render tabs as needed as opposed to rendering them upfront
FlatList 初始化时不显示列表,需要拖拽一下才显示当 React Navigation 与 FlatList 配合使用时,会出现初始化时不显示列表的bug,必须要拖拽一下,才会正常显示
解决方案: 此时需要给FlatList设置removeClippedSubviews={false} 属性,即可解决问题(目前最新版0.46貌似已经解决了此bug),官方文档解释如下:
注意:removeClippedSubviews属性目前是不必要的,而且可能会引起问题。如果你在某些场景碰到内容不渲染的情况(比如使用LayoutAnimation时),尝试设置removeClippedSubviews={false}。我们可能会在将来的版本中修改此属性的默认值。
快速点击重复跳转
react-navigation目录下src/addNavigationHelpers.js
export default function<S: *>(navigation: NavigationProp<S, NavigationAction>) {
// 添加点击判断
let debounce = true;
return {
...navigation,
goBack: (key?: ?string): boolean =>
navigation.dispatch(
NavigationActions.back({
key: key === undefined ? navigation.state.key : key,
}),
),
navigate: (routeName: string,
params?: NavigationParams,
action?: NavigationAction,): boolean => {
if (debounce) {
debounce = false;
navigation.dispatch(
NavigationActions.navigate({
routeName,
params,
action,
}),
);
setTimeout(
() => {
debounce = true;
},
500,
);
return true;
}
return false;
},
/**
* For updating current route params. For example the nav bar title and
* buttons are based on the route params.
* This means `setParams` can be used to update nav bar for example.
*/
setParams: (params: NavigationParams): boolean =>
navigation.dispatch(
NavigationActions.setParams({
params,
key: navigation.state.key,
}),
),
};
}
单页面设置navigationOptions中, 使用this
static navigationOptions = ({navigation, screenProps}) => ({
headerTitle: '登录',
headerLeft:(
<Text onPress={()=>navigation.state.params.navigatePress()} style={{marginLeft:5, width:30, textAlign:"center"}} >
<Icon name='ios-arrow-back'size={24} color='white' />
</Text>
)
});
_onBackAndroid=()=>{
alert('点击headerLeft');
}
componentDidMount(){
//在static中使用this方法
this.props.navigation.setParams({ navigatePress:this._onBackAndroid })
}
大多数页面都是push(从右往左),某些页面想从下往上
const TransitionConfiguration = () => ({
screenInterpolator: (sceneProps) => {
const { scene } = sceneProps;
const { route } = scene;
const params = route.params || {};
const transition = params.transition || 'forHorizontal';
return CardStackStyleInterpolator[transition](sceneProps);
},
});
const Navigator = StackNavigator (
{
// Root:{screen: FilterNews},
Root: {screen: Tab},
CompanyDetail: {screen: CompanyDetail},
LawOption: {screen: LawOption},
},
{
transitionConfig: TransitionConfiguration,
initialRouteName: 'Root',
navigationOptions: { //不要在此处设置 否则后面全部被覆盖
headerStyle: [Style.shadow, {backgroundColor: 'white',borderBottomColor:'white'}],
headerBackTitle: null,
headerTintColor: '#192847',// 返回箭头颜色
showIcon: true,
swipeEnabled: true,//是否可以滑动返回
animationEnabled: true,//是否带动画
gesturesEnabled: true,// 是否支持手势返回
headerTitleStyle: {fontSize: 18, color: Color.textBlack, alignSelf:'center'},//定义title的样式
cardStyle: {
backgroundColor: 'transparent',
},
},
// transitionConfig: (): Object => ({
// containerStyle: {
// backgroundColor: 'transparent',
// },
// }),
}
)
// 使用的时候 ,参数加一个 transition: 'forVertical'
this.props.navigation.navigate('Login', {transition: 'forVertical', someValue: 0})
从下往上背景色是黑色
react-navigation/src/views/CardStack/TransitionConfigs.js
里 ModalSlideFromBottomIOS -> backgroundColor 改为 ‘#fff’
android 有键盘的时候会把 tabBar 顶起来(tabBar悬浮在键盘上方)
工程目录->android->app->src->main->AndroidManifest.xml-> <activity android:name=".MainActivity"
android:windowSoftInputMode="adjustResize"
替换为
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
返回指定页面
tabA 跳转到 tabB (tabNavigator, tabA页面内点击某个按钮跳转到tabB)
android 标题不居中
方案一:
const Stack = StackNavigator(
{
Tab: {
screen: Tab,
navigationOptions: ({navigator}) => ({
// drawerLockMode: 'locked-closed',
})
},
First: {screen: First},
},
{
navigationOptions: {
headerBackTitle: null,
headerTitleStyle: {fontSize: Common.headrTitleSize, alignSelf: 'center', textAlign: 'center'},//定义title的样式
headerRight: (
<View />
)
},
}
)
总处设置, 基本 OK
具体页面内设置的navigationOptions 会覆盖上面总处 navigationOptions 的选项
具体页面内 navigationOptions 如果重新设置了 headerTitleStyle, 就需要在具体处headerTitleStyle 添加 alignSelf: 'center'
另外方案一在没有返回按钮的页面中标题可能会偏左,解决方案就是类似,在页面设置 headerLeft 为一个空View
headerLeft: (
<View />
)
方案二:
MyProject/node_modules/react-navigation/src/views/Header/Header.js
Line 392
alignItems: Platform.OS === 'ios' ? 'center' : 'flex-start',
替换为
alignItems: 'center',
Line 196
_renderTitle 方法中注销掉安卓部分的判断,或者把下面整段都注销
if (Platform.OS === 'android') {
// if (!options.hasLeftComponent) {
// style.left = 0;
// }
// if (!options.hasRightComponent) {
// style.right = 0;
// }
}
相对来说方案二更省事,高效,污染少,但是每次 npm install 后都需要重新来一遍
react-navigation的更多相关文章
- react-native 学习 ----- React Navigation
很久没有的登陆博客园了,密码都是找回的,从当年的大学生已经正常的走上了程序员的道路,看到之前发的博客还是写的android,现在自己已经在使用了react-native了. 大学毕业了,做了java后 ...
- react-native导航器 react navigation 介绍
开发环境搭建好之后,想要进一步了解react-native,可以先从react-native官网上的电影列表案例入手: https://reactnative.cn/docs/0.51/sample- ...
- React Navigation & React Native & React Native Navigation
React Navigation & React Native & React Native Navigation React Navigation https://facebook. ...
- [RN] 04 - React Navigation
react-navigation和react-router的对比: 支持的平台: react-navigation: react-native react-router: react-native.r ...
- React Native常用组件之TabBarIOS、TabBarIOS.Item组件、Navigator组件、NavigatorIOS组件、React Navigation第三方
以下内容为老版本React Native,faceBook已经有了新的导航组件,请移步其他博客参考>>[我是传送门] 参考资料:React Navigation react-native ...
- React-native 导航插件React Navigation 4.x的使用
React-native 导航插件React Navigation 4.x的使用 文档 英文水平可以的话,建议直接阅读英文文档 简单使用介绍 安装插件 yarn add react-navigatio ...
- [RN] React Navigation 使用中遇到的显示 问题 汇总
React Navigation 使用中遇到的显示 问题 汇总 https://www.jianshu.com/p/8b1f18affc5d
- react navigation goBack()返回到任意页面(不集成redux) 一
方案一: 一.适用场景:在app端开发的时候,相反回到某一个页面的时候保持跳转页面的所有状态不更新,也就是说不触发新的生命周期. 例如:A——>B——>C——>D 要想从D页面直接返 ...
- React Navigation / React Native Navigation 多种类型的导航结合使用,构造合理回退栈
React Navigation 更新到版本5已经是非常完善的一套导航管理组件, 提供了Stack , Tab , Drawer 导航方式 , 那么我们应该怎样设计和组合应用他们来构建一个完美的回退栈 ...
- React Navigation基本用法
/** * Created by apple on 2018/9/23. */ import React, { Component } from 'react'; import {AppRegistr ...
随机推荐
- py+selenium 报错NameError: name 'NoSuchElementException' is not defined【已解决】
报错:NameError: name 'NoSuchElementException' is not defined 如图 解决方法: 头部加一句:from selenium.common.exc ...
- 洛谷P2790 ccj与zrz之积木问题 题解
题目链接:https://www.luogu.org/problemnew/show/P2790 这题码量稍有点大... 分析: 这道题模拟即可.因为考虑到所有的操作vector可最快捷的实现,所以数 ...
- C# 针对特定的条件进行锁操作,不用lock,而是mutex
背景:用户领取优惠券,同一个用户需要加锁验证是否已经领取,不同用户则可以同时领取. 上代码示例: 1.创建Person类 /// <summary> /// Person类 /// < ...
- 巧力避免ViewPager的预加载数据,Tablayout+Fragment+viewPager
问题描述 最近在进行一个项目的开发,其中使用到了Tablayout+Fragment+viewPager来搭建一个基本的框架,从而出现了设置数据适配器的时候,item的位置错乱问题.我打印log日志的 ...
- 前端jQuery学习(一)
把最近学习的前端框架jQuery整理一下.你可能听说过jQuery,因为他是JavaScript世界中使用最广泛的一个库. 江湖传言,全世界大约有80~90%的网站直接或间接地使用了jQuery.鉴于 ...
- JS实现在线ps功能
功能介绍 本系统是基于fabric.js实现的canvas版图片,文本编辑器,支持对图片的放大,缩小,旋转,镜面翻转,拖动,显示/隐藏图层,删除图层,替换图层等操作,对文本支持修改文本内容,颜色,字体 ...
- python redis连接 有序集合去重
# -*- coding: utf-8 -*- import redisfrom constant import redis_ip, redis_db, redis_pw, logger, redis ...
- [ PyQt入门教程 ] PyQt5基本控件使用:单选按钮、复选框、下拉框
本文主要介绍PyQt5界面最基本使用的单选按钮.复选框.下拉框三种控件的使用方法进行介绍. 1.RadioButton单选按钮/CheckBox复选框.需要知道如何判断单选按钮是否被选中. 2.Com ...
- idea 新建不了servlet文件 方法(1)
在pem.xml中添加较新版本的servletapi包 <dependency> <groupId>javax.servlet</groupId> <arti ...
- 记一次织梦cms渗透测试
记一次织梦cms渗透测试 0x01 前言 本次测试的整个流程:枚举用户名-针对性暴破-登录后台-后台编辑php文件getshell. 0x02 过程 1.登录功能模块存在用户名枚举缺陷,利用此权限先枚 ...