react-nativereact-native-router-flux

How to prevent hamburger menu replace over back button?


I've been using:

react-native-router-flux v4.0.6

react v16.6.3

react-native v0.57.8

I have a simple question. I have two component: Listing.js and Detail.js

And I have a drawer menu. The problem is that when user click the detail button in the Listing, next page the hamburger menu icon still exist.

But I want to change the hamburger menu to back button.

<Router sceneStyle={{ marginTop: 15 }}>
    <Scene 
        contentComponent={SideMenu} 
        drawerWidth={280} 
        drawerPosition={'left'} 
        drawerImage={require('./hamburger.png')} 
        initial 
        drawer
    >
        <Scene key='main'>
            <Scene key='list' component={Listing} title='Albüm APP' initial />
            <Scene key='detail' component={Detail} title='Albüm Detay' />
        </Scene>
    </Scene>
</Router>

Here the problem:

enter image description here

enter image description here

Here I want to do:

enter image description here


Solution

  • it looks like you can override the default navbar with a custom navbar

    import React from 'react';
    import { Scene, Router } from 'react-native-router-flux';
    import mainScreen from './components/mainScreen';
    import challengeScreen from './components/challengeScreen';
    import NavBar from './components/NavBar';
    
    const RouterComponent = () => {
      return (
        <Router>
    <Scene key="root">
        <Scene key="homeScreen" component={mainScreen} hideNavBar={1} />
        <Scene
         key="screen2" component={challengeScreen} navTransparent={1}
         navBar={NavBar}
           />
    </Scene>
        </Router>
      );
    };
    export default RouterComponent;
    

    // NavBar.js

    import {
     View, Image, StatusBar, TouchableWithoutFeedback
    } from 'react-native';
    import React, { Component } from 'react';
    import { Actions, Router, Scene } from 'react-native-router-flux';
    
    class NavBar extends Component {
      render() {
        return (
    <View style={styles.backgroundStyle}>
          <StatusBar />
          <View style={{ flexDirection: 'row' }}>
          <TouchableWithoutFeedback onPress={() => Actions.homeScreen()}>
          <Image
        source={require('./Images/back-arrow.png')}
        style={styles.backarrowStyle} />
          </TouchableWithoutFeedback>
    
          <Image
      source={require('./Images/help.png')}
      style={styles.helpStyle} />
    
    
      <Image
    source={require('./Images/setting.png')}
    style={styles.settingStyle} />
        </View>
    </View>
        );
      }
    
    }
    const styles = {
      backgroundStyle: {
        backgroundColor: 'transparent'
      },
      backarrowStyle: {
        resizeMode: 'contain',
        flexDirection: 'row',
        width: 50,
        height: 50,
        left: 0,
        justifyContent: 'flex-start'
      },
      helpStyle: {
        resizeMode: 'contain',
          width: 50,
          height: 50,
          left: 220,
          justifyContent: 'flex-end',
          position: 'relative'
    
      },
      settingStyle: {
        resizeMode: 'contain',
        width: 50,
        height: 50,
        justifyContent: 'flex-end',
      position: 'relative',
      left: 210
      }
    };
    
    
    export default NavBar;