A splash screen is the first screen the users see after tapping the app icon. It's typically a simple screen with your app logo in the center and g...
For further actions, you may consider blocking this person and/or reporting abuse
I am now using React Native 0.71. Most of these instructions still work great, but I am stuck at the part about editing AppDelegate.m (Under the heading “Setting a blank background on iOS” above), as that file no longer exists with RN 0.71. Instead, there is AppDelegate.mm, and there is nothing in that file that matches the instructions. I tried just adding the suggested line in the file, but it failed to compile, and I don’t know what I’m doing in that file anyway.
I was able to complete all the other steps, and it works perfectly on Android. It’s nearly there on iOS: it launches with the appropriate blank color as defined in LaunchScreen.storyboard, then it briefly flashes to white, then it goes on correctly to the code created in “The JS Part.” I would like to get rid of the flash of white, and I suspect it relates to the step about editing AppDelegate.m that I can’t figure out in this version of React Native.
Does anyone have a suggestion?
Yes, I've updated the article now.
You can use the following line to change the color of the native view and avoid the blank screen:
It is so kind of you to respond. I’m afraid I still can’t figure out where to put that line, since I have no AppDelegate.m file in this project that was newly started from React Native 0.71. I have also done a search across my entire code base for
self.window.rootViewController
as well asrootView.backgroundColor
and I got no results. I tried adding the line you suggested above to various places in AppDelegate.mm, AppDelegate.h and main.m just to see if it was as simple as that, but in each case, the app could not compile.In the end, I am not sure that it is necessary. Following the rest of your steps (many thanks, by the way), the flash of the default color appears only to happen on dev builds of the app. On a release build, the app launches with my desired color from the beginning and moves smoothly into the splash screen as I would hope.
Open AppDelegate.mm and change the following line:
to this:
I've updated the article. Also there's a slight change in the
LaunchScreen.storyboard
file. You can change the colorSpace of your background to use device RGB (colorSpace="deviceRGB") otherwise the colors will be slightly different between the native to JS handoff.Thank you for the followup. I have now implemented this last change with success. I also thank you for updating your article so it stays relevant.
I am trying to understand this part.
const [state, setState] = useState<
| typeof LOADING_IMAGE
| typeof FADE_IN_IMAGE
| typeof WAIT_FOR_APP_TO_BE_READY
| typeof FADE_OUT
| typeof HIDDEN
When I try to use this, I get an error saying unexpected token pointing to the | in front of the first typeof. How are you able to do that?
For this I converted the constants to a TS enum:
enum SplashState {
Loading,
FadeIn,
WaitForReady,
FadeOut,
Hidden,
}
// ...
const [state, setState] = useState<SplashState>(SplashState.Loading)
Or you could use a TS union type of the string constants.
Hello Everyone,
We got issues in splash screen i.e., white screen is coming after the splash screen instead of redirected to the login screen. And it took more time to load the index.js file.So, that during transition from splash screen to login screen in between white screen.
Could you please help us out as soon possible?
I translated the splash component code as follows:
import React, { useEffect, useRef, useState } from "react";
import { Animated, StyleSheet } from "react-native";
export function WithSplashScreen(props) {
return (
<>
{props.isAppReady && props.children}
);
}
const LOADING_IMAGE = "Loading image";
const FADE_IN_IMAGE = "Fade in image";
const WAIT_FOR_APP_TO_BE_READY = "Wait for app to be ready";
const FADE_OUT = "Fade out";
const HIDDEN = "Hidden";
export const Splash = (isAppReady = props.isAppReady) => {
const containerOpacity = useRef(new Animated.Value(1)).current;
const imageOpacity = useRef(new Animated.Value(0)).current;
const [state, setState] = useState(LOADING_IMAGE);
useEffect(() => {
if (state === FADE_IN_IMAGE) {
Animated.timing(imageOpacity, {
toValue: 1,
duration: 1000, // Fade in duration
useNativeDriver: true,
}).start(() => {
setState(WAIT_FOR_APP_TO_BE_READY);
});
}
}, [imageOpacity, state]);
useEffect(() => {
if (state === WAIT_FOR_APP_TO_BE_READY) {
if (isAppReady) {
setState(FADE_OUT);
}
}
}, [isAppReady, state]);
useEffect(() => {
if (state === FADE_OUT) {
Animated.timing(containerOpacity, {
toValue: 0,
duration: 1000, // Fade out duration
delay: 1000, // Minimum time the logo will stay visible
useNativeDriver: true,
}).start(() => {
setState(HIDDEN);
});
}
}, [containerOpacity, state]);
if (state === HIDDEN) return null;
return (
collapsable={false}
style={[style.container, { opacity: containerOpacity }]}
>
source={require('../images/bluecircle.png')}
fadeDuration={0}
onLoad={() => {
setState(FADE_IN_IMAGE);
}}
style={[style.image, { opacity: imageOpacity }]}
resizeMode="contain"
/>
);
};
const style = StyleSheet.create({
container: {
...StyleSheet.absoluteFillObject,
backgroundColor: '#E0B9BB',
alignItems: "center",
justifyContent: "center",
},
image: {
width: 250,
height: 250,
},
});
Hey. What's this function you're using
initialize()
?I use it to initialize the app and run stuff I need to do on app start.
For example it could look something like this:
Hi! I wanted to attach video to the splash screen background I am from JS world so have little to no knowledge of objective c and all that.
This works pretty great but does anyone else have an issue with the splash screen being a bit blurry on Android?
Just make sure the image you use has a big enough resolution
Thanks it works great on iOS but on android the background color is popping up during navigation (probably due to android:windowBackground set to AppTheme in styles.xml)
Ok the issue is linked to Stack.Navigator V6..
to fix it, i've added a screenOptions param to Stack.Navigator
<Stack.Navigator screenOptions={{ presentation: 'transparentModal', contentStyle: { backgroundColor: 'white' } }}>
Hello everyone!
The image is not appearing for me even though I have placed the right path, anyone that can help?
Thanks in advance!
awesome thank you
Can you share the code as well? The repo I mean, mostly for the Splash Screen but also for how you setup your application.
Here's an example of an app with a completely set up splash screen.
github.com/hrastnik/react-native-s...