iOS Launch screen in React Native
Asked Answered
C

13

116

I'm working with a React Native app and I'm trying to set a customize launch screen but I'm not able to.

React Native creates a LaunchScreen.xib by default, so I've created a LaunchImage inside Images.xcassets:

LaunchImage in Images.xcassets

I've also read that I've to modify the "Launch Screen File" under "App Icons and Launch Images" in my options:

Launch Images options

Once I've done that, my launch screen became totally black and when the app is loaded, there are both top and bottom black frames:

enter image description here

What do I have to do to set my launch screen in my React Native project?

Cardwell answered 1/12, 2015 at 18:15 Comment(8)
Why is the Launch Screen File empty in your second screenshot?Daisydaitzman
Because I've read that I have to leave it empty if I want the app uses the images in assets directoryCardwell
OK, you are right. To get a better understanding: Is the text from the black frame at the top from you or from react?Daisydaitzman
That is from React. At first a black screen is shown (which it'd be the launch screen), after that the text that I show in the screenshot, and after the text my app appears. This text also appeared before, when my app had the default React Native launch screen.Cardwell
uninstall from the device, clean the project and try to install againEdmiston
@Stark wait, you should also click on "Use asset Catalog" and select your LaunchImageEdmiston
Thanks for your response. If I click on "Use Asset catalog" I can't select "LaunchImage" -> puu.sh/lGuc2/8e21ba0967.png I've also tried to uninstall from the device, clean and install again but it didn't work either.Cardwell
How can achieve creating splash screen for the project created with "create-react-native-app" ?Homophile
C
125

I was be able to solve the issue, with the help of this thread: Launch Image not showing up in iOS application (using Images.xcassets)

So I'm gonna explain it deeply in case it can help someone else.

First, you need to create certain images. What I used for that was this template and this webpage with an automatic generator: TiCons

enter image description here

When I downloaded my images, I took the ones inside assets/iphone folder, I only took those ones:

Also you need this Contents.json file in the same folder, I got it from a friend:

{
  "images": [
    {
      "extent": "full-screen",
      "idiom": "iphone",
      "filename": "[email protected]",
      "minimum-system-version": "7.0",
      "orientation": "portrait",
      "scale": "2x",
      "subtype": "retina4"
    },
    {
      "extent": "full-screen",
      "idiom": "iphone",
      "filename": "[email protected]",
      "minimum-system-version": "8.0",
      "orientation": "portrait",
      "scale": "2x",
      "subtype": "667h"
    },
    {
      "extent": "full-screen",
      "idiom": "iphone",
      "filename": "[email protected]",
      "minimum-system-version": "8.0",
      "orientation": "landscape",
      "scale": "3x",
      "subtype": "736h"
    },
    {
      "extent": "full-screen",
      "idiom": "iphone",
      "filename": "[email protected]",
      "minimum-system-version": "8.0",
      "orientation": "portrait",
      "scale": "3x",
      "subtype": "736h"
    },
    {
      "extent": "full-screen",
      "idiom": "iphone",
      "filename": "[email protected]",
      "minimum-system-version": "7.0",
      "orientation": "portrait",
      "scale": "2x"
    }
  ],
  "info": {
    "version": 1,
    "author": "xcode"
  }
}

So, at this point I created a folder called LaunchImage.launchimage inside Images.xcassets folder in my React Native project and save the images and the Contents.json file inside it:

enter image description here

Second, you have to open your project in Xcode and in "General" settings, below "App icons and Launch Images" we have to leave the option "Launch Screen File" empty (also we can delete the LaunchScreen.xib file inside our project), and click in "Use Asset Catalog" after that. A modal will open, we choose to Migrate the catalog Images

enter image description here

Now, in the "Launch Images Source" selector, we can choose the folder we created before, LaunchImage (the one with our images):

enter image description here

We pick this instead of Brand Assets and we can delete Brand Assets folder.

At this point, we'll be able to run our React Native application with our custom launch images:

enter image description here

I know it seems a little bit complex for an supposedly easy task, but after reading a lot about it this was the only way I could get my splash images working, so I wanted to share with the community.

Cardwell answered 3/12, 2015 at 18:53 Comment(21)
Do the images have to be .png I am trying to use .jpgSecondclass
I've not tried with .jpg images. Maybe it only works with .pngCardwell
thanks the error I am getting in xcode is file does not have valid file extension so it sounds likely that is the problem, although i dont see why jpg wouldnt workSecondclass
Do you have to have all 5 options, my app isnt intended to be used landscape so i left it out but it isnt working so im wondering if that is itSecondclass
I'm not sure. You should add all of them and see if it works! :)Cardwell
I still had issue after this, and had to delete the app from the simulator to get the original launch screen to stop showing.Tootsy
I get an issue when deleting LaunchScreen.xib from the project. When building out the project I get "Interface Builder could not open the document LaunchScreen.xib" because it does not exist. I have followed what you said above. My "Launch Images Source" has my folder I created "LaunchImage" and below the "Launch Screen File" is empty with no text in it at all. What do I need to do to get rid of this error?Attainable
Hi @Attainable Did you unset "LaunchScreen.xib" on the selector "Launch Screen File" in "App Icons and Launch Images" ??? In your project settings.Cardwell
@JVLobo turns out I removed the "LaunchScreen.xib" from the project folder structure, but not from xcode itself. Once I took it out of xcode it worked just fine!Attainable
I've followed every step of your detailed tutorial, but I end up having a black (then white, then my app) screen instead of my images. Did you have this kind of issues? Cheers!Fly
Are you still having troubles?? Did you try to do the process again in case you forget something?Cardwell
@JVLobo Hi, is it possible to hide Status bar on splash imageHereto
I'm not 100% sure, but I don't think you can do it @TeodorKolevCardwell
Great instructions, worked for me! Keep in mind you should Delete the app from the simulator, quit the packager (hard quit out of the terminal), Product > Clean in xCode, then Run and let the packager do its thing as if you're running it for the first time. That was my key to success.Crabber
@PrettyGoodPancake hey, i had the same issue, make sure that the launch screen file field is empty, even if you delete the launchscreen.xib file, this filed remains filled in.Shirting
@AdamKatz Yes, you have to have all 5 options.Bern
@JVLobo I followed your step and still see the powered by RN screen, do you have idea?Chard
@JVLobo Thanks for the thorough post. As it turns out for me, none of these options work. I've tried going so far as moving my entire app to new folders, deleting, recreating the AppIcon, etc. What's weird is that.. it was working. And then it suddenly wasn't a few weeks ago. No idea why it changed. No idea how to get it back.Garboard
For the content.json part, you can go to Images.xassets right click the blank area and select New App Icons & Launch Images, it will generate the json file for you.Difficulty
How can achieve creating splash screen for the project created with "create-react-native-app" ?Homophile
I followed this to the T, but for some reason, although it worked on my simulator, it did not work when I launched the app on my device.Cleaner
T
17

Make sure to delete the app from the simulator. Then do a clean on your project.

Tootsy answered 15/1, 2016 at 16:23 Comment(1)
deleting the app from simulator works for me. thanksLoafer
P
10

Update

generator-rn-toolbox is deprecated. Use react-native-make instead.

old Answer

I recommend generator-rn-toolbox for applying launch screen or main icon using on react-native. It is more simple and easy to use through cli as react-native.

  • Do not need to open XCode.
  • Do not need to make a lot of image files for various resolutions.
  • Anytime change launch screen using one line commend.

Requirements

  • node >= 6
  • One square image or psd file with a size of more than 2208x2208 px resolution for a launch screen(splash screen)
  • Positive mind ;)

