解决方案: 给TabNavigator增长lazy: true 属性,官方解释,whether to lazily render tabs as needed as opposed to rendering them upfrontnode
解决方案: 此时须要给FlatList设置removeClippedSubviews={false} 属性,便可解决问题(目前最新版0.46貌似已经解决了此bug),官方文档解释以下:react
注意:removeClippedSubviews属性目前是没必要要的,并且可能会引发问题。若是你在某些场景碰到内容不渲染的状况(好比使用LayoutAnimation时),尝试设置removeClippedSubviews={false}。咱们可能会在未来的版本中修改此属性的默认值。android
react-navigation目录下src/addNavigationHelpers.jsios
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, }), ), }; }
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 }) }
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’npm
工程目录->android->app->src->main->AndroidManifest.xml-> <activity android:name=".MainActivity"react-native
android:windowSoftInputMode="adjustResize" 替换为 android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
方案一:app
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 为一个空Viewide
headerLeft: ( <View /> )
方案二:
MyProject/node_modules/react-navigation/src/views/Header/Header.jsflex
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 后都须要从新来一遍