-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7096 from zoontek/embed-bootsplash-lite
Embed react-native-bootsplash lite module
- Loading branch information
Showing
24 changed files
with
431 additions
and
654 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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 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 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 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 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.