react-native-bootsplash icon indicating copy to clipboard operation
react-native-bootsplash copied to clipboard

v6 - Expo plugin, simpler setup

Open zoontek opened this issue 1 year ago β€’ 12 comments

Hi folks! πŸ‘‹

This PR has been opened to track the development of the next major version: v6 ✨ Note that the React Conf app, that uses expo, is already using this beta (with useHideAnimation)!

Check this beauty πŸ‘€ :

https://github.com/zoontek/react-native-bootsplash/assets/1902323/25179bac-bb9b-4d9b-b1ca-28a4bd01d567

What's new

Expo plugin 🧩

In order to fix the duplicate splash screens issue on Android 12+ and beneficiate from this library animation capabilities, expo users can now uses react-native-bootsplash as a replacement for expo-splash-screen.

The bootsplash CLI is still in charge of the heavy stuff (images generation, license check if required…), but will now outputs all files in assets/bootsplash instead, when it detects that the project uses expo.

The expo plugin edits the android / ios config files (AndroidManifest.xml, MainActivity.{java,kt}, styles.xml, colors.xml, AppDelegate.m, Info.plist, YourApp.xcodeproj…) on prebuild and copy the generated assets in the correct directories.

Simpler setup ✨

In bare react-native projects, the generator is now able to edit your AndroidManifest.xml and styles.xml, removing those two steps from the setup process.

Other changes

  • A new theme is available: Theme.BootSplash.TransparentStatus. It's an easier way to have a transparent status bar on android (with an opaque navigation bar)
  • A ready option has been added to useHideAnimation in order to delay your animation, if you want to wait for something else than just layout rendering + images loading.
  • --assets-output now has a default value, which is assets/bootsplash and will always be generated, as it's required for expo or the useHideAnimation hook (assets/bootsplash_logo.png become assets/bootsplash/logo.png, etc.)
  • --html default is now public/index.html.
  • All iOS assets are now suffixed with a short hash of the different splash screen items to prevent caching issues (before, it was only the logo).
  • iOS implementation now always uses a colorset for background color, even if you choose not to support dark mode (before it was inlined in the .storyboard file in such case).

How to try it

Install the @next version:

$ npm install --save react-native-bootsplash@next
# --- or ---
$ yarn add react-native-bootsplash@next

With expo

  1. Remove expo-splash-screen autolinking (in your package.json):
"expo": {
  "autolinking": {
    "exclude": [
      "expo-splash-screen"
    ]
  }
}
  1. Edit your app.json:
{
  "expo": {
-   "splash": {
-     "image": "./assets/splash.png",
-     "resizeMode": "contain",
-     "backgroundColor": "#ffffff"
-   },
+   "plugins": [
+     ["react-native-bootsplash", { "assetsDir": "assets/bootsplash" }]
+   ]
  }
}

πŸ“Œ The available plugins options are:

type PluginOptions = {
  assetsDir?: string; // optional, default is "assets/bootsplash"
  android?: {
    parentTheme?: "TransparentStatus" | "EdgeToEdge"; // optional, default is `undefined` (`Theme.BootSplash`)
    darkContentBarsStyle?: boolean; // optional, default is `undefined`
  };
};
  1. Run the generation:
$ npx react-native generate-bootsplash …
# --- or ---
$ yarn react-native generate-bootsplash …
  1. Finally, if you meet some, report any issue here πŸ›

What's next?

  • I need to write a (small) MIGRATION.md guide.
  • Currently, the expo integration doesn't properly work with expo-updates. As the RCTRootView instance is recreated during app launch, a quick flicker is unfortunately visible. We are working with the expo team to fix this.
  • Removing the splash property from app.json will be enough to unlink expo-splash-screen, without any additional config in your package.json. The expo team is working on this.

[!NOTE]
Don't forget that the CLI requires a license key for advanced options such as brand image or dark mode. πŸ‘‰ You can buy it on Gumroad and uses the REACTCONF2024 discount code for -50% (expires the 1st of June).

