React-native-router-flux: native router flux custom back button

Created on 22 Feb 2017  路  7Comments  路  Source: aksonov/react-native-router-flux

Version

Tell us which versions you are using:

  • react-native-router-flux v3.?.?
  • react-native v0.?.?

Expected behaviour

Actual behaviour

Steps to reproduce

1.
2.
3.

Most helpful comment

This has been asked here so many times:
My personal choice is to use custom Back and right button components.

Simply go ahead and copy them from the react-native-router-flux src folder, and pass your new component as a prop when for example you create your scenes like so:

<Scene
   key="MyScene1"
   component={MySceneComponent}
   title="MyScene1"
   renderBackButton={() => 
            <LeftButton 
               leftButtonIcon={"arrow-back"} 
               onLeft={() => Actions.pop()} 
               leftButtonColor={"white"} 
               leftButtonIconSize={30} 
             />
   }
/>

You can do the above inside your Scene component/container component too like so, for example on component mount:

import {Actions} from 'react-native-router-flux'
import LeftButton from './leftbutton'

componentDidMount(){
Actions.refresh({renderBackButton: () => 
    <LeftButton 
     leftButtonIcon={"arrow-back"} 
     onLeft={() => Actions.pop()} leftButtonColor={"white"} 
     leftButtonIconSize={30} 
    />
})
}

And I simply use component inside my LeftButton component, that comes with 'react-native-vector-icons'

Hope this helps 馃憤

All 7 comments

This has been asked here so many times:
My personal choice is to use custom Back and right button components.

Simply go ahead and copy them from the react-native-router-flux src folder, and pass your new component as a prop when for example you create your scenes like so:

<Scene
   key="MyScene1"
   component={MySceneComponent}
   title="MyScene1"
   renderBackButton={() => 
            <LeftButton 
               leftButtonIcon={"arrow-back"} 
               onLeft={() => Actions.pop()} 
               leftButtonColor={"white"} 
               leftButtonIconSize={30} 
             />
   }
/>

You can do the above inside your Scene component/container component too like so, for example on component mount:

import {Actions} from 'react-native-router-flux'
import LeftButton from './leftbutton'

componentDidMount(){
Actions.refresh({renderBackButton: () => 
    <LeftButton 
     leftButtonIcon={"arrow-back"} 
     onLeft={() => Actions.pop()} leftButtonColor={"white"} 
     leftButtonIconSize={30} 
    />
})
}

And I simply use component inside my LeftButton component, that comes with 'react-native-vector-icons'

Hope this helps 馃憤

Thank you.

I want to automatically get the title of the previous scene on the current scene and display the return title in the upper left corner of the current scene.

@lucasleelz Easy, just pass the title of the current scene to the next scene.
For example in your current scene of which you want to show the title of on the nextScene:
Actions.nextScene({title: this.props.title})

And in your nextScene (or whatever name you have), just use:

componentDidMount(){
Actions.refresh({backTitle: ()=> this.props.title})
}

Should do the job, obviously you can play around and have the title in the redux store if you use it, and or fire Actions.refresh in a different place for example when you get a response from the api or something.

Hope this helps, hit that thumbs up button 馃憤

Thanks @Amurmurmur for your solusion. I am not able to find './leftbutton'. It is not in source folder of v3. Can you provide a link? thanks

Did some modification based on @Amurmurmur 's answer because I don't have leftButton.js

Router.js
...

    <Scene
      key="customRepetition"
      component={CustomRepeatPicker}
      title="Custom"
      leftTitle="Back"
      onLeft={() => {
        console.log('is this one called?');
        Actions.pop();
      }}
    />

CustomRepeatPicker.js

class CustomRepeatPicker extends React.Component {
  componentDidMount() {
    Actions.refresh({
      onLeft: () => {
        console.log('it is overriden!');
      }
    });
  }

This has been asked here so many times:
My personal choice is to use custom Back and right button components.

Simply go ahead and copy them from the react-native-router-flux src folder, and pass your new component as a prop when for example you create your scenes like so:

<Scene
   key="MyScene1"
   component={MySceneComponent}
   title="MyScene1"
   renderBackButton={() => 
            <LeftButton 
               leftButtonIcon={"arrow-back"} 
               onLeft={() => Actions.pop()} 
               leftButtonColor={"white"} 
               leftButtonIconSize={30} 
             />
   }
/>

You can do the above inside your Scene component/container component too like so, for example on component mount:

import {Actions} from 'react-native-router-flux'
import LeftButton from './leftbutton'

componentDidMount(){
Actions.refresh({renderBackButton: () => 
    <LeftButton 
     leftButtonIcon={"arrow-back"} 
     onLeft={() => Actions.pop()} leftButtonColor={"white"} 
     leftButtonIconSize={30} 
    />
})
}

And I simply use component inside my LeftButton component, that comes with 'react-native-vector-icons'

Hope this helps 馃憤

You Might want to wrap it in a setTimeout

Was this page helpful?
0 / 5 - 0 ratings

Related issues

basdvries picture basdvries  路  3Comments

maphongba008 picture maphongba008  路  3Comments

sylvainbaronnet picture sylvainbaronnet  路  3Comments

fgrs picture fgrs  路  3Comments

GCour picture GCour  路  3Comments