我想知道如何解决一个启动屏幕,比方说它出现几秒钟然后被另一个 View 取代?
我想在第一次启动应用程序时使用它并覆盖一些网络。
最佳答案
这就是我解决加载屏幕的方法。我使用 Navigator Component。
在我的 index.android.js
中,我将 initialRoute
设置为我的 SplashPage/SplashScreen 类,然后在其中设置超时指向您要在特定时间后跳转到的 MainView 的链接。
index.android.js 中的我的导航器:
<Navigator
initialRoute={{id: 'SplashPage'}}
renderScene={this.renderScene}
configureScene={(route) => {
if (route.sceneConfig) {
return route.sceneConfig;
}
return Navigator.SceneConfigs.HorizontalSwipeJump;
}}
/>
我的初始路线类:
class SplashPage extends Component {
componentWillMount () {
var navigator = this.props.navigator;
setTimeout (() => {
navigator.replace({
id: 'MainView', <-- This is the View you go to
});
}, 2000); <-- Time until it jumps to "MainView"
}
render () {
return (
<View style={{flex: 1, backgroundColor: 'red', alignItems: 'center', justifyContent: 'center'}}>
<Image style={{position: 'absolute', left: 0, top: 0, width: windowSize.width, height: windowSize.height}} source={require('image!splash_screen')}></Image>
</View>
);
}
}
module.exports = SplashPage;
编辑
可能更有趣,因为它是“原生”的;) https://github.com/crazycodeboy/react-native-splash-screen
关于android - 如何创建某种在应用程序加载后消失的启动画面/启动画面? ( native react ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33390013/