Install

  1. Install generator-rn-toolbox and yo
  2. npm install -g yo generator-rn-toolbox
  3. Install imagemagick brew install imagemagick
  4. Apply splash screen on iOS

    yo rn-toolbox:assets --splash YOURIMAGE.png --ios

    or Android

    yo rn-toolbox:assets --splash YOURIMAGE.png --android

That's all. :)

Source

Protractile answered 2/5, 2017 at 7:26 Comment(6)
can't believe i have to ask this ... from where do you run the command?Standush
@Standush Your top project directory.Protractile
"✖ splash could not be found" I don't think this worksStandush
@Standush Was there the your image file? I am using it usefully.Protractile
generator-rn-toolbox actuality does all that the accepted answer does.Alternation
This is now deprecated. Use @bam.tech/react-native-makeWatercress
B
9

I have been looking at these answers a lot in SO containing solutions for how to create a new launch screen. I mean let's think about it for a minute.

When we create a new react-native project what do we see for the launch screen?

> Facebook's default launch screen

So that got me thinking, How did they do it?

They created a LaunchScreen.xib

I think there must be a reason for this. So I went into theLaunchScreen.xib and made a change to the default text "React Native..." or what ever it said. I ran the app one more time to see that the launch screen reflected my edits.

Solution 1 Edit the existing LaunchScreen.xib

Solution 2 Create my own

