-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Initialization] Launch screen white flash #1402
Comments
@alinz - this is fixed in the next release: tadeuzagallo@8d99226 |
@alinz does it look something like https://www.dropbox.com/s/xq522ywqsd16vqe/example.mov?dl=0 |
@liubko Yes, this is exactly what I want to get rid of. I haven't applied the patch yet but I will do it tonight. |
@brentvatne: I don't see how that patch would fix this problem (if I'm blind/stupid please forgive :-). The problem is that there's a moment between when the app has launched and React is still working. Ideally the LaunchScreen would show until React is finished and fully rendered as it does in a "fully native" app. |
@oblador - ah, this would allow you to transition more smoothly by having the same background colour as the launch screen in the "flicker" moment. @vjeux - how do you get past this issue in FB apps? I noticed that F8, which if I understand correctly is 100% React Native, transitions directly from the launch screen to the app. cc @nicklockwood |
There's a (separate) fix for this issue too. Use the new
I've been experimenting with a way to automatically detect the launch image and make this completely automatic, but it's not really ready yet. If you're interested, it looks like this:
|
An easy solution to what @nicklockwood described is to load the launchscreen xib if you're on iOS 8+. |
@ide I am using launchscreen xib. I see my lauchscreen view at the launch time but before my app boots up, I see a white view (flash). |
To clarify, iOS hides your launch screen at the point when React begins loading. To avoid seeing a blank screen, you'll need to extend the time that the launch screen is displayed by manually showing the same view as the RCTRootView's loadingView. |
Thanks @nicklockwood for clarification. That was my bad. :) |
Curtesy of http://stackoverflow.com/a/29115477/255765 I ended up with this: for (NSString *imgName in allPngImageNames){
// Find launch images
if ([imgName containsString:@"LaunchImage"]){
UIImage *img = [UIImage imageNamed:imgName]; //-- this is a launch image
// Has image same scale and dimensions as our current device's screen?
if (img.scale == [UIScreen mainScreen].scale && CGSizeEqualToSize(img.size, [UIScreen mainScreen].bounds.size)) {
NSLog(@"Found launch image for current device %@", img.description);
UIImageView *launchView = [[UIImageView alloc] initWithImage: img];
rootView.loadingView = launchView;
}
}
} Seems to work. |
+1 for a standard/documented way. |
@dvine-multimedia does that work better than the code snippet I provided above? |
@nicklockwood Actually they do very much the same thing. When I started to look into this I probably didn't understand what to do with your snipped for pure lack of any xcode experience. When I finally got to the point where I understood what to do, I didn't realize, that you already had been there. Beside that, I personally find "my" solution a bit more readable. But that pure aesthetics. |
@nicklockwood I tried your code but i still see a white flash. I created a launch image to set as the loading view. launch image is same as the launchScreen.xib. This is the only thing holding the release of our app. Really appreciate any help on this. |
Is the flash appearing after the launch image is hidden, or does the launch image fail to appear? (This may be hard to determine just by looking - change the launch image to something like a solid red rectangle temporarily to be sure). |
@nicklockwood I tried to change the color between xib file and the launchScreen Image. I was still seeing that flash. My code looks like this: UIImageView *launchView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"launchScreen1"]];
rootView.loadingView = launchView;
rootView.loadingViewFadeDelay = 0.0;
rootView.loadingViewFadeDuration = 0.15; I removed the last two line loadingViewFadeDelay and duration now and it seems the problem is solved. I don't see any flash. Nice smooth transition. |
@chirag04 I just tried it with sample project and I didn't see the flash :( here's what I did RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"whiteFlash"
launchOptions:launchOptions];
//here's what I did
UIImage *image = [UIImage imageNamed:@"LaunchImage"];
if (image) {
UIImageView *launchView = [[UIImageView alloc] initWithImage: image];
launchView.contentMode = UIViewContentModeBottom;
launchView.image = image;
rootView.loadingView = launchView;
}
///////////////////////////
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [[UIViewController alloc] init];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES; |
Ok. digging deeper it seems the flash maybe coz my app renders nothing until a value is loaded from asyncstore. render() {
if(!this.state.loaded) return (null);
return <View ...../>;
} I think the loadingView thinks that the js finished rendering and hides the loadingView. However js just finished rendering with that @nicklockwood @alinz I'm just shooting in the air. may not be the actual reason. What do you guys think. Also one thing i noticed is that if i set those loadingViewFadeDelay etc values to 0.30 or higher, the transition is very very smooth. the defaults are 0.25 which is also smooth. |
The purpose of the loadingFadeDelay is precisely to cover the scenario where your app doesn't render anything up immediately, so you're using it correctly. You might want to consider setting the loadingViewFadeDelay explicitly though, in case the default ever changes - and make sure you test on the slowest device you support, in case it takes longer to load. |
I like @nicklockwood solution but you have to consider network latency which can not be predict. One other solution is, set component state to some sort of default value to tell your component to display some sort of loading dialog. |
Cool. I think i have the solution. What do you guys think about having 3 components all being the same.
Not sure how point 3 will scale on different devices though. Would you guys even suggest that? |
Thanks. The effect is very smooth. In my current projects I quite literally have In react-native 0.29 (should have said in the comment) the react native team gave us a public method |
That Ref for the interested: 49f20f4#diff-1346852de0c7f8466a36d42de50ec808R20 |
To add onto this... A solution I found was to assign the This doesn't require any delays to ensure it stays visible until fully loaded. A full snippet (and using the tip provided by @dvine-multimedia) that will find the desired LaunchImage for the device is below: NSArray *allPngImageNames = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:nil];
for (NSString *imgName in allPngImageNames){
if ([imgName containsString:@"LaunchImage"]){
UIImage *img = [UIImage imageNamed:imgName];
if (img.scale == [UIScreen mainScreen].scale && CGSizeEqualToSize(img.size, [UIScreen mainScreen].bounds.size)) {
rootView.backgroundColor = [UIColor colorWithPatternImage:img];
}
}
} The LaunchImage now stays visible until the react-native bundle has fully loaded. |
I've tried nearly every code block in this conversation with no chance but this one worked perfectly. |
any solution for android? |
@pareekkhushboo77 https://github.com/mehcode/rn-splash-screen/blob/master/docs/android.md @sercanov @dbonner1987 This also uses the approach mentioned above for iOS to do the javascript launch screen. |
@arnemart Thanks, still kinda works in RN 0.30.0. I had to delete my app and reinstall it. It had the white flash the first time, but none after that. |
@nicklockwood Is there some sort of callback I can use to know when the actual javascript is loaded. The reason for this being, when my app is navigating between pages there is some transparency where rootView.backgroundColor is visible in the background of the view. I also get a similar problem with the Drawer plugin I'm using during the drawer open transition.
So I basically need a callback to know when the the loading is done. |
@UKDeveloper99 Please refer to the documentation I have linked above a couple times. There is such a callback available. https://github.com/mehcode/rn-splash-screen/blob/master/docs/android.md |
@mehcode that's perfect thanks!! |
Anyone have suggestions for how to implement a |
@ajoshdee I had similar issues where the view ended up being much larger than the screen. Not sure if it's related but I was using AutoLayout in my I needed to also set
To get it to size properly. So #1402 (comment) with that added line above |
You can also update launch color in replace this line in appdelegate.m :
by this line : and find color you want with this website |
Did someone managed the resolve this on Android ? |
Here is a solution for both ios and android: https://github.com/mehcode/rn-splash-screen. My code:
|
Is there any solution for this if I am using storyboard for splash screen? I don't have my launch screen images for each dimension anymore. |
In react native for iOS inside
For RED change the number 52 Note: I'm using react native v0.51.0 |
The Launch Screen is only shown until the app has loaded, not until React has loaded. This results in a white flash between the Launch Screen and the initial view of the app. This commit fixes that by showing the Launch Screen until React also has finished loading. The solution was found here: facebook/react-native#1402 (comment)
Is there still no solution for Android? |
@otoinsa see the above answer #1402 (comment) by @neomib. There are some other splash screen libraries that work just as well for e.g. https://github.com/crazycodeboy/react-native-splash-screen. |
Any suggestion on storyboard used as LaunchScreen ? My approach was like this (but the app crashes at launch)
the app crashes with the following error:
Thanks. |
replaced
with
now the app starts but I get black background. |
Or you can use https://github.com/crazycodeboy/react-native-splash-screen it's much easier :) |
The Launch Screen is only shown until the app has loaded, not until React has loaded. This results in a white flash between the Launch Screen and the initial view of the app. This commit fixes that by showing the Launch Screen until React also has finished loading. The solution was found here: facebook/react-native#1402 (comment)
I just wondering if there is a good practice about LaunchScreen. The reason I'm asking this is, if one adds LaunchScreen, there is a white flash before react-native kicks in and load the app. Is there any way we can prevent this?
The text was updated successfully, but these errors were encountered: