score:1

You can just add

onTransitionStart: () => Keyboard.dismiss(),

at your stacknavigator definition and don't need to modify each backbutton.

For example:

const mainScreen = createStackNavigator(
  {
    MainScreen: {
      screen: MainScreen,
    }
  },
  {
    onTransitionStart: () => Keyboard.dismiss(),
    initialRouteName: 'MainScreen'
  }
);

score:2

While defining the StackNavigator try to pass in this option:

const StackNavigatorConfig = {
  navigationOptions: {
    header: ({ goBack }) => {
      const goBackAndDismissKeyboard = (ev) => {
          Keyboard.dismiss()
          return goBack(ev)
      } 
      return { left: <Left onPress={goBackAndDismissKeyboard} />}
    },
  }
}

StackNavigator(RouteConfigs, StackNavigatorConfig)

Related Query

More Query from same tag