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 ...
随机推荐
- 最全caffe安装踩坑记录(Anaconda,nvidia-docker,Linux编译)
Anaconda,nvidia-docker,Linux三种方式安装caffe 1.Anaconda安装caffe 1.首先安装anaconda 2.创建虚拟环境(python2.7) conda c ...
- TensorFlow笔记-图片读取
回到上一篇文件的读取分这么几步: # 构造队列 # 1,构造图片文件的队列 file_queue = tf.train.string_input_producer(filelist) # 构造阅读器 ...
- TensorFlow笔记-变量,图,会话
变量 存储一些临时值的作用或者长久存储.在Tensorflow中当训练模型时,用变量来存储和更新参数.变量包含张量(Tensor)存放于内存的缓存区.建模时它们需要被明确地初始化,模型训练后它们必须被 ...
- antd pro中如何使用mock数据以及调用接口
antd pro的底层基础框架使用的是dva,dva采用effect的方式来管理同步化异步 在dva中主要分为3层 services models components models层用于存放数据 ...
- halcon视频教程如何学习?怎么样才能踏入机器视觉这个行业?
本人是工作八年的视觉工程师,主要从事Halcon和Visionpro视觉开发,谈谈个人对视觉学习看法: 1.HALCON是德国MVtec公司开发的一套完善的标准的机器视觉算法包,它节约了产品成本,缩短 ...
- spring与actionMQ整合
出处:http://www.cnblogs.com/leiOOlei/p/5075402.html 一.配置部分 ActiveMQ的安装这就不说了,很简单, 这个例子采用maven构建,首先看一下po ...
- Shell基本语法---shell介绍
简介 1. shell是在linux系统上高效运行的脚本语言 2. 主要用来开发一些实用的.自动化的小工具,而不是用来开发具有复杂业务逻辑的中大型软件 3. shell的基本命令也是linux操作系统 ...
- 【Intellij】导出 jar 包
需要在 Intellij 导出 jar 包,一时不知道该怎么做,后来总算找到了方法,步骤如下: 1. File → Project Structure... → Artifacts → + → jar ...
- java volatile关键字作用及使用场景
1. volatile关键字的作用:保证了变量的可见性(visibility).被volatile关键字修饰的变量,如果值发生了变更,其他线程立马可见,避免出现脏读的现象.如以下代码片段,isShut ...
- dubbo异常处理
dubbo异常处理 我们的项目使用了dubbo进行不同系统之间的调用. 每个项目都有一个全局的异常处理,对于业务异常,我们会抛出自定义的业务异常(继承RuntimeException). 全局的异常处 ...