You can also see this as a good way to support my work in the react native community, keep my motivation up, and keep this library alive and well-maintained. πŸ™Œ

zoontek avatar May 01 '24 17:05 zoontek

There's no need to run npx expo customize public/index.html if you specify --platforms=web anymore!

zoontek avatar May 28 '24 08:05 zoontek

Hello I tried using v6 on my expo project and found a bug. I'm using expo@51 (0.74.1) with new arch, prebuild setup android shows it as intended. However, IOS shows blank screen. I digged around prebuilt ios directory and found that expo plugin was injecting (< 0.74) config rather than (0.74+) config.

exploitJ avatar Jun 03 '24 15:06 exploitJ

I'm aware, as expo does not properly support customizeRootView with expo-updates

I'm waiting for their fix (it also require a react native update)

zoontek avatar Jun 03 '24 15:06 zoontek

@exploitJ The PR has been accepted, the fix should land soon: https://github.com/facebook/react-native/pull/44775

zoontek avatar Jun 05 '24 15:06 zoontek

Hello, I've just followed the steps mentioned here but I'm not sure how to fully disable the expo splash screen so that it doesn't get invoked at all. At the moment due to the unlinking step mentioned I get Cannot find native module 'ExpoSplashScreen' when running my app. I'm not directly importing the expo splash screen anywhere, so I assume this is called by default. If I remove the unlinking, things work but It looks like I'm getting multiple splash screens. This is using v50 of expo and v3 of expo-router.

Mirthis avatar Jun 06 '24 13:06 Mirthis

@Mirthis Are you running the latest beta? Should be 6.0.0-beta.9. As you disable a module here, don't forget to run a prebuild with --clean.

zoontek avatar Jun 06 '24 13:06 zoontek

@Mirthis Are you running the latest beta? Should be 6.0.0-beta.9. As you disable a module here, don't forget to run a prebuild with --clean.

@zoontek thanks for the quick response. Yes I've just double checked the version and it's 6.0.0-beta.9. I have also run a prebuild with the --clean flag (I have not before seeing your message^^') but no difference.

As mentioned above If I don't remove expo-splash-screen from auto-linking the app works and I can see the splash screen created by bootsplash (icon I selected when running the asset generation, on a white background) and after that the default expo splash-screen (as I removed splash settings from my app.config.ts). That's why I think when removing expo-splash-screen I get the error mentioned, as this is still called somehow. Is the expectation that by just removing expo-splash-screen from the build, this would not be used?

Mirthis avatar Jun 06 '24 15:06 Mirthis

@Mirthis Would you be able to test with Expo 51? Or to publish a repository with a reproduction (Expo 50).

zoontek avatar Jun 06 '24 15:06 zoontek

@zoontek: From an initial test it looks like it works fine with expo 51. Unfortunately the rest of my app doesn't work anymore as the upgrade broke something else :(

I need to spend some more time on this, I'll let you know if I find out something useful.

Mirthis avatar Jun 06 '24 17:06 Mirthis

@Mirthis I will have to set a requirement for Expo 51 anyway, as the customizeRootView fix will land in a RN 0.74 minor update (and so, an Expo 51 update)

zoontek avatar Jun 06 '24 18:06 zoontek

@Mirthis I will have to set a requirement for Expo 51 anyway, as the customizeRootView fix will land in a RN 0.74 minor update (and so, an Expo 51 update)

@zoontek: thanks for your help. I now have a working version on Expo 51.

Mirthis avatar Jun 06 '24 22:06 Mirthis

Fyi I've just released 0.74.3 @zoontek

Titozzz avatar Jul 02 '24 06:07 Titozzz

image

Hi zoontek, I'm having trouble building EAS. what's the problem,

fazomo avatar Jul 08 '24 05:07 fazomo

image

"npx react-native generate-bootsplash" also performed correctly. What's the problem?

fazomo avatar Jul 08 '24 06:07 fazomo

@fazomo First one is an error with the sharp package that cannot be installed on your device for some reason. Second one is because the images has not been generated (because sharp is missing). Fix 1, it will fixes 2.

I highly recommend NOT TO generate the assets in the CI, tho. Generate them on your computer and commit them.

zoontek avatar Jul 08 '24 09:07 zoontek

image "npx react-native generate-bootsplash" also performed correctly. What's the problem?

@zoontek thanks for this amazing PR. I'm trying it (6.0.0-beta.9) with Expo 51.0.20 and it's working perfectly with local prebuild. However, while trying to build the app through EAS I'm getting the same error mentioned by @fazomo. What's really strange is that the assets are actually committed in the git repo. Not sure if I'm missing something

Screenshot 2024-07-15 alle 14 16 56

enzomanuelmangano avatar Jul 15 '24 12:07 enzomanuelmangano

@enzomanuelmangano Did you set the "assetsDir" option in your app config?

zoontek avatar Jul 15 '24 16:07 zoontek

@zoontek I'm using this config in the app.config.ts, copied from React Conf App πŸ˜…. I added the "assetsDir" although I think it's the default but unfortunately the issue is still there. What doesn't make sense to me is that locally the prebuild works perfectly and only fails while creating the build with EAS.

[
  "react-native-bootsplash",
  {
    assetsDir: "assets/bootsplash",
    android: {
      parentTheme: "TransparentStatus",
      darkContentBarsStyle: false
    }
  }
]
Screenshot 2024-07-15 alle 18 10 38

enzomanuelmangano avatar Jul 15 '24 16:07 enzomanuelmangano

@enzomanuelmangano I think there's an issue with workingPath in CI

zoontek avatar Jul 15 '24 16:07 zoontek

@fazomo @enzomanuelmangano Could you try latest beta (10)? The expo plugin now stop using workingPath, uses modRequest.projectRoot instead (don't forget to run expo prebuild --clean)

I also set a requirement for Expo 51.0.20 in order to use customizeRootView (which is finally available in expo!). So…this is probably the latest beta before stable release πŸ‘€

zoontek avatar Jul 16 '24 21:07 zoontek

@fazomo @enzomanuelmangano Could you try latest beta (10)? The expo plugin now stop using workingPath, uses modRequest.projectRoot instead (don't forget to run expo prebuild --clean)

I also set a requirement for Expo 51.0.20 in order to use customizeRootView (which is finally available in expo!). So…this is probably the latest beta before stable release πŸ‘€

Sorry for my late reply. I've just checked again and it worked perfectly! Thanks a lot for your work πŸ™Œ

enzomanuelmangano avatar Jul 19 '24 09:07 enzomanuelmangano

@enzomanuelmangano And thanks for your sponsorship, it means a lot πŸ™

zoontek avatar Jul 19 '24 09:07 zoontek

Hi @zoontek, I face an error (using 6.1.2): drawable/bootsplash_logo not found.

[RUN_GRADLEW] Execution failed for task ':app:processReleaseResources'.
[RUN_GRADLEW] > A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
[RUN_GRADLEW]    > Android resource linking failed
[RUN_GRADLEW]      com.me.myapp.app-mergeReleaseResources-59:/values/values.xml:4911: error: resource drawable/bootsplash_logo (aka com.me.myapp:drawable/bootsplash_logo) not found.
[RUN_GRADLEW] com.me.myapp.app-mergeReleaseResources-59:/values/values.xml:4911: error: resource drawable/bootsplash_logo (aka com.me.myapp:drawable/bootsplash_logo) not found.
[RUN_GRADLEW]      error: failed linking references.

The command I ran: yarn react-native generate-bootsplash assets/my-icon.png --platforms=android,ios --background=026A9F --logo-width=100

I checked android/app/src/main/res/drawable and bootsplash_logo was indeed not there. Found splashscreen_image.png instead.

Happy to provide more details. Thanks :)

mikib0 avatar Sep 01 '24 06:09 mikib0