Some compatibility adjustments for react-navigation bindings (#196)

This commit is contained in:
Krzysztof Magiera
2019-10-23 16:04:50 +02:00
committed by GitHub
parent 7c304a007f
commit 7d4bbb8f88

View File

@@ -18,6 +18,13 @@ import {
ScreenStackHeaderTitleView, ScreenStackHeaderTitleView,
} from 'react-native-screens'; } from 'react-native-screens';
function renderComponentOrThunk(componentOrThunk, props) {
if (typeof componentOrThunk === 'function') {
return componentOrThunk(pops);
}
return componentOrThunk;
}
class StackView extends React.Component { class StackView extends React.Component {
_removeScene = route => { _removeScene = route => {
const { navigation } = this.props; const { navigation } = this.props;
@@ -90,7 +97,7 @@ class StackView extends React.Component {
if (options.headerLeft !== undefined) { if (options.headerLeft !== undefined) {
children.push( children.push(
<ScreenStackHeaderLeftView key="left"> <ScreenStackHeaderLeftView key="left">
{options.headerLeft({ scene })} {renderComponentOrThunk(options.headerLeft, { scene })}
</ScreenStackHeaderLeftView> </ScreenStackHeaderLeftView>
); );
} else if (options.headerBackImage !== undefined) { } else if (options.headerBackImage !== undefined) {
@@ -120,17 +127,21 @@ class StackView extends React.Component {
} }
if (options.headerTitle) { if (options.headerTitle) {
children.push( if (title === undefined && typeof options.headerTitle === 'string') {
<ScreenStackHeaderTitleView key="title"> headerOptions.title = options.headerTitle;
{options.headerTitle({ scene })} } else {
</ScreenStackHeaderTitleView> children.push(
); <ScreenStackHeaderTitleView key="title">
{renderComponentOrThunk(options.headerTitle, { scene })}
</ScreenStackHeaderTitleView>
);
}
} }
if (options.headerRight) { if (options.headerRight) {
children.push( children.push(
<ScreenStackHeaderRightView key="right"> <ScreenStackHeaderRightView key="right">
{options.headerRight({ scene })} {renderComponentOrThunk(options.headerRight, { scene })}
</ScreenStackHeaderRightView> </ScreenStackHeaderRightView>
); );
} }