HwangTaehyun / react-native-lottie-splash-screen

⚡ Lottie splash screen for your react native app!
MIT License
222 stars 62 forks source link

Port to React-Native >= 0.7x and lottie-react-native@6.7.2 #98

Open attarchi opened 4 months ago

attarchi commented 4 months ago

Summary by CodeRabbit

google-cla[bot] commented 4 months ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

ashwini-ksingh commented 1 month ago

@attarchi @erie-e9 When are we planning to release this?

attarchi commented 1 month ago

I have no idea when the repo owner wants to do it but meanwhile, you can add this to your package.json.

    "react-native-lottie-splash-screen": "https://github.com/attarchi/react-native-lottie-splash-screen",
ashwini-ksingh commented 1 month ago

@attarchi I did try using your fork, but getting this error with RN 0.75.4

attarchi commented 1 month ago

@attarchi I did try using your fork, but getting this error with RN 0.75.4

I have tested 0.75.4, and there is no error. Please remove the previous one and set it up from begin with this instruction.

ashwini-ksingh commented 1 month ago

@attarchi It was some issue with the build schemes configured in my project. Recreated the scheme and build was successful.

However, on ios, the lottie splash is immediately removed after load, and does not complete the animation. (tried with setAnimationFinished true/false, but its removed immediately). This is only happening in release build, works fine on debug.

attarchi commented 1 month ago

@HwangTaehyun Cloud you please check this PR?

QaysTrad commented 1 month ago

I have no idea when the repo owner wants to do it but meanwhile, you can add this to your package.json.

    "react-native-lottie-splash-screen": "https://github.com/attarchi/react-native-lottie-splash-screen",

Thanks for updating the package,

I have installed the package from your repo, but when I use RNRestart.restart() the lottie splash it's run again on the iOS, until I close the app and reopen it and when I use LottieSplashScreen.show() the app froze with no response

"react-native": "0.74.0", "react": "18.2.0", "react-native-lottie-splash-screen": "https://github.com/attarchi/react-native-lottie-splash-screen",

attarchi commented 1 month ago

Hi @QaysTrad,

Thank you for your feedback and for testing the package!

I'll look into the issue with RNRestart.restart() causing the Lottie splash screen to reappear on iOS. There might be a conflict there that I'll need to resolve.

Regarding LottieSplashScreen.show(), I have actually removed that method as it didn't align with the package's purpose. This package is designed to handle the native splash screen while React Native is initializing. Once the app is fully loaded and you have access to React components, it's better to control Lottie animations directly using the lottie-react-native package. This package's focus is on the startup process, so handling splash screens beyond that isn't necessary.

Let me know if you need any further clarification!

attarchi commented 1 month ago

Hi @ashwini-ksingh,

I've added an example project to the source code for running this app with RN 0.7x, and updated the package. Please check out the latest version.

Regarding your issue, keep in mind that when setAnimationFinished is set to true, the application won’t wait for the Lottie animation to finish before removing the splash screen. To ensure the splash screen waits for the animation to complete, set this value to false and clear the build folder inside your iOS project directory.

Here’s how you can set it in your code:

// AppDelegate.mm file

    // Make the splash screen wait for the Lottie animation to finish
    [RNSplashScreen setAnimationFinished:false];

After making these changes, rebuild the project, and the splash screen should behave as expected in the release build. Let me know if this resolves the issue!

erie-e9 commented 4 weeks ago

Hi again, I just followed instructions and all seem to be right, app is running without problems using this package v2, but I'm not sure if it 'cuz I'm using latest versions of all, I mean I'm testing new project with latest version of Xcode, metro, react@18.3.1, react-native@0.76.0, iOS simulator with iOS 18 and I notice it runs very quick, I can see my splash-screen only for 0.5 seconds and it only shows it when I close and reopen the app, nothing is displayed if I reload it in terminal.

Note: I know Lottie file is in the splash-screen because that little black square with white words in right side is part of it, it's like a watermark. Note 2: I tested it with RNSplashScreen setAnimationFinished = false and true.

I just read the latest version of metro and react-native help to improve build time but I'd like to be sure that's the reason.

Simulator Screen Recording - iPhone 16 Pro - 2024-10-25 at 15 55 18

ashwini-ksingh commented 3 weeks ago

@erie-e9 I am also facing the same behavior (though I am on RN 0.75.4) Not sure why, its the same using the example in the repo as well (example/RN.0.7x-cli) @attarchi

singhayush1403 commented 3 weeks ago

@erie-e9 Have the same issue. The lottie doesn't finish but the screen is removed

attarchi commented 3 weeks ago

@singhayush1403 @ashwini-ksingh @erie-e9

Thank you very much for your collaboration. I noticed the issue but couldn’t fix it, as I don’t have extensive experience with Objective-C and iOS app initialization. I’ll publish this version in my repo as is. Could you please open a separate issue to address the iOS problem in a future update? If anyone can help with this, feel free to jump in with a PR. Thanks!

attarchi commented 3 weeks ago

I've published the latest changes to npm! You can check out the package here: @attarchi/react-native-lottie-splash-screen on NPM.

