react-native - react-navigation:带有嵌套导航器的全屏背景
问题描述
首先,对于正在寻找使用嵌套导航器显示全屏背景图像的解决方案的任何人,下面的代码将提供一个很好的开端。我找不到任何更好的资源,我花了一段时间才把它放在一起。
现在进入问题。问题是在使用嵌套导航器时似乎没有更好的方法来显示一致的全屏图像背景,这将是许多应用程序最常见的用例。理想情况下,您配置的背景图像RootStack
就是这样。
下面代码的问题是MenuStack
即使包裹在 a 中也不会显示背景图像,MenuStackWrapper
并且当尝试在Menu
组件本身中渲染图像时,图像调整大小不同,因此看起来像是在移动。
const MenuStack = createStackNavigator(
{
Menu,
Log,
},
{
headerMode: 'none'
}
);
const MainStack = createBottomTabNavigator(
{
Now,
Today,
Menu: MenuStack
},
{
initialRouteName: 'Now',
tabBarOptions: {
style: {
backgroundColor: 'transparent'
}
}
}
);
class MainStackWrapper extends Component {
static router = MainStack.router;
render() {
return (
<ImageBackground source={require('./res/images/bgr.png')} style={{ width: '100%', height: '100%' }} imageStyle={styles.backgroundImage}>
<MainStack navigation={this.props.navigation} />
</ImageBackground>
);
}
}
const AppStack = createStackNavigator(
{
Main: MainStackWrapper,
Modal: ModalScreen
},
{
mode: 'modal',
headerMode: 'none',
cardStyle: {
backgroundColor: 'transparent'
}
}
);
const AuthStack = createSwitchNavigator({
SignIn,
SignUp,
ForgotPass
});
const RootStack = createSwitchNavigator(
{
AuthLoading,
Auth: AuthStack,
App: AppStack
},
{
initialRouteName: 'AuthLoading'
}
);
type Props = {};
export default class App<Props> extends Component {
render() {
return (
<ImageBackground source={require('./res/images/bgr.png')} style={{ width: '100%', height: '100%' }} imageStyle={styles.backgroundImage}>
<StatusBar barStyle="light-content" backgroundColor="transparent" translucent={true} />
<RootStack />
</ImageBackground>
);
}
}
const styles = StyleSheet.create({
backgroundImage: {
resizeMode: 'cover',
width: null,
height: null,
backgroundColor: 'transparent',
flex: 1,
flexDirection: 'column'
}
});
解决方案
推荐阅读
- kubernetes - Kube / 使用配置图创建部署
- c# - 处理调用的通用方法
- c - times() syscall. Overflowed return value
- html - Make two tables side by side not overlap as screen gets smaller
- android - mText1.getLayoutParams().height = NEW VALUE 在弹窗中不生效
- if-statement - C++:IF/ELSE 与正值和负值的比较
- php - 替代使用 shebang
- sql - 更改 SQL 用户名
- pyspark - 如何在 pyspark 中将 Unicode 日期/时间字符串转换为 python 日期时间
- c# - 在 Observable Collection 中移动项目将移动项目重置为默认值