Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardware Back Button issue on a Hidden tabBar Screen #3498

Closed
Kida007 opened this issue Feb 11, 2018 · 6 comments
Closed

Hardware Back Button issue on a Hidden tabBar Screen #3498

Kida007 opened this issue Feb 11, 2018 · 6 comments

Comments

@Kida007
Copy link

Kida007 commented Feb 11, 2018

I just have a Simple TabNavigator, In which one of the Tabs navigate to a screen with Hidden TabBar . which i achieved using this :
Trip: { screen:Trip, navigationOptions:{ tabBarLabel:'Start', tabBarVisible: false } }

Now When i press hardware Back Button it crashes with :
TypeError: undefined is not an object (evaluating '_this3._component.setNativeProps')
and if it make it Visible, it works just fine i.e navigates to the first Tab Screen.

@Kida007 Kida007 changed the title Hardware Back Button on a Hidden tabBar Screen Hardware Back Button issue on a Hidden tabBar Screen Feb 11, 2018
@iloo123
Copy link

iloo123 commented Feb 12, 2018

Why do you have tabBarLabel:'Start' when you're hiding it ?

@iloo123
Copy link

iloo123 commented Feb 12, 2018

Try this

import { Platform, BackHandler } from 'react-native'

componentWillMount() {
        if (Platform.OS !== 'android') return
        BackHandler.addEventListener('hardwareBackPress', () => {
            const { dispatch } = this.props
            dispatch({ type: 'Navigation/BACK' })
            return true
        })
 }

    componentWillUnmount() {
        if (Platform.OS === 'android') BackHandler.removeEventListener('hardwareBackPress')
    }

@Kida007
Copy link
Author

Kida007 commented Feb 12, 2018

Thanks @iloo123 for reply .
I tried BackHandler on that Specific Tab Screen.
Apparently BackHandler doesn't work inside TabNavigator (for me atleast).

I want to achieve something like this :
Like This

Which I think better be achieved by Custom TabBar .

But I still Think Back Button on Hidden TabBar Screen is not Working ideally .

@iloo123
Copy link

iloo123 commented Feb 13, 2018

Try this with in the screen. I'm sure this will work

  static navigationOptions = ({navigation}) => ({
    tabBarVisible: false,
    headerLeft: (<View style={{paddingLeft: 25}}><TouchableOpacity onPress={() => navigation.goBack()}>
    <Image source={require('./icons/back.png')} style={{width: 20, height: 20, resizeMode: 'contain'}} />
    </TouchableOpacity></View>),
    headerTitle: <View>
                  <Text style={styles.titleStyle}>Account Settings</Text>
                </View>,
  })

@Kida007
Copy link
Author

Kida007 commented Feb 13, 2018

thanks for the reply!
but does that solve the problem of 'hardwareBackButton' ?

@Kida007
Copy link
Author

Kida007 commented Feb 14, 2018

So This is How I solved.

1) Changing Route Model.

Instead of using that particular screen in TabNavigator. I used it as a screen in the parent Stack Navigator which contains the TabNavigator.

so the route looks like

Parent Stack
|-- Login
|
|-- TabNavigator
|
|-- Screen I want to Navigate from middle Tab

2 ) Controlling TabBar middle Tab to operate differently .

This can be Done by using tabBarComponent in TabNavigatorConfig to control Navigation
as we have to stop navigation for the middle Tab and navigate to some other screen in
Stack Navigator. we can do this :

tabBarComponent: ({jumpToIndex, ...props, navigation})=>(
      <TabBarBottom
        {...props}
        jumpToIndex= {(index)=>{
          if(index==2) navigation.navigate('TripStack') ;
          else jumpToIndex(index)
        }}
        style={ Styles.tabBarStyle}
        labelStyle= {{ fontSize:10 }}
      />
    )
      />
    )

I Think this is the right way to do it.
But I'm not Sure of the Original Issue.

Anyways I found that here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants