如何在react-navigation中将通用背景图像添加到stackNavigator中的所有屏幕?

时间:2018-11-05 22:03:04

标签: javascript reactjs react-native react-navigation react-navigation-stack

我有一个React-native应用程序,类似于react-navigation中描述的authentication flow。我想在 AppStack 的所有屏幕上添加通用背景图片。

我尝试过的事情

  • 我尝试将 AppStack 导航器包装在<ImageBackground/>内,并且屏幕卡总是以某种方式位于顶部。

我需要帮助!

代码段

const AppStack = createStackNavigator({ Home: HomeScreen, Other: OtherScreen });
const AuthStack = createStackNavigator({ SignIn: SignInScreen, SignUp: SignUpScreen });

class SignInScreen extends React.Component {
    render() {
        return (
            <View style={{ flex: 1, backgroundColor: 'transparent' }}>
                <View style={{ width: '50%', backgroundColor: 'white' }}>
                    <Text>Sign in</Text>
                </View>

            </View>
        )
    }
}

class SignUpScreen extends React.Component {
    render() {
        return (
            <View style={{ flex: 1, backgroundColor: 'transparent' }}>
                <View style={{ width: '50%', backgroundColor: 'white' }}>
                    <Text>Sign up</Text>
                </View>

            </View>
        )
    }
}

class Authentication extends React.Component {
    render() {
        return (
            <ImageBackground source={source} style={{ flex: 1 }} >
                <AuthStack />
            </ImageBackground>
        )
    }
}

export default createSwitchNavigator(
    {
        AuthLoading: AuthLoadingScreen,
        App: AppStack,
        Auth: Authentication,
    },
    {
        initialRouteName: 'Auth',
    }
);

1 个答案:

答案 0 :(得分:0)

您可以通过修改cardStyle来添加颜色,如下所示:

const AppStack = createStackNavigator(
  { Home: HomeScreen, Other: OtherScreen },
  { cardStyle: { backgroundColor: "green" } }
);

据我所知,无法通过样式设置背景图片。

尽管可以创建自己的CardComponent.

相关问题