javascript - 如何在 react-navigation 中向 stackNavigator 中的所有屏幕添加公共背景图像?
问题描述
我有一个 react-native 应用程序,类似于react-navigation 中描述的身份验证流程。我想为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',
}
);
解决方案
您可以通过修改来添加颜色cardStyle
,如下所示:
const AppStack = createStackNavigator(
{ Home: HomeScreen, Other: OtherScreen },
{ cardStyle: { backgroundColor: "green" } }
);
据我所知,没有办法从样式中设置背景图像。
您可以创建自己的CardComponent
.
推荐阅读
- scala - Scala 数据框:使用 regexp_replace 将空格替换为空值
- sql-server - SQL Server 作业:FTP 找不到文件
- hive - 在 Hive 中等效交叉应用?
- excel - 如何将XML中的数组值插入Excel中行的每个顺序单元格,为每一行循环?
- python - Python没有这样的文件或目录错误尝试在Mac上打印文件列表目录
- c++ - 我试图制作一个要求用户输入问题和答案的程序,但程序没有正确循环
- firebase - 使用 Flutter Firestore Firebase 将值保存为字符串
- mysql - 您如何根据 MIN 日期对值求和?
- javascript - 尝试对 firebase 数据库进行排序不起作用
- angular - Angular 5 使用 @ViewChildren 访问 div 列表