我有一个React-native应用程序,类似于react-navigation中描述的authentication flow。我想在 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',
}
);
答案 0 :(得分:0)
您可以通过修改cardStyle
来添加颜色,如下所示:
const AppStack = createStackNavigator(
{ Home: HomeScreen, Other: OtherScreen },
{ cardStyle: { backgroundColor: "green" } }
);
据我所知,无法通过样式设置背景图片。
尽管可以创建自己的CardComponent
.