Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

让页面组件在RN环境能自定义navigationOptions #3835

Merged
merged 1 commit into from
Jul 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/taro-router-rn/src/getWrappedScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function getWrappedScreen (Screen, Taro, globalNavigationOptions = {}) {
const title = navigation.getParam('title') || navigationOptions.title || globalNavigationOptions.title
const rest = (navigationOptions.navigationStyle || globalNavigationOptions.navigationStyle) === 'custom' ? {header: null} : {}
const headerTintColor = navigation.getParam('headerTintColor') || navigationOptions.headerTintColor || globalNavigationOptions.headerTintColor
return {
const options = {
...rest,
headerTitle: <View style={{flexDirection: 'row', alignItems: 'center'}}>
{navigation.getParam('isNavigationBarLoadingShow') && <LoadingView />}
Expand All @@ -36,6 +36,15 @@ function getWrappedScreen (Screen, Taro, globalNavigationOptions = {}) {
backgroundColor: navigation.getParam('backgroundColor') || navigationOptions.backgroundColor || globalNavigationOptions.backgroundColor
}
}

// 如果页面组件也定义了navigationOptions,那么就合并页面那边的返回值
if (Screen.navigationOptions !== undefined) {
const target = Screen.navigationOptions({ navigation });
Object.assign(target, options);
return target;
}
return options;
}
}

/**
Expand Down