Skip to content

Instantly share code, notes, and snippets.

@r0b0t3d
Last active July 18, 2023 03:06
Show Gist options
  • Save r0b0t3d/1877de009cc2741900e67ded0b26d927 to your computer and use it in GitHub Desktop.
Save r0b0t3d/1877de009cc2741900e67ded0b26d927 to your computer and use it in GitHub Desktop.
Add option for react-native-bootsplash to use custom xml
diff --git a/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java b/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java
index 83dbff8..aae4fae 100644
--- a/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java
+++ b/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java
@@ -4,6 +4,7 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
import android.content.Context;
+import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
@@ -19,8 +20,15 @@ public class RNBootSplash {
private static boolean mInitialized = false;
private static int mDrawableResId = -1;
+ private static int mLayoutResId = -1;
private static boolean mIsVisible = false;
+ public static void initLayout(int layoutResId, Activity activity) {
+ mLayoutResId = layoutResId;
+ mInitialized = true;
+ RNBootSplash.show(activity, 0.0f);
+ }
+
public static void init(final int drawableResId, @NonNull final Activity activity) {
if (!mInitialized) {
mDrawableResId = drawableResId;
@@ -40,17 +48,20 @@ public class RNBootSplash {
mIsVisible = true;
Context context = activity.getApplicationContext();
- LinearLayout layout = new LinearLayout(context);
- LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
- View view = new View(context);
int roundedDuration = duration.intValue();
-
- view.setBackgroundResource(mDrawableResId);
+ LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
+ ViewGroup layout = null;
+ if (mDrawableResId != -1) {
+ layout = new LinearLayout(context);
+ View view = new View(context);
+ view.setBackgroundResource(mDrawableResId);
+ layout.setLayoutTransition(null);
+ ((LinearLayout)layout).setOrientation(LinearLayout.VERTICAL);
+ layout.addView(view, params);
+ } else {
+ layout = (ViewGroup) LayoutInflater.from(activity).inflate(mLayoutResId, null, false);
+ }
layout.setId(R.id.bootsplash_layout_id);
- layout.setLayoutTransition(null);
- layout.setOrientation(LinearLayout.VERTICAL);
- layout.addView(view, params);
-
if (roundedDuration <= 0) {
activity.addContentView(layout, params);
} else {
@@ -78,7 +89,7 @@ public class RNBootSplash {
mIsVisible = false;
- final LinearLayout layout = activity.findViewById(R.id.bootsplash_layout_id);
+ final ViewGroup layout = activity.findViewById(R.id.bootsplash_layout_id);
if (layout == null) {
return;
diff --git a/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java b/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java
index ed3f243..03008e0 100644
--- a/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java
+++ b/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java
@@ -3,6 +3,7 @@ package com.zoontek.rnbootsplash;
import android.app.Activity;
import androidx.annotation.DrawableRes;
+import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
public class RNBootSplash {
@@ -10,4 +11,8 @@ public class RNBootSplash {
public static void init(final @DrawableRes int drawableResId, @NonNull final Activity activity) {
RNBootSplashModule.init(drawableResId, activity);
}
+
+ public static void initLayout(final @LayoutRes int layoutRes, @NonNull final Activity activity) {
+ RNBootSplashModule.initLayout(layoutRes, activity);
+ }
}
diff --git a/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModule.java b/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModule.java
index fca937f..3948074 100644
--- a/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModule.java
+++ b/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModule.java
@@ -4,6 +4,7 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
import android.content.Context;
+import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
@@ -30,12 +31,15 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
private static final int ANIMATION_DURATION = 220;
private static int mDrawableResId = -1;
+ private static int mLayoutResId = -1;
private static boolean mSplashVisible = false;
private static boolean mAppPaused = true;
private static boolean mFadeOption = false;
- @Nullable private static String mTaskToRunOnResume = null;
- @Nullable private static Promise mPendingPromise = null;
+ @Nullable
+ private static String mTaskToRunOnResume = null;
+ @Nullable
+ private static Promise mPendingPromise = null;
public RNBootSplashModule(ReactApplicationContext reactContext) {
super(reactContext);
@@ -64,6 +68,11 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
RNBootSplashModule.show(activity, false);
}
+ public static void initLayout(int layoutResId, Activity activity) {
+ mLayoutResId = layoutResId;
+ RNBootSplashModule.show(activity, false);
+ }
+
@Override
public void onHostDestroy() {
mAppPaused = true;
@@ -110,16 +119,19 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
mSplashVisible = true;
Context context = activity.getApplicationContext();
- LinearLayout layout = new LinearLayout(context);
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
- View view = new View(context);
-
- view.setBackgroundResource(mDrawableResId);
+ ViewGroup layout = null;
+ if (mDrawableResId != -1) {
+ layout = new LinearLayout(context);
+ View view = new View(context);
+ view.setBackgroundResource(mDrawableResId);
+ layout.setLayoutTransition(null);
+ ((LinearLayout) layout).setOrientation(LinearLayout.VERTICAL);
+ layout.addView(view, params);
+ } else {
+ layout = (ViewGroup) LayoutInflater.from(activity).inflate(mLayoutResId, null, false);
+ }
layout.setId(R.id.bootsplash_layout_id);
- layout.setLayoutTransition(null);
- layout.setOrientation(LinearLayout.VERTICAL);
- layout.addView(view, params);
-
if (fade) {
layout.setAlpha(0.0f);
activity.addContentView(layout, params);
@@ -196,7 +208,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
@ReactMethod
public void show(final boolean fade, final Promise promise) {
- if (mDrawableResId == -1) {
+ if (mDrawableResId == -1 && mLayoutResId == -1) {
promise.reject("uninitialized_module", "react-native-bootsplash has not been initialized");
return;
}
@@ -219,7 +231,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
@ReactMethod
public void hide(final boolean fade, final Promise promise) {
- if (mDrawableResId == -1) {
+ if (mDrawableResId == -1 && mLayoutResId == -1) {
promise.reject("uninitialized_module", "react-native-bootsplash has not been initialized");
return;
}
diff --git a/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java b/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java
index ed3f243..03008e0 100644
--- a/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java
+++ b/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java
@@ -3,6 +3,7 @@ package com.zoontek.rnbootsplash;
import android.app.Activity;
import androidx.annotation.DrawableRes;
+import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
public class RNBootSplash {
@@ -10,4 +11,8 @@ public class RNBootSplash {
public static void init(final @DrawableRes int drawableResId, @NonNull final Activity activity) {
RNBootSplashModule.init(drawableResId, activity);
}
+
+ public static void initLayout(final @LayoutRes int layoutRes, @NonNull final Activity activity) {
+ RNBootSplashModule.initLayout(layoutRes, activity);
+ }
}
diff --git a/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModule.java b/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModule.java
index 2ea93d4..474b7f4 100644
--- a/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModule.java
+++ b/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModule.java
@@ -4,6 +4,7 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
import android.content.Context;
+import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
@@ -12,6 +13,7 @@ import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import androidx.annotation.DrawableRes;
+import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import com.facebook.react.ReactApplication;
@@ -38,6 +40,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
}
private static int mDrawableResId = -1;
+ private static int mLayoutResId = -1;
private final ArrayList<RNBootSplashTask> mTaskQueue = new ArrayList<>();
private Status mStatus = Status.HIDDEN;
@@ -46,7 +49,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
public RNBootSplashModule(ReactApplicationContext reactContext) {
super(reactContext);
- if (mDrawableResId != -1) {
+ if (mDrawableResId != -1 || mLayoutResId != -1) {
mStatus = Status.VISIBLE;
}
@@ -58,16 +61,20 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
return MODULE_NAME;
}
- private static LinearLayout getLayout(@NonNull Activity activity, LayoutParams params) {
+ private static ViewGroup getLayout(@NonNull Activity activity, LayoutParams params) {
Context context = activity.getApplicationContext();
- LinearLayout layout = new LinearLayout(context);
- View view = new View(context);
-
- view.setBackgroundResource(mDrawableResId);
+ ViewGroup layout;
+ if (mDrawableResId != -1) {
+ layout = new LinearLayout(context);
+ View view = new View(context);
+ view.setBackgroundResource(mDrawableResId);
+ layout.setLayoutTransition(null);
+ ((LinearLayout) layout).setOrientation(LinearLayout.VERTICAL);
+ layout.addView(view, params);
+ } else {
+ layout = (ViewGroup) LayoutInflater.from(activity).inflate(mLayoutResId, null, false);
+ }
layout.setId(R.id.bootsplash_layout_id);
- layout.setLayoutTransition(null);
- layout.setOrientation(LinearLayout.VERTICAL);
- layout.addView(view, params);
return layout;
}
@@ -91,6 +98,24 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
});
}
+ public static void initLayout(@LayoutRes int layoutResId, final Activity activity) {
+ mLayoutResId = layoutResId;
+ UiThreadUtil.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (activity == null
+ || activity.isFinishing()
+ || activity.findViewById(R.id.bootsplash_layout_id) != null) {
+ return;
+ }
+
+ LayoutParams params = new LayoutParams(
+ LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
+ activity.addContentView(getLayout(activity, params), params);
+ }
+ });
+ }
+
@Override
public void onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy();
@@ -145,7 +170,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
}
private void shiftNextTask() {
- boolean shouldSkipTick = mDrawableResId == -1
+ boolean shouldSkipTick = (mDrawableResId == -1 && mLayoutResId == -1)
|| mStatus == Status.TRANSITIONING
|| mIsAppInBackground
|| mTaskQueue.isEmpty();
@@ -188,7 +213,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
LayoutParams params = new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
- LinearLayout layout = getLayout(activity, params);
+ ViewGroup layout = getLayout(activity, params);
if (task.getFade()) {
layout.setAlpha(0.0f);
@@ -233,7 +258,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
return;
}
- final LinearLayout layout = activity.findViewById(R.id.bootsplash_layout_id);
+ final ViewGroup layout = activity.findViewById(R.id.bootsplash_layout_id);
if (layout == null) {
promise.resolve(true); // splash screen is already hidden
@@ -276,7 +301,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
@ReactMethod
public void show(final boolean fade, final Promise promise) {
- if (mDrawableResId == -1) {
+ if (mDrawableResId == -1 && mLayoutResId == -1) {
promise.reject("uninitialized_module", "react-native-bootsplash has not been initialized");
} else {
mTaskQueue.add(new RNBootSplashTask(RNBootSplashTask.Type.SHOW, fade, promise));
@@ -286,7 +311,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
@ReactMethod
public void hide(final boolean fade, final Promise promise) {
- if (mDrawableResId == -1) {
+ if (mDrawableResId == -1 && mLayoutResId == -1) {
promise.reject("uninitialized_module", "react-native-bootsplash has not been initialized");
} else {
mTaskQueue.add(new RNBootSplashTask(RNBootSplashTask.Type.HIDE, fade, promise));
diff --git a/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java b/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java
index ed3f243..03008e0 100644
--- a/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java
+++ b/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java
@@ -3,6 +3,7 @@ package com.zoontek.rnbootsplash;
import android.app.Activity;
import androidx.annotation.DrawableRes;
+import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
public class RNBootSplash {
@@ -10,4 +11,8 @@ public class RNBootSplash {
public static void init(final @DrawableRes int drawableResId, @NonNull final Activity activity) {
RNBootSplashModule.init(drawableResId, activity);
}
+
+ public static void initLayout(final @LayoutRes int layoutRes, @NonNull final Activity activity) {
+ RNBootSplashModule.initLayout(layoutRes, activity);
+ }
}
diff --git a/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModule.java b/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModule.java
index 0111b5d..5a064dc 100644
--- a/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModule.java
+++ b/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModule.java
@@ -4,6 +4,7 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
import android.content.Context;
+import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
@@ -41,7 +42,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
}
private static int mDrawableResId = -1;
-
+ private static int mLayoutResId = -1;
private final ArrayList<RNBootSplashTask> mTaskQueue = new ArrayList<>();
private Status mStatus = Status.HIDDEN;
private boolean mIsAppInBackground = false;
@@ -61,16 +62,21 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
return MODULE_NAME;
}
- private static LinearLayout getLayout(@NonNull Activity activity, LayoutParams params) {
+ private static ViewGroup getLayout(@NonNull Activity activity, LayoutParams params) {
Context context = activity.getApplicationContext();
- LinearLayout layout = new LinearLayout(context);
- View view = new View(context);
+ ViewGroup layout;
+ if (mDrawableResId != -1) {
+ layout = new LinearLayout(context);
+ View view = new View(context);
- view.setBackgroundResource(mDrawableResId);
+ view.setBackgroundResource(mDrawableResId);
+ layout.addView(view, params);
+ ((LinearLayout)layout).setOrientation(LinearLayout.VERTICAL);
+ } else {
+ layout = (ViewGroup) LayoutInflater.from(activity).inflate(mLayoutResId, null, false);
+ }
layout.setId(R.id.bootsplash_layout_id);
layout.setLayoutTransition(null);
- layout.setOrientation(LinearLayout.VERTICAL);
- layout.addView(view, params);
return layout;
}
@@ -94,6 +100,24 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
});
}
+ public static void initLayout(int layoutResId, final Activity activity) {
+ mLayoutResId = layoutResId;
+ UiThreadUtil.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (activity == null
+ || activity.isFinishing()
+ || activity.findViewById(R.id.bootsplash_layout_id) != null) {
+ return;
+ }
+
+ LayoutParams params = new LayoutParams(
+ LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
+ activity.addContentView(getLayout(activity, params), params);
+ }
+ });
+ }
+
@Override
public void onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy();
@@ -148,7 +172,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
}
private void shiftNextTask() {
- boolean shouldSkipTick = mDrawableResId == -1
+ boolean shouldSkipTick = (mDrawableResId == -1 && mLayoutResId == -1)
|| mStatus == Status.TRANSITIONING_TO_VISIBLE
|| mStatus == Status.TRANSITIONING_TO_HIDDEN
|| mIsAppInBackground
@@ -202,7 +226,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
LayoutParams params = new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
- LinearLayout layout = getLayout(activity, params);
+ ViewGroup layout = getLayout(activity, params);
if (task.getFade()) {
layout.setAlpha(0.0f);
@@ -288,7 +312,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
@ReactMethod
public void show(final boolean fade, final Promise promise) {
- if (mDrawableResId == -1) {
+ if (mDrawableResId == -1 && mLayoutResId == -1) {
promise.reject("uninitialized_module", "react-native-bootsplash has not been initialized");
} else {
mTaskQueue.add(new RNBootSplashTask(RNBootSplashTask.Type.SHOW, fade, promise));
@@ -298,7 +322,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
@ReactMethod
public void hide(final boolean fade, final Promise promise) {
- if (mDrawableResId == -1) {
+ if (mDrawableResId == -1 && mLayoutResId == -1) {
promise.reject("uninitialized_module", "react-native-bootsplash has not been initialized");
} else {
mTaskQueue.add(new RNBootSplashTask(RNBootSplashTask.Type.HIDE, fade, promise));
diff --git a/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java b/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java
index ed3f243..03008e0 100644
--- a/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java
+++ b/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java
@@ -3,6 +3,7 @@ package com.zoontek.rnbootsplash;
import android.app.Activity;
import androidx.annotation.DrawableRes;
+import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
public class RNBootSplash {
@@ -10,4 +11,8 @@ public class RNBootSplash {
public static void init(final @DrawableRes int drawableResId, @NonNull final Activity activity) {
RNBootSplashModule.init(drawableResId, activity);
}
+
+ public static void initLayout(final @LayoutRes int layoutRes, @NonNull final Activity activity) {
+ RNBootSplashModule.initLayout(layoutRes, activity);
+ }
}
diff --git a/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModule.java b/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModule.java
index db52c9e..5f25b74 100644
--- a/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModule.java
+++ b/node_modules/react-native-bootsplash/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModule.java
@@ -3,6 +3,7 @@ package com.zoontek.rnbootsplash;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
+import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
@@ -39,6 +40,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
}
private static int mDrawableResId = -1;
+ private static int mLayoutResId = -1;
private static final ArrayList<RNBootSplashTask> mTaskQueue = new ArrayList<>();
private static Status mStatus = Status.HIDDEN;
private static boolean mIsAppInBackground = false;
@@ -53,16 +55,19 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
return MODULE_NAME;
}
- private static LinearLayout getLayout(@NonNull Activity activity, LayoutParams params) {
- LinearLayout layout = new LinearLayout(activity);
- View view = new View(activity);
-
- view.setBackgroundResource(mDrawableResId);
+ private static ViewGroup getLayout(@NonNull Activity activity, LayoutParams params) {
+ ViewGroup layout;
+ if (mDrawableResId != -1) {
+ layout = new LinearLayout(activity);
+ View view = new View(activity);
+ view.setBackgroundResource(mDrawableResId);
+ ((LinearLayout)layout).setOrientation(LinearLayout.VERTICAL);
+ layout.addView(view, params);
+ } else {
+ layout = (ViewGroup) LayoutInflater.from(activity).inflate(mLayoutResId, null, false);
+ }
layout.setId(R.id.bootsplash_layout_id);
layout.setLayoutTransition(null);
- layout.setOrientation(LinearLayout.VERTICAL);
- layout.addView(view, params);
-
return layout;
}
@@ -86,6 +91,21 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
});
}
+ public static void initLayout(int layoutResId, final Activity activity) {
+ mLayoutResId = layoutResId;
+ UiThreadUtil.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (activity == null || activity.isFinishing() || activity.findViewById(R.id.bootsplash_layout_id) != null) {
+ return;
+ }
+ LayoutParams params = new LayoutParams(
+ LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
+ activity.addContentView(getLayout(activity, params), params);
+ }
+ });
+ }
+
@Override
public void onHostDestroy() {
mIsAppInBackground = true;
@@ -103,7 +123,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
}
private void shiftNextTask() {
- boolean shouldSkipTick = mDrawableResId == -1
+ boolean shouldSkipTick = (mDrawableResId == -1 && mLayoutResId == -1)
|| mStatus == Status.TRANSITIONING_TO_VISIBLE
|| mStatus == Status.TRANSITIONING_TO_HIDDEN
|| mIsAppInBackground
@@ -157,7 +177,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
LayoutParams params = new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
- LinearLayout layout = getLayout(activity, params);
+ ViewGroup layout = getLayout(activity, params);
if (task.getFade()) {
layout.setAlpha(0.0f);
@@ -243,7 +263,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
@ReactMethod
public void show(final boolean fade, final Promise promise) {
- if (mDrawableResId == -1) {
+ if (mDrawableResId == -1 && mLayoutResId == -1) {
promise.reject("uninitialized_module", "react-native-bootsplash has not been initialized");
} else {
mTaskQueue.add(new RNBootSplashTask(RNBootSplashTask.Type.SHOW, fade, promise));
@@ -253,7 +273,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
@ReactMethod
public void hide(final boolean fade, final Promise promise) {
- if (mDrawableResId == -1) {
+ if (mDrawableResId == -1 && mLayoutResId == -1) {
promise.reject("uninitialized_module", "react-native-bootsplash has not been initialized");
} else {
mTaskQueue.add(new RNBootSplashTask(RNBootSplashTask.Type.HIDE, fade, promise));
@jaredcat
Copy link

jaredcat commented Jun 23, 2022

@r0b0t3d I'm using react-native-bootsplash+3.2.6.patch with 3.2.6 (technically 3.2.7) of react-native-bootsplash but when call RNBootSplash.hide(); my app is crashing. Any ideas?

Nvm. My layout file was using RelativeLayout swapped it to LinearLayout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment