我正在使用react-navigation和 stack-navigator 来管理我的屏幕。
我正在使用的平台:
- 安卓
- 反应原生:0.47.1
- 反应导航:1.0.0-beta.11
- 模拟器和设备
我有一个屏幕,它充当模态表单,但它实际上是一个全屏。为什么“作为模态形式”的部分很重要?那是因为它是一种带有一些选项和透明背景颜色的模式菜单。
这是我所期望的:
但我得到的是:
如您所见,在第二个示例中,背景颜色被完全替换或先前加载的组件被卸载,因此我想要实现的效果丢失了。 这个想法是能够像任何其他屏幕一样导航到这个屏幕。
如果无法使用 react-navigation 完成,我还能采取什么其他方式来做到这一点?
该组件执行动作(redux),因为它是一个跨应用程序组件,并在内部封装了许多机制和逻辑,这就是为什么我不能将它用作使用PureComponent
该组件的组件的中继。至少,将这个组件作为 PureComponent 将迫使我在许多其他组件中复制许多机制和逻辑。
为了这个问题,也为了避免问题太大,两个屏幕都有完全相同的样式,但是通过StackNavigation
的那个替换了backgroundColor
,或者卸载了前一个屏幕。
这是我到目前为止所拥有的:
//PlaylistSelector.js
render() {
//Just a full size empty screen to check and avoid bugs
//Using red instead of transparent, works
return (
<View style={{ flex: 1, backgroundColor: 'transparent' }}>
</View>
);
}
//Navigator.js
import { StackNavigator } from 'react-navigation';
import Album from './Album'; //This is the screen I expect to keep at the background
import PlaylistSelector from './PlaylistSelector';
const AppNavigator = StackNavigator(
{
...moreScreens,
Album: { screen: Album },
PlaylistSelector: {
screen: PlaylistSelector,
navigationOptions: {
style: { backgroundColor: 'red' } //Does not work, red is just to ilustrate, should be transparent,
cardStyle: { //Does not work,
backgroundColor: 'transparent',
},
bodyStyle: { //Does not work,
backgroundColor: 'transparent',
},
}
}
},
{
initialRouteName: 'Splash',
headerMode: 'none',
cardStyle: { //Does not work
backgroundColor: 'transparent',
},
transitionConfig: (): Object => ({ //Does not work
containerStyle: {
backgroundColor: 'transparent',
},
}),
}
);
export default AppNavigator;