diff --git a/createNativeStackNavigator.js b/createNativeStackNavigator.js index e65aef63..f00bafd0 100644 --- a/createNativeStackNavigator.js +++ b/createNativeStackNavigator.js @@ -18,6 +18,13 @@ import { ScreenStackHeaderTitleView, } from 'react-native-screens'; +function renderComponentOrThunk(componentOrThunk, props) { + if (typeof componentOrThunk === 'function') { + return componentOrThunk(pops); + } + return componentOrThunk; +} + class StackView extends React.Component { _removeScene = route => { const { navigation } = this.props; @@ -90,7 +97,7 @@ class StackView extends React.Component { if (options.headerLeft !== undefined) { children.push( - {options.headerLeft({ scene })} + {renderComponentOrThunk(options.headerLeft, { scene })} ); } else if (options.headerBackImage !== undefined) { @@ -120,17 +127,21 @@ class StackView extends React.Component { } if (options.headerTitle) { - children.push( - - {options.headerTitle({ scene })} - - ); + if (title === undefined && typeof options.headerTitle === 'string') { + headerOptions.title = options.headerTitle; + } else { + children.push( + + {renderComponentOrThunk(options.headerTitle, { scene })} + + ); + } } if (options.headerRight) { children.push( - {options.headerRight({ scene })} + {renderComponentOrThunk(options.headerRight, { scene })} ); }