react-native-bootsplash 6.1.4 → 6.2.0-rc.0

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 (43) hide show
  1. package/README.md +1 -0
  2. package/android/build.gradle +6 -4
  3. package/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.kt +13 -0
  4. package/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashDialog.kt +79 -0
  5. package/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModuleImpl.kt +242 -0
  6. package/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashPackage.kt +37 -0
  7. package/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashQueue.kt +26 -0
  8. package/android/src/main/res/values/colors.xml +8 -0
  9. package/android/src/main/res/values/styles.xml +13 -13
  10. package/android/src/main/res/values-night/styles.xml +1 -1
  11. package/android/src/main/res/values-v23/styles.xml +2 -2
  12. package/android/src/main/res/values-v29/styles.xml +1 -1
  13. package/android/src/main/res/values-v31/styles.xml +1 -1
  14. package/android/src/newarch/com/zoontek/rnbootsplash/RNBootSplashModule.kt +39 -0
  15. package/android/src/oldarch/com/zoontek/rnbootsplash/RNBootSplashModule.kt +43 -0
  16. package/dist/commonjs/addon/index.js +31 -31
  17. package/dist/commonjs/expo.js +1 -0
  18. package/dist/commonjs/expo.js.map +1 -1
  19. package/dist/commonjs/generate.js +14 -11
  20. package/dist/commonjs/generate.js.map +1 -1
  21. package/dist/commonjs/index.js +13 -4
  22. package/dist/commonjs/index.js.map +1 -1
  23. package/dist/module/addon/index.js +31 -31
  24. package/dist/module/expo.js +1 -0
  25. package/dist/module/expo.js.map +1 -1
  26. package/dist/module/generate.js +14 -11
  27. package/dist/module/generate.js.map +1 -1
  28. package/dist/module/index.js +13 -4
  29. package/dist/module/index.js.map +1 -1
  30. package/dist/typescript/expo.d.ts.map +1 -1
  31. package/dist/typescript/generate.d.ts.map +1 -1
  32. package/dist/typescript/index.d.ts.map +1 -1
  33. package/package.json +7 -6
  34. package/src/expo.ts +1 -0
  35. package/src/generate.ts +22 -17
  36. package/src/index.ts +25 -6
  37. package/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java +0 -13
  38. package/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashDialog.java +0 -119
  39. package/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModuleImpl.java +0 -306
  40. package/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashPackage.java +0 -46
  41. package/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashQueue.java +0 -31
  42. package/android/src/newarch/com/zoontek/rnbootsplash/RNBootSplashModule.java +0 -51
  43. package/android/src/oldarch/com/zoontek/rnbootsplash/RNBootSplashModule.java +0 -55
