-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Embed react-native-bootsplash lite module #7096
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
aeceb57
Embed a lite iOS version of react-native-bootsplash-4
zoontek 6486dae
Use [UIApplication sharedApplication]
zoontek 1e7f750
Don't rely on UIApplicationState
zoontek e026e8d
Add lite Android version
zoontek 9d7aae6
Update react-native-screens + react-navigation
zoontek 0d12526
Add ios module
zoontek b7a87e8
Add android module
zoontek fdb78a0
Update loading screen colors
zoontek 0cd250c
Force hide after 10 secs after content load
zoontek 54809ec
Fix tests
zoontek 24c4e75
Prefer local mock
zoontek e88f943
Merge branch 'main' into embed-bootsplash-lite
zoontek fbb7f54
Fix lock files
zoontek a116be0
Merge branch 'main' into embed-bootsplash-lite
zoontek 61f234d
Fix merging conflict
zoontek 95f520a
Handle feedbacks
zoontek 111cee1
Fix code styling issues
zoontek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
android/app/src/main/java/com/expensify/chat/bootsplash/BootSplash.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.expensify.chat.bootsplash; | ||
|
|
||
| import android.app.Activity; | ||
| import androidx.annotation.DrawableRes; | ||
| import androidx.annotation.NonNull; | ||
|
|
||
| public class BootSplash { | ||
|
|
||
| public static void init(final @DrawableRes int drawableResId, @NonNull final Activity activity) { | ||
| BootSplashModule.init(drawableResId, activity); | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
android/app/src/main/java/com/expensify/chat/bootsplash/BootSplashActivity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package com.expensify.chat.bootsplash; | ||
|
|
||
| import android.content.Intent; | ||
| import android.os.Bundle; | ||
| import androidx.annotation.Nullable; | ||
| import androidx.appcompat.app.AppCompatActivity; | ||
| import com.expensify.chat.MainActivity; | ||
|
|
||
| public class BootSplashActivity extends AppCompatActivity { | ||
|
|
||
| @Override | ||
| protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| forwardIntentToMainActivity(getIntent()); | ||
| } | ||
|
|
||
| @Override | ||
| protected void onNewIntent(Intent intent) { | ||
| super.onNewIntent(intent); | ||
| forwardIntentToMainActivity(intent); | ||
| } | ||
|
|
||
| protected void forwardIntentToMainActivity(Intent intent) { | ||
| Intent intentCopy = (Intent) intent.clone(); | ||
| intentCopy.setClass(this, MainActivity.class); | ||
|
|
||
| startActivity(intentCopy); | ||
| finish(); | ||
| } | ||
| } |
128 changes: 128 additions & 0 deletions
128
android/app/src/main/java/com/expensify/chat/bootsplash/BootSplashModule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| package com.expensify.chat.bootsplash; | ||
|
|
||
| import android.animation.Animator; | ||
| import android.animation.AnimatorListenerAdapter; | ||
| import android.app.Activity; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
| import android.view.animation.AccelerateInterpolator; | ||
| import android.widget.LinearLayout; | ||
| import android.widget.LinearLayout.LayoutParams; | ||
| import androidx.annotation.DrawableRes; | ||
| import com.expensify.chat.R; | ||
| import com.facebook.react.bridge.Promise; | ||
| import com.facebook.react.bridge.ReactApplicationContext; | ||
| import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
| import com.facebook.react.bridge.ReactMethod; | ||
| import com.facebook.react.bridge.UiThreadUtil; | ||
| import com.facebook.react.module.annotations.ReactModule; | ||
| import java.util.Timer; | ||
| import java.util.TimerTask; | ||
|
|
||
| @ReactModule(name = BootSplashModule.MODULE_NAME) | ||
| public class BootSplashModule extends ReactContextBaseJavaModule { | ||
|
|
||
| public static final String MODULE_NAME = "BootSplash"; | ||
| private static int mDrawableResId = -1; | ||
| private static boolean mSplashVisible = false; | ||
|
|
||
| public BootSplashModule(ReactApplicationContext reactContext) { | ||
| super(reactContext); | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return MODULE_NAME; | ||
| } | ||
|
|
||
| protected static void init(final @DrawableRes int drawableResId, final Activity activity) { | ||
| UiThreadUtil.runOnUiThread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| if (activity == null | ||
| || activity.isFinishing() | ||
| || activity.findViewById(R.id.bootsplash_layout_id) != null) { | ||
| return; | ||
| } | ||
|
|
||
| mDrawableResId = drawableResId; | ||
| mSplashVisible = true; | ||
|
|
||
| LinearLayout layout = new LinearLayout(activity); | ||
| layout.setId(R.id.bootsplash_layout_id); | ||
| layout.setLayoutTransition(null); | ||
| layout.setOrientation(LinearLayout.VERTICAL); | ||
|
|
||
| View view = new View(activity); | ||
| view.setBackgroundResource(mDrawableResId); | ||
|
|
||
| LayoutParams params = new LayoutParams( | ||
| LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); | ||
|
|
||
| layout.addView(view, params); | ||
| activity.addContentView(layout, params); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private void waitAndHide() { | ||
| final Timer timer = new Timer(); | ||
|
|
||
| timer.schedule(new TimerTask() { | ||
| @Override | ||
| public void run() { | ||
| hide(); | ||
| timer.cancel(); | ||
| } | ||
| }, 250); | ||
| } | ||
|
|
||
| @ReactMethod | ||
| public void hide() { | ||
| if (mDrawableResId == -1) | ||
| return; | ||
|
|
||
| UiThreadUtil.runOnUiThread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| final Activity activity = getReactApplicationContext().getCurrentActivity(); | ||
|
|
||
| if (activity == null || activity.isFinishing()) { | ||
| waitAndHide(); | ||
| return; | ||
| } | ||
|
|
||
| final LinearLayout layout = activity.findViewById(R.id.bootsplash_layout_id); | ||
|
|
||
| // check if splash screen is already hidden | ||
| if (layout == null) | ||
| return; | ||
|
|
||
| final ViewGroup parent = (ViewGroup) layout.getParent(); | ||
|
|
||
| layout | ||
| .animate() | ||
| .setDuration(250) | ||
| .alpha(0.0f) | ||
| .setInterpolator(new AccelerateInterpolator()) | ||
| .setListener(new AnimatorListenerAdapter() { | ||
| @Override | ||
| public void onAnimationEnd(Animator animation) { | ||
| super.onAnimationEnd(animation); | ||
|
|
||
| if (parent != null) | ||
| parent.removeView(layout); | ||
|
|
||
| mDrawableResId = -1; | ||
| mSplashVisible = false; | ||
| } | ||
| }).start(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @ReactMethod | ||
| public void getVisibilityStatus(final Promise promise) { | ||
| promise.resolve(mSplashVisible ? "visible" : "hidden"); | ||
| } | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
android/app/src/main/java/com/expensify/chat/bootsplash/BootSplashPackage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.expensify.chat.bootsplash; | ||
|
|
||
| import androidx.annotation.NonNull; | ||
| import com.facebook.react.ReactPackage; | ||
| import com.facebook.react.bridge.NativeModule; | ||
| import com.facebook.react.bridge.ReactApplicationContext; | ||
| import com.facebook.react.uimanager.ViewManager; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| public class BootSplashPackage implements ReactPackage { | ||
|
|
||
| @NonNull | ||
| @Override | ||
| public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) { | ||
| return Arrays.<NativeModule>asList(new BootSplashModule(reactContext)); | ||
| } | ||
|
|
||
| @NonNull | ||
| @Override | ||
| public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) { | ||
| return Collections.emptyList(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <resources> | ||
| <item type="id" name="bootsplash_layout_id" /> | ||
| </resources> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // | ||
| // RCTBootSplash.h | ||
| // NewExpensify | ||
| // | ||
| // Created by Mathieu Acthernoene on 07/01/2022. | ||
| // | ||
|
|
||
| #import <React/RCTBridgeModule.h> | ||
| #import <React/RCTRootView.h> | ||
|
|
||
| @interface RCTBootSplash : NSObject <RCTBridgeModule> | ||
|
|
||
| + (void)initWithStoryboard:(NSString * _Nonnull)storyboardName | ||
| rootView:(RCTRootView * _Nullable)rootView; | ||
|
|
||
| @end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.