Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional theming to Android splash screen #125

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public class MainApplication extends Application implements ReactApplication {
2. Go to `node_modules` ➜ `react-native-splash-screen` and add `SplashScreen.xcodeproj`
3. In XCode, in the project navigator, select your project. Add `libSplashScreen.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
4. To fix `'SplashScreen.h' file not found`, you have to select your project → Build Settings → Search Paths → Header Search Paths to add:

`$(SRCROOT)/../node_modules/react-native-splash-screen/ios`


Expand Down Expand Up @@ -203,14 +203,29 @@ Open `android/app/src/main/res/values/styles.xml` and add `<item name="android:w

If you want to customize the color of the status bar when the splash screen is displayed:

Create `android/app/src/main/res/values/colors.xml` and add
Create `android/app/src/main/res/values/colors.xml` and add
```xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary_dark"><!-- Colour of your status bar here --></color>
<color name="status_bar_color"><!-- Colour of your status bar here --></color>
</resources>
```

Create a style definition for this in `android/app/src/main/res/values/colors.xml`:
```xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="SplashScreenTheme" parent="SplashScreen_SplashTheme">
<item name="colorPrimaryDark">@color/status_bar_color</item>
</style>
</resources>
```

Change your `show` method to include your custom style:
```java
SplashScreen.show(this, false, R.style.SplashScreenTheme);
```

### iOS

Customize your splash screen via LaunchImage or LaunchScreen.xib,
Expand Down
17 changes: 15 additions & 2 deletions android/src/main/java/org/devio/rn/splashscreen/SplashScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,27 @@
* Email:crazycodeboy@gmail.com
*/
public class SplashScreen {
private static int NULL_ID = 0;
private static Dialog mSplashDialog;
private static WeakReference<Activity> mActivity;

/**
* 打开启动屏
*/
public static void show(final Activity activity, final boolean fullScreen) {
public static void show(final Activity activity, final boolean fullScreen, final int themeResId) {
if (activity == null) return;
mActivity = new WeakReference<Activity>(activity);
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (!activity.isFinishing()) {

mSplashDialog = new Dialog(activity, fullScreen ? R.style.SplashScreen_Fullscreen : R.style.SplashScreen_SplashTheme);
mSplashDialog = new Dialog(
activity,
themeResId != NULL_ID ? themeResId

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be best to check if it is fullScreen first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, now that I'm thinking about it, there might be an even cleaner implementation here:

// Not concerned with fullscreen anymore
public static void show(final Activity activity, final int themeResId) {
  ...
}

public static void show(Activity activity, boolean fullScreen) {
    int resourceId = fullScreen ? R.style.SplashScreen_Fullscreen : R.style.SplashScreen_SplashTheme;

    show(activity, resourceId);
}

: fullScreen ? R.style.SplashScreen_Fullscreen
: R.style.SplashScreen_SplashTheme
);
mSplashDialog.setContentView(R.layout.launch_screen);
mSplashDialog.setCancelable(false);

Expand All @@ -40,6 +46,13 @@ public void run() {
});
}

/**
* 打开启动屏
*/
public static void show(final Activity activity, final boolean fullScreen) {
show(activity, fullScreen, 0);
}

/**
* 打开启动屏
*/
Expand Down
3 changes: 0 additions & 3 deletions android/src/main/res/values/refs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
<item type="layout" name="launch_screen">
@layout/launch_screen
</item>
<item type="color" name="primary_dark">
@color/primary_dark
</item>
</resources>
1 change: 0 additions & 1 deletion android/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<style name="SplashScreen_SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowAnimationStyle">@style/SplashScreen_SplashAnimation</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
</style>
<style name="SplashScreen_Fullscreen" parent="SplashScreen_SplashTheme">
<item name="android:windowFullscreen">true</item>
Expand Down