@@ -1,119 +0,0 @@
1
- package com.zoontek.rnbootsplash;
2
-
3
- import android.app.Activity;
4
- import android.app.Dialog;
5
- import android.content.DialogInterface;
6
- import android.os.Bundle;
7
- import android.view.Window;
8
- import android.view.WindowManager;
9
-
10
- import androidx.annotation.NonNull;
11
- import androidx.annotation.StyleRes;
12
-
13
- public class RNBootSplashDialog extends Dialog {
14
-
15
- private final boolean mFade;
16
-
17
- public RNBootSplashDialog(@NonNull Activity activity, @StyleRes int themeResId, boolean fade) {
18
- super(activity, themeResId);
19
-
20
- mFade = fade;
21
-
22
- setOwnerActivity(activity);
23
- setCancelable(false);
24
- setCanceledOnTouchOutside(false);
25
- }
26
-
27
- @Override
28
- public void onBackPressed() {
29
- Activity activity = getOwnerActivity();
30
-
31
- if (activity != null) {
32
- activity.moveTaskToBack(true);
33
- }
34
- }
35
-
36
- @Override
37
- public void dismiss() {
38
- if (!isShowing()) {
39
- return;
40
- }
41
-
42
- try {
43
- super.dismiss();
44
- } catch (Exception ignored) {}
45
- }
46
-
47
- public void dismiss(@NonNull final Runnable callback) {
48
- if (!isShowing()) {
49
- callback.run();
50
- return;
51
- }
52
-
53
- setOnDismissListener(new OnDismissListener() {
54
- @Override
55
- public void onDismiss(DialogInterface dialog) {
56
- callback.run();
57
- }
58
- });
59
-
60
- try {
61
- super.dismiss();
62
- } catch (Exception ignored) {
63
- callback.run();
64
- }
65
- }
66
-
67
- @Override
68
- public void show() {
69
- if (isShowing()) {
70
- return;
71
- }
72
-
73
- try {
74
- super.show();
75
- } catch (Exception ignored) {}
76
- }
77
-
78
- public void show(@NonNull final Runnable callback) {
79
- if (isShowing()) {
80
- callback.run();
81
- return;
82
- }
83
-
84
- setOnShowListener(new DialogInterface.OnShowListener() {
85
- @Override
86
- public void onShow(DialogInterface dialog) {
87
- callback.run();
88
- }
89
- });
90
-
91
- try {
92
- super.show();
93
- } catch (Exception ignored) {
94
- callback.run();
95
- }
96
- }
97
-
98
- @Override
99
- protected void onCreate(Bundle savedInstanceState) {
100
- final Window window = getWindow();
101
-
102
- if (window != null) {
103
- window.setLayout(
104
- WindowManager.LayoutParams.MATCH_PARENT,
105
- WindowManager.LayoutParams.MATCH_PARENT
106
- );
107
-
108
- window.setWindowAnimations(mFade
109
- ? R.style.BootSplashFadeOutAnimation
110
- : R.style.BootSplashNoAnimation);
111
-
112
- if (RNBootSplashModuleImpl.isSamsungOneUI4()) {
113
- window.setBackgroundDrawableResource(R.drawable.compat_splash_screen_oneui_4);
114
- }
115
- }
116
-
117
- super.onCreate(savedInstanceState);
118
- }
119
- }
@@ -1,306 +0,0 @@
1
- package com.zoontek.rnbootsplash;
2
-
3
- import android.annotation.SuppressLint;
4
- import android.app.Activity;
5
- import android.content.res.Configuration;
6
- import android.content.res.Resources;
7
- import android.os.Build;
8
- import android.util.TypedValue;
9
- import android.view.View;
10
- import android.view.ViewConfiguration;
11
- import android.view.ViewTreeObserver;
12
- import android.window.SplashScreen;
13
- import android.window.SplashScreenView;
14
-
15
- import androidx.annotation.NonNull;
16
- import androidx.annotation.Nullable;
17
- import androidx.annotation.StyleRes;
18
-
19
- import com.facebook.common.logging.FLog;
20
- import com.facebook.react.bridge.Promise;
21
- import com.facebook.react.bridge.ReactApplicationContext;
22
- import com.facebook.react.bridge.UiThreadUtil;
23
- import com.facebook.react.common.ReactConstants;
24
- import com.facebook.react.uimanager.PixelUtil;
25
-
26
- import java.lang.reflect.Field;
27
- import java.util.HashMap;
28
- import java.util.Map;
29
- import java.util.Timer;
30
- import java.util.TimerTask;
31
-
32
- public class RNBootSplashModuleImpl {
33
-
34
- public static final String NAME = "RNBootSplash";
35
-
36
- private static final RNBootSplashQueue<Promise> mPromiseQueue = new RNBootSplashQueue<>();
37
-
38
- private enum Status {
39
- HIDDEN,
40
- HIDING,
41
- INITIALIZING,
42
- VISIBLE,
43
- }
44
-
45
- @NonNull
46
- private static Status mStatus = Status.HIDDEN;
47
-
48
- @StyleRes
49
- private static int mThemeResId = -1;
50
-
51
- @Nullable
52
- private static RNBootSplashDialog mInitialDialog = null;
53
- @Nullable
54
- private static RNBootSplashDialog mFadeOutDialog = null;
55
-
56
- protected static void init(
57
- @Nullable final Activity activity,
58
- @StyleRes int themeResId
59
- ) {
60
- if (mThemeResId != -1) {
61
- FLog.w(ReactConstants.TAG, NAME + ": Ignored initialization, module is already initialized.");
62
- return;
63
- }
64
-
65
- mThemeResId = themeResId;
66
-
67
- if (activity == null) {
68
- FLog.w(ReactConstants.TAG, NAME + ": Ignored initialization, current activity is null.");
69
- return;
70
- }
71
-
72
- // Apply postBootSplashTheme
73
- TypedValue typedValue = new TypedValue();
74
- Resources.Theme currentTheme = activity.getTheme();
75
-
76
- if (currentTheme
77
- .resolveAttribute(R.attr.postBootSplashTheme, typedValue, true)) {
78
- int finalThemeId = typedValue.resourceId;
79
-
80
- if (finalThemeId != 0) {
81
- activity.setTheme(finalThemeId);
82
- }
83
- }
84
-
85
- // Keep the splash screen on-screen until Dialog is shown
86
- final View contentView = activity.findViewById(android.R.id.content);
87
- mStatus = Status.INITIALIZING;
88
-
89
- contentView
90
- .getViewTreeObserver()
91
- .addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
92
- @Override
93
- public boolean onPreDraw() {
94
- if (mStatus == Status.INITIALIZING) {
95
- return false;
96
- }
97
-
98
- contentView
99
- .getViewTreeObserver()
100
- .removeOnPreDrawListener(this);
101
-
102
- return true;
103
- }
104
- });
105
-
106
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
107
- // This is not called on Android 12 when activity is started using intent
108
- // (Android studio / CLI / notification / widget…)
109
- SplashScreen.OnExitAnimationListener listener = new SplashScreen.OnExitAnimationListener() {
110
- @Override
111
- public void onSplashScreenExit(@NonNull SplashScreenView view) {
112
- view.remove(); // Remove it immediately, without animation
113
-
114
- activity
115
- .getSplashScreen()
116
- .clearOnExitAnimationListener();
117
- }
118
- };
119
-
120
- activity
121
- .getSplashScreen()
122
- .setOnExitAnimationListener(listener);
123
- }
124
-
125
- mInitialDialog = new RNBootSplashDialog(activity, mThemeResId, false);
126
-
127
- UiThreadUtil.runOnUiThread(new Runnable() {
128
- @Override
129
- public void run() {
130
- mInitialDialog.show(new Runnable() {
131
- @Override
132
- public void run() {
133
- mStatus = Status.VISIBLE;
134
- }
135
- });
136
- }
137
- });
138
- }
139
-
140
- private static void clearPromiseQueue() {
141
- while (!mPromiseQueue.isEmpty()) {
142
- Promise promise = mPromiseQueue.shift();
143
-
144
- if (promise != null) {
145
- promise.resolve(true);
146
- }
147
- }
148
- }
149
-
150
- private static @NonNull Runnable getHideSequenceRunnable() {
151
- final Runnable fadeOutDialogDismiss = new Runnable() {
152
- @Override
153
- public void run() {
154
- mFadeOutDialog = null;
155
- mStatus = Status.HIDDEN;
156
- clearPromiseQueue();
157
- }
158
- };
159
-
160
- final Runnable initialDialogDismiss = new Runnable() {
161
- @Override
162
- public void run() {
163
- mInitialDialog = null;
164
-
165
- if (mFadeOutDialog != null) {
166
- mFadeOutDialog.dismiss(fadeOutDialogDismiss);
167
- } else {
168
- fadeOutDialogDismiss.run();
169
- }
170
- }
171
- };
172
-
173
- return new Runnable() {
174
- @Override
175
- public void run() {
176
- if (mInitialDialog != null) {
177
- mInitialDialog.dismiss(initialDialogDismiss);
178
- } else {
179
- initialDialogDismiss.run();
180
- }
181
- }
182
- };
183
- }
184
-
185
- private static void hideAndClearPromiseQueue(
186
- final ReactApplicationContext reactContext,
187
- final boolean fade
188
- ) {
189
- UiThreadUtil.runOnUiThread(new Runnable() {
190
- @Override
191
- public void run() {
192
- final Activity activity = reactContext.getCurrentActivity();
193
-
194
- if (mStatus == Status.INITIALIZING
195
- || activity == null
196
- || activity.isFinishing()
197
- || activity.isDestroyed()
198
- ) {
199
- final Timer timer = new Timer();
200
-
201
- timer.schedule(new TimerTask() {
202
- @Override
203
- public void run() {
204
- timer.cancel();
205
- hideAndClearPromiseQueue(reactContext, fade);
206
- }
207
- }, 100);
208
-
209
- return;
210
- }
211
-
212
- if (mStatus == Status.HIDING) {
213
- return; // wait until fade out end for clearPromiseQueue
214
- }
215
-
216
- if (mStatus == Status.HIDDEN) {
217
- clearPromiseQueue();
218
- return; // both initial and fade out dialog are hidden
219
- }
220
-
221
- mStatus = Status.HIDING;
222
-
223
- if (fade) {
224
- // Create a new Dialog instance with fade out animation
225
- mFadeOutDialog = new RNBootSplashDialog(activity, mThemeResId, true);
226
- mFadeOutDialog.show(getHideSequenceRunnable());
227
- } else if (mInitialDialog != null) {
228
- mInitialDialog.dismiss(getHideSequenceRunnable());
229
- } else {
230
- getHideSequenceRunnable().run();
231
- }
232
- }
233
- });
234
- }
235
-
236
- // From https://stackoverflow.com/a/61062773
237
- public static boolean isSamsungOneUI4() {
238
- String name = "SEM_PLATFORM_INT";
239
-
240
- try {
241
- Field field = Build.VERSION.class.getDeclaredField(name);
242
- int version = (field.getInt(null) - 90000) / 10000;
243
- return version == 4;
244
- } catch (Exception ignored) {
245
- return false;
246
- }
247
- }
248
-
249
- protected static void onHostDestroy() {
250
- mStatus = Status.HIDDEN;
251
- mThemeResId = -1;
252
- clearPromiseQueue();
253
-
254
- if (mInitialDialog != null) {
255
- mInitialDialog.dismiss();
256
- mInitialDialog = null;
257
- }
258
- if (mFadeOutDialog != null) {
259
- mFadeOutDialog.dismiss();
260
- mFadeOutDialog = null;
261
- }
262
- }
263
-
264
- public static Map<String, Object> getConstants(final ReactApplicationContext reactContext) {
265
- final Resources resources = reactContext.getResources();
266
- HashMap<String, Object> constants = new HashMap<>();
267
-
268
- int uiMode =
269
- reactContext.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
270
-
271
- @SuppressLint({"InternalInsetResource", "DiscouragedApi"}) final int statusBarHeightResId =
272
- resources.getIdentifier("status_bar_height", "dimen", "android");
273
-
274
- @SuppressLint({"InternalInsetResource", "DiscouragedApi"}) final int navigationBarHeightResId =
275
- resources.getIdentifier("navigation_bar_height", "dimen", "android");
276
-
277
- float statusBarHeight = statusBarHeightResId > 0
278
- ? PixelUtil.toDIPFromPixel(resources.getDimensionPixelSize(statusBarHeightResId))
279
- : 0;
280
-
281
- float navigationBarHeight = navigationBarHeightResId > 0 &&
282
- !ViewConfiguration.get(reactContext).hasPermanentMenuKey()
283
- ? PixelUtil.toDIPFromPixel(resources.getDimensionPixelSize(navigationBarHeightResId))
284
- : 0;
285
-
286
- constants.put("darkModeEnabled", uiMode == Configuration.UI_MODE_NIGHT_YES);
287
- constants.put("logoSizeRatio", isSamsungOneUI4() ? 0.5 : 1);
288
- constants.put("navigationBarHeight", navigationBarHeight);
289
- constants.put("statusBarHeight", statusBarHeight);
290
-
291
- return constants;
292
- }
293
-
294
- public static void hide(
295
- final ReactApplicationContext reactContext,
296
- final boolean fade,
297
- final Promise promise
298
- ) {
299
- mPromiseQueue.push(promise);
300
- hideAndClearPromiseQueue(reactContext, fade);
301
- }
302
-
303
- public static void isVisible(final Promise promise) {
304
- promise.resolve(mStatus != Status.HIDDEN);
305
- }
306
- }
@@ -1,46 +0,0 @@
1
- package com.zoontek.rnbootsplash;
2
-
3
- import androidx.annotation.Nullable;
4
-
5
- import com.facebook.react.TurboReactPackage;
6
- import com.facebook.react.bridge.NativeModule;
7
- import com.facebook.react.bridge.ReactApplicationContext;
8
- import com.facebook.react.module.model.ReactModuleInfo;
9
- import com.facebook.react.module.model.ReactModuleInfoProvider;
10
-
11
- import java.util.HashMap;
12
- import java.util.Map;
13
-
14
- public class RNBootSplashPackage extends TurboReactPackage {
15
-
16
- @Nullable
17
- @Override
18
- public NativeModule getModule(String name, ReactApplicationContext reactContext) {
19
- if (name.equals(RNBootSplashModuleImpl.NAME)) {
20
- return new RNBootSplashModule(reactContext);
21
- } else {
22
- return null;
23
- }
24
- }
25
-
26
- @Override
27
- public ReactModuleInfoProvider getReactModuleInfoProvider() {
28
- return () -> {
29
- final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
30
- boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
31
-
32
- ReactModuleInfo moduleInfo = new ReactModuleInfo(
33
- RNBootSplashModuleImpl.NAME,
34
- RNBootSplashModuleImpl.NAME,
35
- false,
36
- false,
37
- true,
38
- false,
39
- isTurboModule
40
- );
41
-
42
- moduleInfos.put(RNBootSplashModuleImpl.NAME, moduleInfo);
43
- return moduleInfos;
44
- };
45
- }
46
- }
@@ -1,31 +0,0 @@
1
- package com.zoontek.rnbootsplash;
2
-
3
- import androidx.annotation.NonNull;
4
- import androidx.annotation.Nullable;
5
-
6
- import java.util.Vector;
7
-
8
- /**
9
- * Represents a first-in-first-out (FIFO) thread safe queue of objects.
10
- * Its source code is based on Java internal <code>Stack</code>.
11
- */
12
- public class RNBootSplashQueue<E> extends Vector<E> {
13
-
14
- public RNBootSplashQueue() {}
15
-
16
- @Nullable
17
- public synchronized E shift() {
18
- if (size() == 0) {
19
- return null;
20
- }
21
-
22
- E item = elementAt(0);
23
- removeElementAt(0);
24
-
25
- return item;
26
- }
27
-
28
- public void push(@NonNull E item) {
29
- addElement(item);
30
- }
31
- }
@@ -1,51 +0,0 @@
1
- package com.zoontek.rnbootsplash;
2
-
3
- import androidx.annotation.NonNull;
4
-
5
- import com.facebook.react.bridge.LifecycleEventListener;
6
- import com.facebook.react.bridge.Promise;
7
- import com.facebook.react.bridge.ReactApplicationContext;
8
- import com.facebook.react.module.annotations.ReactModule;
9
-
10
- import java.util.Map;
11
-
12
- @ReactModule(name = RNBootSplashModuleImpl.NAME)
13
- public class RNBootSplashModule extends NativeRNBootSplashSpec implements LifecycleEventListener {
14
-
15
- public RNBootSplashModule(ReactApplicationContext reactContext) {
16
- super(reactContext);
17
- reactContext.addLifecycleEventListener(this);
18
- }
19
-
20
- @Override
21
- @NonNull
22
- public String getName() {
23
- return RNBootSplashModuleImpl.NAME;
24
- }
25
-
26
- @Override
27
- public void onHostResume() {}
28
-
29
- @Override
30
- public void onHostPause() {}
31
-
32
- @Override
33
- public void onHostDestroy() {
34
- RNBootSplashModuleImpl.onHostDestroy();
35
- }
36
-
37
- @Override
38
- protected Map<String, Object> getTypedExportedConstants() {
39
- return RNBootSplashModuleImpl.getConstants(getReactApplicationContext());
40
- }
41
-
42
- @Override
43
- public void hide(boolean fade, Promise promise) {
44
- RNBootSplashModuleImpl.hide(getReactApplicationContext(), fade, promise);
45
- }
46
-
47
- @Override
48
- public void isVisible(Promise promise) {
49
- RNBootSplashModuleImpl.isVisible(promise);
50
- }
51
- }
@@ -1,55 +0,0 @@
1
- package com.zoontek.rnbootsplash;
2
-
3
- import androidx.annotation.NonNull;
4
- import androidx.annotation.Nullable;
5
-
6
- import com.facebook.react.bridge.LifecycleEventListener;
7
- import com.facebook.react.bridge.Promise;
8
- import com.facebook.react.bridge.ReactApplicationContext;
9
- import com.facebook.react.bridge.ReactContextBaseJavaModule;
10
- import com.facebook.react.bridge.ReactMethod;
11
- import com.facebook.react.module.annotations.ReactModule;
12
-
13
- import java.util.Map;
14
-
15
- @ReactModule(name = RNBootSplashModuleImpl.NAME)
16
- public class RNBootSplashModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
17
-
18
- public RNBootSplashModule(ReactApplicationContext reactContext) {
19
- super(reactContext);
20
- reactContext.addLifecycleEventListener(this);
21
- }
22
-
23
- @NonNull
24
- @Override
25
- public String getName() {
26
- return RNBootSplashModuleImpl.NAME;
27
- }
28
-
29
- @Override
30
- public void onHostResume() {}
31
-
32
- @Override
33
- public void onHostPause() {}
34
-
35
- @Override
36
- public void onHostDestroy() {
37
- RNBootSplashModuleImpl.onHostDestroy();
38
- }
39
-
40
- @Nullable
41
- @Override
42
- public Map<String, Object> getConstants() {
43
- return RNBootSplashModuleImpl.getConstants(getReactApplicationContext());
44
- }
45
-
46
- @ReactMethod
47
- public void hide(boolean fade, Promise promise) {
48
- RNBootSplashModuleImpl.hide(getReactApplicationContext(), fade, promise);
49
- }
50
-
51
- @ReactMethod
52
- public void isVisible(Promise promise) {
53
- RNBootSplashModuleImpl.isVisible(promise);
54
- }
55
- }