From cfc20a7dbd66ceb01dcb9032d8ef23acd2dda893 Mon Sep 17 00:00:00 2001 From: Michael Radionov Date: Tue, 4 Jul 2017 14:27:37 +0300 Subject: [PATCH 1/3] Android: Allow custom background color --- .../mehcode/reactnative/splashscreen/SplashScreen.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/mehcode/reactnative/splashscreen/SplashScreen.java b/android/src/main/java/com/mehcode/reactnative/splashscreen/SplashScreen.java index 9b6cd5d..1eac6e5 100644 --- a/android/src/main/java/com/mehcode/reactnative/splashscreen/SplashScreen.java +++ b/android/src/main/java/com/mehcode/reactnative/splashscreen/SplashScreen.java @@ -18,6 +18,10 @@ public class SplashScreen { * Show the splash screen. */ public static void show(final ReactActivity activity, final ReactInstanceManager instanceManager) { + SplashScreen.show(activity, instanceManager, Color.WHITE); + } + + public static void show(final ReactActivity activity, final ReactInstanceManager instanceManager, final int backgroundColor) { if (activity == null) return; // Store weak-reference to showing activity (in case we try to hide too early) @@ -43,14 +47,14 @@ public void run() { // background state and we will not get the context created event ReactContext ctx = instanceManager.getCurrentReactContext(); if (ctx != null) { - activity.getWindow().getDecorView().setBackgroundColor(Color.WHITE); + activity.getWindow().getDecorView().setBackgroundColor(backgroundColor); } else { // Else; wait until react is initialized before we release the native splash instanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() { @Override public void onReactContextInitialized(ReactContext context) { // Hide the native splash screen - activity.getWindow().getDecorView().setBackgroundColor(Color.WHITE); + activity.getWindow().getDecorView().setBackgroundColor(backgroundColor); } }); } From 10d2a260abe62341f2d26a72da8f5a8627dbb837 Mon Sep 17 00:00:00 2001 From: Michael Radionov Date: Mon, 10 Jul 2017 17:57:57 +0300 Subject: [PATCH 2/3] Android: Use themes to set background color --- .../mehcode/reactnative/splashscreen/SplashScreen.java | 9 +++++---- android/src/main/res/values/attr.xml | 5 +++++ 2 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 android/src/main/res/values/attr.xml diff --git a/android/src/main/java/com/mehcode/reactnative/splashscreen/SplashScreen.java b/android/src/main/java/com/mehcode/reactnative/splashscreen/SplashScreen.java index 1eac6e5..900dd7e 100644 --- a/android/src/main/java/com/mehcode/reactnative/splashscreen/SplashScreen.java +++ b/android/src/main/java/com/mehcode/reactnative/splashscreen/SplashScreen.java @@ -2,6 +2,7 @@ import android.app.Activity; import android.app.Dialog; +import android.content.res.TypedArray; import android.graphics.Color; import com.facebook.react.ReactActivity; @@ -18,10 +19,6 @@ public class SplashScreen { * Show the splash screen. */ public static void show(final ReactActivity activity, final ReactInstanceManager instanceManager) { - SplashScreen.show(activity, instanceManager, Color.WHITE); - } - - public static void show(final ReactActivity activity, final ReactInstanceManager instanceManager, final int backgroundColor) { if (activity == null) return; // Store weak-reference to showing activity (in case we try to hide too early) @@ -39,6 +36,10 @@ public void run() { mSplashDialog.show(); } + // Use color of "splashBackgroundColor" attribute in user theme, fallback to white if not set + TypedArray styledAttributes = activity.getTheme().obtainStyledAttributes(R.styleable.RNSplashScreen_Styleable); + final int backgroundColor = styledAttributes.getColor(R.styleable.RNSplashScreen_Styleable_splashBackgroundColor, Color.WHITE); + // If given an instance manager; ensure that we transition to the stage-2 // splash screen // TODO: If you think of a better way to do this; PR please diff --git a/android/src/main/res/values/attr.xml b/android/src/main/res/values/attr.xml new file mode 100644 index 0000000..63b09f2 --- /dev/null +++ b/android/src/main/res/values/attr.xml @@ -0,0 +1,5 @@ + + + + + From 337c7af9b8ee5d59b00c74612ab0bc1eaf5efeb2 Mon Sep 17 00:00:00 2001 From: Michael Radionov Date: Mon, 10 Jul 2017 18:07:27 +0300 Subject: [PATCH 3/3] Android: Add docs for background color customization --- docs/android.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/android.md b/docs/android.md index 23839ef..8df51da 100644 --- a/docs/android.md +++ b/docs/android.md @@ -44,3 +44,12 @@ // [...] } ``` + +5. (OPTIONAL) In `android/app/src/main/res/values/styles.xml`: Add `splashBackgroundColor` attribute with a color you want to see under keyboard while open/close animation is happening (defaults to white). + + ```xml + + ```