Table of Contents
Preface
ReactNative's App guide page implementation logic
Solution to the RN guide page:
How to judge whether to display the boot page or the homepage
App boot page Implementation code
Achievement effect
Home Web Front-end Front-end Q&A How to use react to implement a boot page

How to use react to implement a boot page

Jan 06, 2023 pm 03:44 PM
react

How to use react to implement the boot page: 1. Create a startup interface with code such as "import React, { Component } from 'react'; import{AppRegistry,StyleSheet,Text,View,AsyncStorage...} "; 2. Determine each startup and obtain whether the attributes loaded for the first time have been saved before. If it has been loaded, the home page will be displayed. If it has not been loaded, the boot page will be displayed.

How to use react to implement a boot page

The operating environment of this tutorial: Windows 10 system, react18.0.0 version, Dell G3 computer.

How to use react to implement the boot page?

Preface

Seeing that many companies are beginning to try to use ReactNative to achieve cross-platform development, I have also written many articles recently, hoping to help more students who want to know more get started quickly. ReactNative.

ReactNative's App guide page implementation logic

  • Implementing the guide page in RN is much more complicated than the native implementation.
  • Reasons:
  • 1. The native configuration information info.plist file cannot be read in RN, so it is impossible to determine whether the current version is the latest version. If it is the latest version, the boot page will be displayed
  • 2. The local storage of RN is asynchronous, not synchronous. This will cause an error to be reported at the beginning if you want to obtain the local storage information and judge whether to display the boot page or the homepage based on the storage information
    • The reason for the error is very simple. As soon as the program starts, the interface needs to be displayed immediately, but due to asynchronousness, it cannot return so quickly.

Solution to the RN guide page:

  • Write a startup interface by yourself, display the startup interface at the beginning
  • Then after the startup interface is displayed, determine whether to display the boot page or the homepage later

How to judge whether to display the boot page or the homepage

  • Enter the interface for the first time, write an attribute, and record the first load.
  • Every time it is started, get whether the attributes loaded for the first time have been saved before. If it has been loaded, the home page will be displayed. If it has not been loaded, the boot page will be displayed.

App boot page Implementation code

/**
 * Created by ithinkeryz on 2017/5/15.
 */
 import React, { Component } from 'react';import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    AsyncStorage,
    Image} from 'react-native';import Main from './Main/Main'import {Navigator} from 'react-native-deprecated-custom-components'import Guide from './Guide/Guide'import Common from './Common/Common'class LaunchView extends Component {
    render(){
        return (
            <Image source={{uri:&#39;LaunchImage&#39;}} style={{width:Common.screenW,height:Common.screenH}}/>
        )
    }

    componentDidMount() {
        // 延迟点
        setTimeout(this.openApp.bind(this),2000);
        // this.openApp();
    }

    openApp(){
        AsyncStorage.getItem(&#39;isFirst&#39;,(error,result)=>{

            if (result == &#39;false&#39;) {
                console.log(&#39;不是第一次打开&#39;);

                this.props.navigator.replace({
                    component:Main                })

            } else  {

                console.log(&#39;第一次打开&#39;);

                // 存储
                AsyncStorage.setItem(&#39;isFirst&#39;,&#39;false&#39;,(error)=>{
                    if (error) {
                        alert(error);
                    }
                });

                this.props.navigator.replace({
                    component:Guide                })
            }
        });
    }}export default class App extends Component {

    // 渲染场景
    _renderScene(route, navigator){
        return (
            <route.component navigator={navigator} {...route} />
        )
    }



    render() {
        // 判断是不是第一次打开


        return (
            <Navigator  initialRoute={{
                component: LaunchView            }}
                        renderScene={this._renderScene.bind(this)}

                        style={{flex:1}}
            />
        );


    }
    }
Copy after login

Achievement effect

First time entering

How to use react to implement a boot page
##Startup page
How to use react to implement a boot page
Guidance page
After entering, go directly to the home page

How to use react to implement a boot page
Homepage

Recommended learning: "

react video tutorial"

The above is the detailed content of How to use react to implement a boot page. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to build a real-time chat app with React and WebSocket How to build a real-time chat app with React and WebSocket Sep 26, 2023 pm 07:46 PM

How to build a real-time chat app with React and WebSocket

Guide to React front-end and back-end separation: How to achieve decoupling and independent deployment of front-end and back-end Guide to React front-end and back-end separation: How to achieve decoupling and independent deployment of front-end and back-end Sep 28, 2023 am 10:48 AM

Guide to React front-end and back-end separation: How to achieve decoupling and independent deployment of front-end and back-end

How to build simple and easy-to-use web applications with React and Flask How to build simple and easy-to-use web applications with React and Flask Sep 27, 2023 am 11:09 AM

How to build simple and easy-to-use web applications with React and Flask

How to build a reliable messaging app with React and RabbitMQ How to build a reliable messaging app with React and RabbitMQ Sep 28, 2023 pm 08:24 PM

How to build a reliable messaging app with React and RabbitMQ

How to build a fast data analysis application using React and Google BigQuery How to build a fast data analysis application using React and Google BigQuery Sep 26, 2023 pm 06:12 PM

How to build a fast data analysis application using React and Google BigQuery

React code debugging guide: How to quickly locate and solve front-end bugs React code debugging guide: How to quickly locate and solve front-end bugs Sep 26, 2023 pm 02:25 PM

React code debugging guide: How to quickly locate and solve front-end bugs

React Router User Guide: How to implement front-end routing control React Router User Guide: How to implement front-end routing control Sep 29, 2023 pm 05:45 PM

React Router User Guide: How to implement front-end routing control

React responsive design guide: How to achieve adaptive front-end layout effects React responsive design guide: How to achieve adaptive front-end layout effects Sep 26, 2023 am 11:34 AM

React responsive design guide: How to achieve adaptive front-end layout effects

See all articles