I have the following structure, which allows me to create a loading before displaying the content of the App:
App.js
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Splash from './Splash';
export default class App extends React.Component {
state = {
loaded: false
}
constructor() {
super();
Splash.load(v => this.setState({loaded: true}));
}
render() {
return(
<View style={styles.container}>
{this.state.loaded ? <Text>Welcome!</Text> : <Text>Loading...</Text>}
</View>
)
}
}
Splash.js
export default class Splash {
static load(cb){
setTimeout(cb, 3000);
}
}
What I want is to show a background color plus the logo when opening the application and after a few x seconds the content is displayed.
This is what I want to achieve:
After show content/information:
Based on the approach of my code that changes I must use, I am sure that they are some small changes that unfortunately I cannot find an example on the web to be able to achieve it.
The best way to implement a Splash Screen is using React-Navigation since by using this we can manage which view we can put first and then in the same way in all the respective navigation of the app
First, if you don't have React navigation, install it as follows
Y
Finally for the example we are going to use the Stack type navigation for which we need to install the following library as well
We are going to start to approach it by creating 2 views, Splash.js and Menu.js and then in the App.js import them and show them
in Splash you put this
Then in the Menu view
Finally in App.js we would have to import Splash and Menu, create the navigation
If you notice within
<Stack.Navigator>
I put the Splash first, this is done so that it is the first view in rendersThat would be it, you should keep in mind to change the paths of the image and the app.js imports depending on the file structure of your project
If I miss any mistake I apologize, I did it without trying
Cheer up, keep learning and filling yourself with new things