@onekeyfe/react-native-splash-screen 1.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +36 -0
  3. package/ReactNativeSplashScreen.podspec +30 -0
  4. package/android/CMakeLists.txt +24 -0
  5. package/android/build.gradle +130 -0
  6. package/android/gradle.properties +4 -0
  7. package/android/src/main/AndroidManifest.xml +1 -0
  8. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  9. package/android/src/main/java/com/margelo/nitro/reactnativesplashscreen/ReactNativeSplashScreen.kt +77 -0
  10. package/android/src/main/java/com/margelo/nitro/reactnativesplashscreen/ReactNativeSplashScreenPackage.kt +24 -0
  11. package/android/src/main/java/com/margelo/nitro/reactnativesplashscreen/SplashImageResizeMode.kt +23 -0
  12. package/android/src/main/java/com/margelo/nitro/reactnativesplashscreen/SplashScreenBridge.kt +108 -0
  13. package/android/src/main/java/com/margelo/nitro/reactnativesplashscreen/SplashScreenView.kt +34 -0
  14. package/android/src/main/java/com/margelo/nitro/reactnativesplashscreen/SplashViewController.kt +117 -0
  15. package/ios/ReactNativeSplashScreen.swift +15 -0
  16. package/lib/module/ReactNativeSplashScreen.nitro.js +4 -0
  17. package/lib/module/ReactNativeSplashScreen.nitro.js.map +1 -0
  18. package/lib/module/index.js +6 -0
  19. package/lib/module/index.js.map +1 -0
  20. package/lib/module/package.json +1 -0
  21. package/lib/typescript/package.json +1 -0
  22. package/lib/typescript/src/ReactNativeSplashScreen.nitro.d.ts +9 -0
  23. package/lib/typescript/src/ReactNativeSplashScreen.nitro.d.ts.map +1 -0
  24. package/lib/typescript/src/index.d.ts +4 -0
  25. package/lib/typescript/src/index.d.ts.map +1 -0
  26. package/nitro.json +17 -0
  27. package/nitrogen/generated/android/c++/JHybridReactNativeSplashScreenSpec.cpp +80 -0
  28. package/nitrogen/generated/android/c++/JHybridReactNativeSplashScreenSpec.hpp +66 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativesplashscreen/HybridReactNativeSplashScreenSpec.kt +62 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativesplashscreen/reactnativesplashscreenOnLoad.kt +35 -0
  31. package/nitrogen/generated/android/reactnativesplashscreen+autolinking.cmake +81 -0
  32. package/nitrogen/generated/android/reactnativesplashscreen+autolinking.gradle +27 -0
  33. package/nitrogen/generated/android/reactnativesplashscreenOnLoad.cpp +44 -0
  34. package/nitrogen/generated/android/reactnativesplashscreenOnLoad.hpp +25 -0
  35. package/nitrogen/generated/ios/ReactNativeSplashScreen+autolinking.rb +60 -0
  36. package/nitrogen/generated/ios/ReactNativeSplashScreen-Swift-Cxx-Bridge.cpp +49 -0
  37. package/nitrogen/generated/ios/ReactNativeSplashScreen-Swift-Cxx-Bridge.hpp +110 -0
  38. package/nitrogen/generated/ios/ReactNativeSplashScreen-Swift-Cxx-Umbrella.hpp +44 -0
  39. package/nitrogen/generated/ios/ReactNativeSplashScreenAutolinking.mm +33 -0
  40. package/nitrogen/generated/ios/ReactNativeSplashScreenAutolinking.swift +25 -0
  41. package/nitrogen/generated/ios/c++/HybridReactNativeSplashScreenSpecSwift.cpp +11 -0
  42. package/nitrogen/generated/ios/c++/HybridReactNativeSplashScreenSpecSwift.hpp +84 -0
  43. package/nitrogen/generated/ios/swift/Func_void_bool.swift +47 -0
  44. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
  45. package/nitrogen/generated/ios/swift/HybridReactNativeSplashScreenSpec.swift +57 -0
  46. package/nitrogen/generated/ios/swift/HybridReactNativeSplashScreenSpec_cxx.swift +157 -0
  47. package/nitrogen/generated/shared/c++/HybridReactNativeSplashScreenSpec.cpp +22 -0
  48. package/nitrogen/generated/shared/c++/HybridReactNativeSplashScreenSpec.hpp +63 -0
  49. package/package.json +169 -0
  50. package/src/ReactNativeSplashScreen.nitro.ts +7 -0
  51. package/src/index.tsx +8 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 OneKey
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # react-native-splash-screen
2
+
3
+ react-native-splash-screen
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install react-native-splash-screen react-native-nitro-modules
9
+
10
+ > `react-native-nitro-modules` is required as this library relies on [Nitro Modules](https://nitro.margelo.com/).
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```js
16
+ import { ReactNativeSplashScreen } from 'react-native-splash-screen';
17
+
18
+ // ...
19
+
20
+ const result = await ReactNativeSplashScreen.hello({ message: 'World' });
21
+ console.log(result); // { success: true, data: 'Hello, World!' }
22
+ ```
23
+
24
+ ## Contributing
25
+
26
+ - [Development workflow](CONTRIBUTING.md#development-workflow)
27
+ - [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
28
+ - [Code of conduct](CODE_OF_CONDUCT.md)
29
+
30
+ ## License
31
+
32
+ MIT
33
+
34
+ ---
35
+
36
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -0,0 +1,30 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "ReactNativeSplashScreen"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => min_ios_version_supported }
14
+ s.source = { :git => "https://github.com/OneKeyHQ/app-modules/react-native-splash-screen.git", :tag => "#{s.version}" }
15
+
16
+ s.source_files = [
17
+ "ios/**/*.{swift}",
18
+ "ios/**/*.{m,mm}",
19
+ "cpp/**/*.{hpp,cpp}",
20
+ ]
21
+
22
+ s.dependency 'React-jsi'
23
+ s.dependency 'React-callinvoker'
24
+ s.dependency 'ReactNativeNativeLogger'
25
+
26
+ load 'nitrogen/generated/ios/ReactNativeSplashScreen+autolinking.rb'
27
+ add_nitrogen_files(s)
28
+
29
+ install_modules_dependencies(s)
30
+ end
@@ -0,0 +1,24 @@
1
+ project(reactnativesplashscreen)
2
+ cmake_minimum_required(VERSION 3.9.0)
3
+
4
+ set(PACKAGE_NAME reactnativesplashscreen)
5
+ set(CMAKE_VERBOSE_MAKEFILE ON)
6
+ set(CMAKE_CXX_STANDARD 20)
7
+
8
+ # Define C++ library and add all sources
9
+ add_library(${PACKAGE_NAME} SHARED src/main/cpp/cpp-adapter.cpp)
10
+
11
+ # Add Nitrogen specs :)
12
+ include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/reactnativesplashscreen+autolinking.cmake)
13
+
14
+ # Set up local includes
15
+ include_directories("src/main/cpp" "../cpp")
16
+
17
+ find_library(LOG_LIB log)
18
+
19
+ # Link all libraries together
20
+ target_link_libraries(
21
+ ${PACKAGE_NAME}
22
+ ${LOG_LIB}
23
+ android # <-- Android core
24
+ )
@@ -0,0 +1,130 @@
1
+ buildscript {
2
+ ext.getExtOrDefault = {name ->
3
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ReactNativeSplashScreen_' + name]
4
+ }
5
+
6
+ repositories {
7
+ google()
8
+ mavenCentral()
9
+ }
10
+
11
+ dependencies {
12
+ classpath "com.android.tools.build:gradle:8.7.2"
13
+ // noinspection DifferentKotlinGradleVersion
14
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
15
+ }
16
+ }
17
+
18
+ def reactNativeArchitectures() {
19
+ def value = rootProject.getProperties().get("reactNativeArchitectures")
20
+ return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
21
+ }
22
+
23
+ apply plugin: "com.android.library"
24
+ apply plugin: "kotlin-android"
25
+ apply from: '../nitrogen/generated/android/reactnativesplashscreen+autolinking.gradle'
26
+
27
+ apply plugin: "com.facebook.react"
28
+
29
+ def getExtOrIntegerDefault(name) {
30
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["ReactNativeSplashScreen_" + name]).toInteger()
31
+ }
32
+
33
+ android {
34
+ namespace "com.margelo.nitro.reactnativesplashscreen"
35
+
36
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
37
+
38
+ defaultConfig {
39
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
40
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
41
+
42
+ externalNativeBuild {
43
+ cmake {
44
+ cppFlags "-frtti -fexceptions -Wall -fstack-protector-all"
45
+ arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
46
+ abiFilters (*reactNativeArchitectures())
47
+
48
+ buildTypes {
49
+ debug {
50
+ cppFlags "-O1 -g"
51
+ }
52
+ release {
53
+ cppFlags "-O2"
54
+ }
55
+ }
56
+ }
57
+ }
58
+ }
59
+
60
+ externalNativeBuild {
61
+ cmake {
62
+ path "CMakeLists.txt"
63
+ }
64
+ }
65
+
66
+ packagingOptions {
67
+ excludes = [
68
+ "META-INF",
69
+ "META-INF/**",
70
+ "**/libc++_shared.so",
71
+ "**/libfbjni.so",
72
+ "**/libjsi.so",
73
+ "**/libfolly_json.so",
74
+ "**/libfolly_runtime.so",
75
+ "**/libglog.so",
76
+ "**/libhermes.so",
77
+ "**/libhermes-executor-debug.so",
78
+ "**/libhermes_executor.so",
79
+ "**/libreactnative.so",
80
+ "**/libreactnativejni.so",
81
+ "**/libturbomodulejsijni.so",
82
+ "**/libreact_nativemodule_core.so",
83
+ "**/libjscexecutor.so"
84
+ ]
85
+ }
86
+
87
+ buildFeatures {
88
+ buildConfig true
89
+ prefab true
90
+ }
91
+
92
+ buildTypes {
93
+ release {
94
+ minifyEnabled false
95
+ }
96
+ }
97
+
98
+ lintOptions {
99
+ disable "GradleCompatible"
100
+ }
101
+
102
+ compileOptions {
103
+ sourceCompatibility JavaVersion.VERSION_1_8
104
+ targetCompatibility JavaVersion.VERSION_1_8
105
+ }
106
+
107
+ sourceSets {
108
+ main {
109
+ java.srcDirs += [
110
+ "generated/java",
111
+ "generated/jni"
112
+ ]
113
+ }
114
+ }
115
+ }
116
+
117
+ repositories {
118
+ mavenCentral()
119
+ google()
120
+ }
121
+
122
+ def kotlin_version = getExtOrDefault("kotlinVersion")
123
+
124
+ dependencies {
125
+ implementation "com.facebook.react:react-android"
126
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
127
+ implementation project(":react-native-nitro-modules")
128
+
129
+ implementation project(":onekeyfe_react-native-native-logger")
130
+ }
@@ -0,0 +1,4 @@
1
+ ReactNativeSplashScreen_kotlinVersion=1.9.25
2
+ ReactNativeSplashScreen_compileSdkVersion=35
3
+ ReactNativeSplashScreen_targetSdkVersion=35
4
+ ReactNativeSplashScreen_minSdkVersion=24
@@ -0,0 +1 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" />
@@ -0,0 +1,6 @@
1
+ #include <jni.h>
2
+ #include "reactnativesplashscreenOnLoad.hpp"
3
+
4
+ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
5
+ return margelo::nitro::reactnativesplashscreen::initialize(vm);
6
+ }
@@ -0,0 +1,77 @@
1
+ package com.margelo.nitro.reactnativesplashscreen
2
+
3
+ import android.os.Build
4
+ import com.facebook.proguard.annotations.DoNotStrip
5
+ import com.margelo.nitro.NitroModules
6
+ import com.margelo.nitro.core.Promise
7
+ import com.margelo.nitro.nativelogger.OneKeyLog
8
+ import java.util.concurrent.CountDownLatch
9
+ import java.util.concurrent.TimeUnit
10
+
11
+ /**
12
+ * Splash screen module for Android compatibility.
13
+ *
14
+ * - API >= 31 (Android 12+): The system AndroidX SplashScreen API handles the splash screen
15
+ * natively in MainActivity. Both methods are no-ops and return true immediately.
16
+ *
17
+ * - API < 31 (Android < 12): The system has no built-in splash screen API.
18
+ * MainActivity calls [SplashScreenBridge.show] during onCreate to display a view overlay
19
+ * matching the app's splash drawable. This module then delegates:
20
+ * - [preventAutoHideAsync] → [SplashScreenBridge.preventAutoHide] to keep the overlay visible
21
+ * until JS explicitly hides it.
22
+ * - [hideAsync] → [SplashScreenBridge.hide] to remove the overlay.
23
+ *
24
+ * iOS: expo-splash-screen via the launch storyboard handles everything. The iOS implementation
25
+ * in ReactNativeSplashScreen.swift is intentionally empty.
26
+ */
27
+ @DoNotStrip
28
+ class ReactNativeSplashScreen : HybridReactNativeSplashScreenSpec() {
29
+
30
+ override fun preventAutoHideAsync(): Promise<Boolean> {
31
+ return Promise.async {
32
+ OneKeyLog.info("SplashScreen", "preventAutoHideAsync OS_VERSION=${Build.VERSION.SDK_INT}")
33
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
34
+ // API 31+: AndroidX SplashScreen handles it in MainActivity
35
+ return@async true
36
+ }
37
+ val activity = NitroModules.applicationContext?.currentActivity
38
+ if (activity == null) {
39
+ OneKeyLog.warn("SplashScreen", "preventAutoHideAsync: no current activity")
40
+ return@async false
41
+ }
42
+ SplashScreenBridge.preventAutoHide(activity)
43
+ true
44
+ }
45
+ }
46
+
47
+ override fun hideAsync(): Promise<Boolean> {
48
+ return Promise.async {
49
+ OneKeyLog.info("SplashScreen", "hideAsync OS_VERSION=${Build.VERSION.SDK_INT}")
50
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
51
+ // API 31+: AndroidX SplashScreen handles it
52
+ return@async true
53
+ }
54
+ val activity = NitroModules.applicationContext?.currentActivity
55
+ if (activity == null) {
56
+ OneKeyLog.warn("SplashScreen", "hideAsync: no current activity")
57
+ return@async false
58
+ }
59
+ val latch = CountDownLatch(1)
60
+ var result = false
61
+ SplashScreenBridge.hide(
62
+ activity,
63
+ onSuccess = { hasEffect ->
64
+ result = hasEffect
65
+ latch.countDown()
66
+ },
67
+ onFailure = { reason ->
68
+ OneKeyLog.warn("SplashScreen", "hideAsync failed: $reason")
69
+ result = false
70
+ latch.countDown()
71
+ }
72
+ )
73
+ latch.await(5, TimeUnit.SECONDS)
74
+ result
75
+ }
76
+ }
77
+ }
@@ -0,0 +1,24 @@
1
+ package com.margelo.nitro.reactnativesplashscreen
2
+
3
+ import com.facebook.react.BaseReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.module.model.ReactModuleInfoProvider
7
+
8
+ class ReactNativeSplashScreenPackage : BaseReactPackage() {
9
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
10
+ return null
11
+ }
12
+
13
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
14
+ return ReactModuleInfoProvider { HashMap() }
15
+ }
16
+
17
+ companion object {
18
+ init {
19
+ System.loadLibrary("reactnativesplashscreen")
20
+ }
21
+ }
22
+ }
23
+
24
+
@@ -0,0 +1,23 @@
1
+ package com.margelo.nitro.reactnativesplashscreen
2
+
3
+ import android.widget.ImageView
4
+
5
+ internal enum class SplashImageResizeMode(
6
+ val scaleType: ImageView.ScaleType,
7
+ val value: String
8
+ ) {
9
+ CONTAIN(ImageView.ScaleType.FIT_CENTER, "contain"),
10
+ COVER(ImageView.ScaleType.CENTER_CROP, "cover"),
11
+ NATIVE(ImageView.ScaleType.CENTER, "native");
12
+
13
+ companion object {
14
+ fun fromString(value: String?): SplashImageResizeMode {
15
+ if (value != null) {
16
+ for (mode in values()) {
17
+ if (mode.value == value) return mode
18
+ }
19
+ }
20
+ return CONTAIN
21
+ }
22
+ }
23
+ }
@@ -0,0 +1,108 @@
1
+ package com.margelo.nitro.reactnativesplashscreen
2
+
3
+ import android.app.Activity
4
+ import androidx.core.content.ContextCompat
5
+ import com.margelo.nitro.nativelogger.OneKeyLog
6
+ import java.util.WeakHashMap
7
+
8
+ /**
9
+ * Static bridge called by the host app's MainActivity to show/manage the splash screen.
10
+ *
11
+ * Usage in MainActivity.onCreate() (for API < 31 only):
12
+ * SplashScreenBridge.show(this)
13
+ */
14
+ object SplashScreenBridge {
15
+ private const val TAG = "SplashScreen"
16
+
17
+ private val controllers = WeakHashMap<Activity, SplashViewController>()
18
+
19
+ @Volatile
20
+ var isAlreadyHidden = false
21
+
22
+ /**
23
+ * Show the splash screen overlay. Call this from MainActivity.onCreate()
24
+ * for API < Build.VERSION_CODES.S (API 31).
25
+ */
26
+ @JvmStatic
27
+ fun show(activity: Activity) {
28
+ if (isAlreadyHidden) return
29
+ if (controllers.containsKey(activity)) {
30
+ OneKeyLog.warn(TAG, "show: already shown for this activity")
31
+ return
32
+ }
33
+ val splashView = createSplashView(activity) ?: run {
34
+ OneKeyLog.warn(TAG, "show: failed to create splash view")
35
+ return
36
+ }
37
+ val controller = SplashViewController(activity, splashView)
38
+ controllers[activity] = controller
39
+ controller.show()
40
+ OneKeyLog.info(TAG, "show: started for activity")
41
+ }
42
+
43
+ @JvmStatic
44
+ fun preventAutoHide(activity: Activity) {
45
+ val controller = controllers[activity]
46
+ if (controller == null) {
47
+ OneKeyLog.warn(TAG, "preventAutoHide: no controller for activity")
48
+ return
49
+ }
50
+ controller.preventAutoHide()
51
+ }
52
+
53
+ @JvmStatic
54
+ fun hide(
55
+ activity: Activity,
56
+ onSuccess: ((Boolean) -> Unit)?,
57
+ onFailure: ((String) -> Unit)?
58
+ ) {
59
+ isAlreadyHidden = true
60
+ val controller = controllers[activity]
61
+ if (controller == null) {
62
+ OneKeyLog.warn(TAG, "hide: no controller for activity")
63
+ onFailure?.invoke("No splash screen registered for this activity")
64
+ return
65
+ }
66
+ controller.hide(onSuccess, onFailure)
67
+ }
68
+
69
+ private fun createSplashView(activity: Activity): android.view.View? {
70
+ return try {
71
+ val context = activity
72
+
73
+ // Read resize mode from app string resource (convention: "expo_splash_screen_resize_mode")
74
+ val resizeModeStr = try {
75
+ val id = context.resources.getIdentifier(
76
+ "expo_splash_screen_resize_mode", "string", context.packageName
77
+ )
78
+ if (id != 0) context.getString(id).lowercase() else "contain"
79
+ } catch (e: Exception) { "contain" }
80
+
81
+ val resizeMode = SplashImageResizeMode.fromString(resizeModeStr)
82
+
83
+ // For NATIVE mode use "splashscreen", otherwise use "splashscreen_image"
84
+ val drawableName = if (resizeMode == SplashImageResizeMode.NATIVE) "splashscreen" else "splashscreen_image"
85
+ val imageResId = context.resources.getIdentifier(drawableName, "drawable", context.packageName)
86
+ val bgColorId = context.resources.getIdentifier(
87
+ "splashscreen_background", "color", context.packageName
88
+ )
89
+
90
+ OneKeyLog.info(TAG, "createSplashView: resizeMode=$resizeModeStr drawable=$drawableName imageResId=$imageResId")
91
+
92
+ val view = SplashScreenView(context)
93
+ if (bgColorId != 0) {
94
+ view.setBackgroundColor(ContextCompat.getColor(context, bgColorId))
95
+ } else {
96
+ view.setBackgroundColor(android.graphics.Color.WHITE)
97
+ }
98
+ if (imageResId != 0) {
99
+ view.imageView.setImageResource(imageResId)
100
+ }
101
+ view.configureResizeMode(resizeMode)
102
+ view
103
+ } catch (e: Exception) {
104
+ OneKeyLog.error(TAG, "createSplashView failed: ${e.message}")
105
+ null
106
+ }
107
+ }
108
+ }
@@ -0,0 +1,34 @@
1
+ package com.margelo.nitro.reactnativesplashscreen
2
+
3
+ import android.annotation.SuppressLint
4
+ import android.content.Context
5
+ import android.view.ViewGroup
6
+ import android.widget.ImageView
7
+ import android.widget.RelativeLayout
8
+
9
+ @SuppressLint("ViewConstructor")
10
+ internal class SplashScreenView(context: Context) : RelativeLayout(context) {
11
+
12
+ val imageView: ImageView = ImageView(context).also { iv ->
13
+ iv.layoutParams = LayoutParams(
14
+ LayoutParams.MATCH_PARENT,
15
+ LayoutParams.MATCH_PARENT
16
+ )
17
+ addView(iv)
18
+ }
19
+
20
+ init {
21
+ layoutParams = ViewGroup.LayoutParams(
22
+ ViewGroup.LayoutParams.MATCH_PARENT,
23
+ ViewGroup.LayoutParams.MATCH_PARENT
24
+ )
25
+ }
26
+
27
+ fun configureResizeMode(resizeMode: SplashImageResizeMode) {
28
+ imageView.scaleType = resizeMode.scaleType
29
+ when (resizeMode) {
30
+ SplashImageResizeMode.CONTAIN -> imageView.adjustViewBounds = true
31
+ else -> imageView.adjustViewBounds = false
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,117 @@
1
+ package com.margelo.nitro.reactnativesplashscreen
2
+
3
+ import android.app.Activity
4
+ import android.os.Handler
5
+ import android.os.Looper
6
+ import android.view.View
7
+ import android.view.ViewGroup
8
+ import com.margelo.nitro.nativelogger.OneKeyLog
9
+ import java.lang.ref.WeakReference
10
+
11
+ internal class SplashViewController(
12
+ activity: Activity,
13
+ private val splashView: View
14
+ ) {
15
+ private companion object {
16
+ private const val TAG = "SplashScreen"
17
+ private const val SEARCH_INTERVAL_MS = 20L
18
+
19
+ // Look up ReactRootView class at runtime to avoid compile-time dependency
20
+ private val reactRootViewClass: Class<*>? by lazy {
21
+ try {
22
+ Class.forName("com.facebook.react.ReactRootView")
23
+ } catch (e: ClassNotFoundException) {
24
+ null
25
+ }
26
+ }
27
+ }
28
+
29
+ private val weakActivity = WeakReference(activity)
30
+ private val contentView: ViewGroup = activity.findViewById(android.R.id.content)
31
+ private val handler = Handler(Looper.getMainLooper())
32
+
33
+ private var autoHideEnabled = true
34
+ private var splashShown = false
35
+
36
+ fun show() {
37
+ val activity = weakActivity.get() ?: return
38
+ activity.runOnUiThread {
39
+ val parent = splashView.parent as? ViewGroup
40
+ parent?.removeView(splashView)
41
+ contentView.addView(splashView)
42
+ splashShown = true
43
+ OneKeyLog.info(TAG, "splash view added to content")
44
+ searchForRootView()
45
+ }
46
+ }
47
+
48
+ fun preventAutoHide() {
49
+ autoHideEnabled = false
50
+ OneKeyLog.info(TAG, "autoHide disabled")
51
+ }
52
+
53
+ fun hide(
54
+ onSuccess: ((Boolean) -> Unit)?,
55
+ onFailure: ((String) -> Unit)?
56
+ ) {
57
+ if (!splashShown) {
58
+ OneKeyLog.info(TAG, "hide: splash not shown, skipping")
59
+ onSuccess?.invoke(false)
60
+ return
61
+ }
62
+ val activity = weakActivity.get()
63
+ if (activity == null || activity.isFinishing || activity.isDestroyed) {
64
+ onFailure?.invoke("Activity is already destroyed")
65
+ return
66
+ }
67
+ Handler(activity.mainLooper).post {
68
+ contentView.removeView(splashView)
69
+ autoHideEnabled = true
70
+ splashShown = false
71
+ OneKeyLog.info(TAG, "splash view removed")
72
+ onSuccess?.invoke(true)
73
+ }
74
+ }
75
+
76
+ private fun searchForRootView() {
77
+ val found = findRootView(contentView)
78
+ if (found != null) {
79
+ handleRootView(found)
80
+ return
81
+ }
82
+ handler.postDelayed(::searchForRootView, SEARCH_INTERVAL_MS)
83
+ }
84
+
85
+ private fun findRootView(view: View): ViewGroup? {
86
+ val cls = reactRootViewClass
87
+ if (cls != null && cls.isInstance(view)) {
88
+ return view as? ViewGroup
89
+ }
90
+ if (view !== splashView && view is ViewGroup) {
91
+ for (i in 0 until view.childCount) {
92
+ val found = findRootView(view.getChildAt(i))
93
+ if (found != null) return found
94
+ }
95
+ }
96
+ return null
97
+ }
98
+
99
+ private fun handleRootView(rootView: ViewGroup) {
100
+ if (rootView.childCount > 0 && autoHideEnabled) {
101
+ hide(null, null)
102
+ }
103
+ rootView.setOnHierarchyChangeListener(object : ViewGroup.OnHierarchyChangeListener {
104
+ override fun onChildViewAdded(parent: View, child: View) {
105
+ if (rootView.childCount == 1 && autoHideEnabled) {
106
+ hide(null, null)
107
+ }
108
+ }
109
+
110
+ override fun onChildViewRemoved(parent: View, child: View) {
111
+ if (rootView.childCount == 0) {
112
+ show()
113
+ }
114
+ }
115
+ })
116
+ }
117
+ }
@@ -0,0 +1,15 @@
1
+ import NitroModules
2
+
3
+ // iOS splash screen is managed by expo-splash-screen via the launch storyboard.
4
+ // This module exists solely to provide Android < API 31 compatibility (see SplashScreenBridge.kt).
5
+ // On iOS, both methods are intentional no-ops.
6
+ class ReactNativeSplashScreen: HybridReactNativeSplashScreenSpec {
7
+
8
+ func preventAutoHideAsync() throws -> Promise<Bool> {
9
+ return Promise.resolved(withResult: true)
10
+ }
11
+
12
+ func hideAsync() throws -> Promise<Bool> {
13
+ return Promise.resolved(withResult: true)
14
+ }
15
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export {};
4
+ //# sourceMappingURL=ReactNativeSplashScreen.nitro.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["ReactNativeSplashScreen.nitro.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ import { NitroModules } from 'react-native-nitro-modules';
4
+ const ReactNativeSplashScreenHybridObject = NitroModules.createHybridObject('ReactNativeSplashScreen');
5
+ export const ReactNativeSplashScreen = ReactNativeSplashScreenHybridObject;
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NitroModules","ReactNativeSplashScreenHybridObject","createHybridObject","ReactNativeSplashScreen"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAGzD,MAAMC,mCAAmC,GACvCD,YAAY,CAACE,kBAAkB,CAA8B,yBAAyB,CAAC;AAEzF,OAAO,MAAMC,uBAAuB,GAAGF,mCAAmC","ignoreList":[]}