Skip to content

Commit

Permalink
Some compatibility adjustments for react-navigation bindings (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmagiera committed Oct 23, 2019
1 parent 7c304a0 commit 7d4bbb8
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions createNativeStackNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,7 +97,7 @@ class StackView extends React.Component {
if (options.headerLeft !== undefined) {
children.push(
<ScreenStackHeaderLeftView key="left">
{options.headerLeft({ scene })}
{renderComponentOrThunk(options.headerLeft, { scene })}
</ScreenStackHeaderLeftView>
);
} else if (options.headerBackImage !== undefined) {
Expand Down Expand Up @@ -120,17 +127,21 @@ class StackView extends React.Component {
}

if (options.headerTitle) {
children.push(
<ScreenStackHeaderTitleView key="title">
{options.headerTitle({ scene })}
</ScreenStackHeaderTitleView>
);
if (title === undefined && typeof options.headerTitle === 'string') {
headerOptions.title = options.headerTitle;
} else {
children.push(
<ScreenStackHeaderTitleView key="title">
{renderComponentOrThunk(options.headerTitle, { scene })}
</ScreenStackHeaderTitleView>
);
}
}

if (options.headerRight) {
children.push(
<ScreenStackHeaderRightView key="right">
{options.headerRight({ scene })}
{renderComponentOrThunk(options.headerRight, { scene })}
</ScreenStackHeaderRightView>
);
}
Expand Down

0 comments on commit 7d4bbb8

Please sign in to comment.