Feel free to install it and continue bug fixing.

$ yarn add @attarchi/react-native-lottie-splash-screen
coderabbitai[bot] commented 3 weeks ago

Walkthrough

The changes in this pull request include modifications to several configuration files and the introduction of new files for a React Native project. Key updates involve enhancements to the .gitignore and .npmignore files to exclude Yarn-related files, the addition of a .yarnrc.yml configuration, and significant updates to the README.md for improved clarity. New Android and iOS project files have been created, including MainActivity.kt, MainApplication.kt, and various resource files for managing the splash screen feature. The package.json has been updated to reflect new dependencies and project structure.

Changes

File/Path Change Summary
.gitignore Added entries for Yarn-related files and directories, including .yarn/* while allowing certain subdirectories.
.npmignore Added entry to ignore the .yarn directory.
.yarnrc.yml Introduced configuration settings for Yarn, including cacheFolder, nodeLinker, and yarnPath.
README.md Added "Versions compatibilities" section, reorganized installation instructions, and clarified setup for Android and iOS.
android/build.gradle Applied kotlin-android plugin, updated Lottie library version, and centralized support library version management.
android/src/main/java/org/devio/rn/splashscreen/SplashScreen.java Deleted file managing splash screen functionality in Java.
android/src/main/java/org/devio/rn/splashscreen/SplashScreen.kt Introduced new Kotlin object for managing splash screen dialog with methods to show, hide, and set animation state.
android/src/main/java/org/devio/rn/splashscreen/SplashScreenModule.java Deleted Java class for splash screen module.
android/src/main/java/org/devio/rn/splashscreen/SplashScreenModule.kt Added new Kotlin class extending ReactContextBaseJavaModule for splash screen functionality.
android/src/main/java/org/devio/rn/splashscreen/SplashScreenReactPackage.java Deleted Java class for integrating splash screen functionality.
android/src/main/java/org/devio/rn/splashscreen/SplashScreenReactPackage.kt Added new Kotlin class implementing ReactPackage for splash screen integration.
examples/RN.0.69/package.json Updated project name and dependency path.
examples/RN.0.7x-cli/.bundle/config Added configuration variables for Bundler.
examples/RN.0.7x-cli/.eslintrc.js Introduced ESLint configuration file.
examples/RN.0.7x-cli/.gitignore Created comprehensive .gitignore for various platforms and tools.
examples/RN.0.7x-cli/.prettierrc.js Added Prettier configuration file.
examples/RN.0.7x-cli/.watchmanconfig Created empty Watchman configuration file.
examples/RN.0.7x-cli/.yarnrc.yml Added Yarn configuration settings.
examples/RN.0.7x-cli/App.tsx Introduced sample React Native application with splash screen management.
examples/RN.0.7x-cli/Gemfile Created Gemfile specifying Ruby version and gem dependencies.
examples/RN.0.7x-cli/README.md Added comprehensive guide for getting started with the project.
examples/RN.0.7x-cli/__tests__/App.test.tsx Introduced test file for rendering the App component.
examples/RN.0.7x-cli/android/app/build.gradle New build.gradle file for Android application configuration.
examples/RN.0.7x-cli/android/app/proguard-rules.pro Added comments for ProGuard rules guidance.
examples/RN.0.7x-cli/android/app/src/debug/AndroidManifest.xml Created new AndroidManifest.xml for debug configuration.
examples/RN.0.7x-cli/android/app/src/main/AndroidManifest.xml New manifest file declaring permissions and application components.
examples/RN.0.7x-cli/android/app/src/main/java/com/example/MainActivity.kt New Kotlin file defining the main activity with splash screen integration.
examples/RN.0.7x-cli/android/app/src/main/java/com/example/MainApplication.kt New file for application class extending Application and implementing ReactApplication.
examples/RN.0.7x-cli/android/app/src/main/res/drawable/rn_edit_text_material.xml New drawable resource for inset layout.
examples/RN.0.7x-cli/android/app/src/main/res/layout/launch_screen.xml New layout file defining the launch screen with a Lottie animation.
examples/RN.0.7x-cli/android/app/src/main/res/raw/loading.json New JSON file defining a loading animation.
examples/RN.0.7x-cli/android/app/src/main/res/values/colors.xml New color resource for splash screen background.
examples/RN.0.7x-cli/android/app/src/main/res/values/strings.xml New string resource for application name.
examples/RN.0.7x-cli/android/app/src/main/res/values/styles.xml New styles for application theme and splash screen animation.
examples/RN.0.7x-cli/android/build.gradle New build.gradle configuration for the Android project.
examples/RN.0.7x-cli/android/gradle.properties New properties file for Gradle configuration.
examples/RN.0.7x-cli/android/settings.gradle New Gradle configuration for plugin management and project structure.
examples/RN.0.7x-cli/app.json New JSON file for application metadata.
examples/RN.0.7x-cli/babel.config.js New Babel configuration file for React Native.
examples/RN.0.7x-cli/index.js New entry point for the React Native application.
examples/RN.0.7x-cli/ios/.xcode.env New file for sourcing environment variables in Xcode.
examples/RN.0.7x-cli/ios/Dynamic.swift New Swift class for managing Lottie animations.
examples/RN.0.7x-cli/ios/Podfile New Podfile for integrating React Native with iOS.
examples/RN.0.7x-cli/ios/example-Bridging-Header.h New bridging header for Objective-C interoperability.
examples/RN.0.7x-cli/ios/example.xcodeproj/project.pbxproj New Xcode project file defining project structure and configuration.
examples/RN.0.7x-cli/ios/example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist New workspace checks plist file.
examples/RN.0.7x-cli/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme New scheme file for managing build and execution actions in Xcode.
examples/RN.0.7x-cli/ios/example.xcworkspace/contents.xcworkspacedata New workspace configuration file.
examples/RN.0.7x-cli/ios/example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist New plist file for workspace checks.
examples/RN.0.7x-cli/ios/example/AppDelegate.h New header file for custom application delegate.
examples/RN.0.7x-cli/ios/example/AppDelegate.mm New implementation file for application delegate with splash screen setup.
examples/RN.0.7x-cli/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json New JSON file for AppIcon asset catalog.
examples/RN.0.7x-cli/ios/example/Images.xcassets/Contents.json New JSON structure for asset catalog metadata.
examples/RN.0.7x-cli/ios/example/Info.plist New plist file for application configuration.
examples/RN.0.7x-cli/ios/example/LaunchScreen.storyboard New storyboard file for launch screen layout.
examples/RN.0.7x-cli/ios/example/PrivacyInfo.xcprivacy New plist file for privacy-related configurations.
examples/RN.0.7x-cli/ios/example/main.m New entry point for the iOS application.
examples/RN.0.7x-cli/ios/exampleTests/Info.plist New plist file for test target configuration.
examples/RN.0.7x-cli/ios/exampleTests/exampleTests.m New unit test suite for the application.
examples/RN.0.7x-cli/jest.config.js New Jest configuration file for testing.
examples/RN.0.7x-cli/metro.config.js New Metro configuration file for bundling.
examples/RN.0.7x-cli/package.json New package.json file with project metadata, dependencies, and scripts.
examples/RN.0.7x-cli/tsconfig.json New TypeScript configuration file extending base settings.
index.d.ts Removed static method show() from SplashScreen class in module.
ios/Dynamic.swift Updated method signatures in Dynamic class to reflect new Lottie framework.
package.json Updated version, peer dependencies, and added new scripts for the project.

Poem

In the garden of code, we hop and play,
With new paths and scripts, we brighten the day.
Splash screens dancing, colors so bright,
With Yarn and Lottie, our app takes flight!
So gather 'round, friends, let’s cheer and rejoice,
For changes are blooming, let’s lift up our voice! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
🪧 Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , please review it.` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### CodeRabbit Configuration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
ashwini-ksingh commented 3 weeks ago

@attarchi

This seems to be an issue with the default zIndex given to App component, compared to the LottieAnimationView view added for splash.

I added animationView.reactZIndex = 1; in createAnimationView function, and it started working for me on 0.75.4 with new architecture and bridgeless enabled.

attarchi commented 3 weeks ago

@ashwini-ksingh
Thanks! Your solution worked perfectly.

Since the old architecture doesn’t support reactZIndex, I set animationUIView.layer.zPosition = 1 in AppDelegate.mm, and it resolved the issue.

@erie-e9
The example project has been updated and should work as expected. Also, you can also add animationUIView.layer.zPosition = 1 directly to your AppDelegate.mm file.

erie-e9 commented 3 weeks ago

Somebody else facing these errors on Android?

EDIT:

Solution enable next ones in gradle.properties: android.useAndroidX=true android.enableJetifier=true

Steps:

Error 1

Captura de pantalla 2024-10-31 a la(s) 5 05 46 p m

Error 2

Unresolved reference Lottie in MainActivity.kt

Captura de pantalla 2024-10-31 a la(s) 5 19 48 p m

I already tested Clear project and run rm -rf android/app/build android/app/.cxx android/build but error still happens.

attarchi commented 3 days ago

@erie-e9
I tested this with React Native 0.76.2 and encountered the same error. It seems this issue isn’t directly related to this package; version 0.76.x might still have some unresolved bugs. Here's how I resolved it:

  1. Yarn vs. npm
    I'm using yarn instead of npm, which might help avoid dependency issues.

  2. Gradle settings
    Make sure your gradle.properties file includes the following settings:

    android.useAndroidX=true
    android.enableJetifier=true
    newArchEnabled=false
  3. Fix for MainActivity.kt You might have missed adding this import to the header of your MainActivity.kt file:

import android.os.Bundle
  1. Ensure correct lottie-react-native version Verify that the lottie-react-native package is installed with the exact version 6.7.2:
yarn add lottie-react-native@6.7.2
  1. Please run your project with this command:
    yarn start --reset-cache

Let me know if these steps work for you!

erie-e9 commented 3 days ago

Thank you for your detailed answer. I edited my comment with fix for me, as we mentioned solution is enable those flags. Anyway, I'm using new arch, so for me is working fine without newArchEnabled=false