rn 手动实现启动页

(1)在index.js中挂载的组件是一个栈导航组件,该组件中包含启动组件和app组件

(2)然后在启动页组件中通过定时器跳转到其他组件

代码示例:
index.js

/**
 * @format
 */

 import React,{Component} from 'react'


import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import Launch from './pages/launch/index';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';

class Power extends Component{

    render()
    {
        const Stack=new createStackNavigator()
        return(
            <NavigationContainer>
                <Stack.Navigator
                    initialRouteName='launch'
                >
                    <Stack.Screen name='launch' component={Launch} options={{headerShown:false}} />
                    <Stack.Screen name='app' component={App} options={{headerShown:false}} />
                </Stack.Navigator>
            </NavigationContainer>
        )
    }

}

AppRegistry.registerComponent(appName, () =>Power);

app.js:

import React,{Component} from 'react'
import 'react-native-gesture-handler';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import {
  View,
  Text,
  StyleSheet,
  Image
} from 'react-native'
import Main from './pages/main/index'
import Half from './pages/halfHour/index'
import Search from './pages/search/index'

class App extends Component{
    state={
      selectedTab:''
    }

    render()
    {
        const Stack=new createStackNavigator();
        return(
            // <NavigationContainer>
              <Stack.Navigator initialRouteName='main'>
                <Stack.Screen name='main' component={Main} options={{headerShown:false}}/>
                <Stack.Screen name='half' component={Half} options={{headerShown:false}}/>
                <Stack.Screen name='search' component={Search} options={{headerShown:false}}/>
              </Stack.Navigator>
            // </NavigationContainer>
        )
    }
}

const styles = StyleSheet.create({


})

export default App

启动页组件:

import React,{Component} from 'react'
import {
  View,
  Text,
  StyleSheet,
  Image,
  Dimensions
} from 'react-native'

class Launch extends Component{

    componentDidMount()
    {
        let that=this;

        setTimeout(()=>{
            that.props.navigation.navigate('app');
        },3000)
    }
    
    render()
    {
        return(

            <View>
                <Image style={{width:Dimensions.get('window').width,height:Dimensions.get('window').height}} source={{uri:'https://dss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1431796901,1804537979&fm=26&gp=0.jpg'}} />

            </View>
        )
    }
}

const styles = StyleSheet.create({


})

export default Launch

效果图:
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值