Skip to content

Commit

Permalink
fix(ui): android splash screen (#1803)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwltr authored May 8, 2024
1 parent f69dfa6 commit 898a58a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions android/app/src/main/java/com/bitkit/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.bitkit

import android.os.Bundle;
import android.os.Bundle
import com.bitkit.modules.SplashScreen.SplashScreenModule
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
import com.facebook.react.defaults.DefaultReactActivityDelegate
import com.bitkit.modules.SplashScreen.SplashScreenModule

class MainActivity : ReactActivity() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.os.Build;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.bitkit.R;
import com.facebook.react.bridge.ReactApplicationContext;
Expand All @@ -17,7 +18,6 @@ public class SplashScreenModule extends ReactContextBaseJavaModule {
private static WeakReference<Activity> mainActivityRef;
private static Dialog splashDialog;

/* Boilerplate */
SplashScreenModule(@NonNull ReactApplicationContext reactContext) {
super(reactContext);
}
Expand All @@ -28,7 +28,6 @@ public String getName() {
return "SplashScreenModule";
}

/* React Native method */
@ReactMethod
public void hide() {
Activity currentActivity = getCurrentActivity();
Expand Down Expand Up @@ -63,13 +62,18 @@ public void hide() {
});
}

/* Native util */
public static void show(@NonNull final Activity activity) {
mainActivityRef = new WeakReference<>(activity);

// Set app background color back to black
activity.getWindow().setBackgroundDrawableResource(R.color.black);

activity.runOnUiThread(() -> {
// Leave out the second argument if you're not using animations
splashDialog = new Dialog(activity, R.style.AppTheme_SplashDialog);
// Set splash screen status & navigation bar color
splashDialog.getWindow().setStatusBarColor(ContextCompat.getColor(activity, R.color.brand));
splashDialog.getWindow().setNavigationBarColor(ContextCompat.getColor(activity, R.color.brand));
splashDialog.setContentView(R.layout.splash_screen);
splashDialog.setCancelable(false);

Expand All @@ -78,4 +82,4 @@ public static void show(@NonNull final Activity activity) {
}
});
}
}
}
9 changes: 3 additions & 6 deletions android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
<item name="android:windowBackground">@color/black</item>
<item name="android:navigationBarColor">@color/brand</item>
</style>


<!-- Colors get updated programmatically in SplashScreenModule -->
<style name="SplashTheme" parent="AppTheme">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:statusBarColor" tools:targetApi="m">@color/brand</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
<item name="android:navigationBarColor">@color/black</item>
</style>

<style name="WindowExitFadeOut">
Expand Down

0 comments on commit 898a58a

Please sign in to comment.