So I did, it took me longer to type up this answer than learning how to create my own. Both of these solutions are compatible with all the devices.

Step 1:

Delete LaunchScreen.xib

step 2:

click on images.xcassets right click in the white space click **import**then select the image you want to add. enter image description here

step 3:

Right click on your project's root folder and add a new file of type Launch Screen and name it what ever you want.

enter image description here

step 4

Click on your project in the left nav, go to Settings > General and under App Icons and Launch Images. Make sure Launch Image Source is blank and the Launch Screen File is the same name as your newly created launch screen.

enter image description here

step 5

Click on your brand new file you created in step 2, drag an Image View or edit how ever it pleases you.

enter image description here

Then that's it, you're done. You don't even need to clean the solution, just rebuild.

Bilious answered 23/4, 2017 at 2:58 Comment(8)
@Noitidart Glad I could be of some help.Bilious
What I did was not even delete the LaunchScreen.xib, I just deleted the text nodes, then I dragged in an image view, imported the image like you described, then set the image in the UIImageView :) Is there any way to make it responsive? Like on tablet it should be 3x, and on phone it should be 2x? Also my UIImageView is not centered on all devices. :( Here is screenshot of what i have - i.imgur.com/o5SMgHN.pngEiffel
Oh sweet, never mind, its just using xcode normally, setting properties etc these two links really helped me out - simblestudios.com/blog/development/… && developer.apple.com/library/content/documentation/… andEiffel
@Eiffel Good find on those. I'm sure they would be useful for someone looking at this answer.Bilious
Thanks brother! i think the way you discovered is the real way to do it. Creating images with a set backgound color that are the size of each device in each landscape/portrait is not the way to go about it (how the most upvoted answer here does it). Now i can EASILY adjust the color of the background. Scaling etc can be acheived perfectly. With the image, everything is on the image.Eiffel
thus the process is same as if your were developing a swift native app. coolAudraaudras
@OrthoHomeDefense Hi, I am trying to have multiple images as splashscreen. one that fills the page and the other one is logo in the center. I am trying to use this: github.com/crazycodeboy/react-native-splash-screen. its mentioned there to use either LaunchImage or launchscreen.xib I tried using storyboard but then im not sure how to dismiss it (I can do SplashScreen.hide() if Im using LaunchImage) but not sure how to do this in launchscreen.xibOram
@Oram I am not sure I understood your question correctly but in the launchscreen.xib you can configure the properties of a UIimageView to take up the entire screen for the first image. Then stack another UIimageView on top of that one. If that doesn't answer your question can you please post a new SO question and I can try to answer there? Thanks.Bilious
U
7

Just went through this and works a treat. The only road block I discovered was not clearing the simulator content. If you find that your new launch screen isn't working you need to open the simulation and go to the following:

Simulator > Reset content and settings

There must be some hardcore caching going on within that simulator but once that was done - rerun and you'll see the app. Make sure you do this for both xcode simulators and react-native simulators!

Unwarranted answered 23/8, 2016 at 15:36 Comment(0)
A
7

Make sure the 'Launch Screen File' select is empty: enter image description here

Allopathy answered 8/6, 2017 at 8:4 Comment(0)
G
1

Follow this link:

If you want to add a splash screen to my React Native application.Follow the process, the result will be all yours.

STEP:1 First,I created a splashImageResource folder and added the launchScreen.xib file with the splash image.

STEP:2 change the code as written inside the subviews tag. with this code<subviews> <imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" image="splash.png" translatesAutoresizingMaskIntoConstraints="NO" id="ZkI-RL-69Z"> </imageView> </subviews>

STEP:3 You should open your app in Xcode. Here are the steps to follow:

a) Go to your project folder

b) Open the ios folder

c) Go to the file that has .xcodeproj as the extension, in my case it's splasScreenTutorial.xcodeproj

d) Open this file in your Xcode.

e) Delete the launchScreen.xib file.

f) Click on the splashScreenTutorial folder, then go to the TARGETS section

g) Click on the General Tab on the top-left corner of your Xcode and scroll down to App Icons and Launch Images

h) Go to Launch Images Source and click Use Asset Catalog. Click on migrate.

i) Remove the text LaunchScreen from Launch Screen File.

j) Go back to your project folder and open the Images.xcassets file. You should see AppIcon and LaunchImage.

k) Next, click on the LaunchImage, Finally, drag the splash screen images that you have of different sizes to the Launch Image box.

Drag the images like this.

Test Splash Screen a) To see the changes, you need to delete the app from your simulator if you have run the app initially.

b) To delete the app, click on the Hardware menu on your Simulator bar and go to Home.

c) Tap and hold down the particular app icon you want to delete, and click on the X sign on the icon.

d) Run your app again using react-native run-ios

You can see your Splash Screen

Goosy answered 15/12, 2017 at 12:1 Comment(0)
M
1

If you create a Launch screen with the help of React then you should add the same thing in the LaunchScreen.xib file in iOS Xcode for that you can take a Screenshot and add it as an Image in the Images.xcassets.

Open LaunchScreen then add UIImageView in the View from Object Library from Right Panel in Xcode.

enter image description here

Add Trailing, Leading, Bottom and Top Constraints to the View. As Shown Below -

enter image description here

Don't Forget to change the UIImageView ContentMode as AspectFit so that it will look same when the app runs.

After That you need to add code in AppDelegate so that you don't get a white screen. The code is -

 UIView* launchScreenView = [[[NSBundle mainBundle] loadNibNamed:@"LaunchScreen" owner:self options:nil] objectAtIndex:0];
 launchScreenView.frame = self.window.bounds;
 rootView.loadingView = launchScreenView;

You can Refer - https://facebook.github.io/react-native/docs/running-on-device.html#pro-tip

Mennonite answered 22/3, 2018 at 12:1 Comment(0)
D
1

For me on XCode 10.1 and react-native 59.2 I had to go through the additional steps after already adding the images, storyboard and 1 universal image.

  • Right click on the image, click Show in Finder, then edit your Contents.json file
  • Add the image to the 2x and 3x sections
  • Go to the Launch Screen storyboard, with the "ruler" menu
  • Make sure only the inside red arrows are on, not the outside red arrows
  • Click "Safe Area Relative Margins"

enter image description here

Image should now be centered on all size iPhones (tested on Portrait).

Ditzel answered 1/4, 2019 at 19:16 Comment(0)
D
0

If you want to use the existing Launch Screen .xib file React Native initially has set up, but with your own logo and background color (and without any of the React Native default text), you can follow the instructions here: https://medium.com/@kelleyannerose/react-native-ios-splash-screen-in-xcode-bd53b84430ec.

Drennen answered 6/11, 2017 at 14:45 Comment(0)
R
0

Just for those still having trouble, there is one more step missing from the accepted answer before making the iOS Launch screen work.

Open Info.plist in the project folder and delete "Main nib file base name" key. Then, rebuild and hopefully the issue is gone.

Ringhals answered 31/3, 2018 at 20:23 Comment(0)
M
0

Upon following the above solutions my app was getting stuck on the Splash Screen so I did the following 7 steps to add the custom splash screen on ios.

  1. Open the Xcode and locate the LaunchScreen.xib file in your project (Notice that this is the screen which is shown by default in ios)
  2. To remove/edit the text on the screen click on it and do the necessary changes as you like.
  3. To change the background color locate the following icons on the right side bar and click the little icon button at the very top, fourth from the left (when you hover, it’ll say “Show the Attributes Inspector”)

enter image description here

  1. Now that you have know how to change the background color, lets add image to the Splash screen to do that click on the following button and select the Image view from the list and drag and place it where ever you want it on the splash screen.

enter image description here

  1. Now we have to add the image to the Images.xcassets so that we can reference it in the LaunchScreen.xib to do that goto Images.xcassets. click on + button followed by import and then add the image you want to show in the splash screen. Beneath AppIcon you’ll see your image file name. This is the name we’ll use to reference in our LaunchScreen.xib

  2. Now we have to reference the image we added in the LaunchScreen.xib file so navigate back to LaunchScreen.xib and click the image view that we added earlier and on the right hand corner you will see bunch of options. click on first one that says image and select the image which you imported in step 5

enter image description here

  1. clean the project and run react-native run-ios and you should see the changes.
Mier answered 2/4, 2019 at 8:45 Comment(0)
G
-5

You should set the launch screen image source as your image set. Afterwards delete the LauncScreen.xib file. Afterwards do a global search in your project and remove all references to LaunchScreen.xib (look in your entire project. I user sublime text editor so it's cmd+shift+f) and it should work.

Grant answered 2/12, 2015 at 9:54 Comment(1)
Thanks for your answer. I don't understand well because I think you did a typo. I've done a global search in my project to remove references to LaunchScreen.xib, pero there are no references to the file: puu.sh/lGu7z/8fd88a886e.png Thanks.Cardwell

© 2022 - 2024 — McMap. All rights reserved.