Skip to content

Commit

Permalink
4.0.1 (#286)
Browse files Browse the repository at this point in the history
* Switch to Stack

* Update Podfile.lock

* Revert naming logic
  • Loading branch information
zoontek authored Nov 24, 2021
1 parent f1c6d59 commit bc2cd7b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.facebook.react.common.ReactConstants;
import com.facebook.react.module.annotations.ReactModule;

import java.util.ArrayList;
import java.util.Stack;
import java.util.Timer;
import java.util.TimerTask;

Expand All @@ -40,9 +40,9 @@ private enum Status {
@Nullable
private static SplashScreen mSplashScreen = null;

private static final ArrayList<RNBootSplashTask> mTaskQueue = new ArrayList<>();
private static final Stack<RNBootSplashTask> mTaskStack = new Stack<>();
private static Status mStatus = Status.HIDDEN;
private static boolean mIsAppInBackground = false;
private static boolean mIsAppInForeground = true;
private static boolean mShouldFade = false;
private static boolean mShouldKeepOnScreen = true;

Expand Down Expand Up @@ -99,29 +99,27 @@ public void onAnimationEnd(Animator animation) {

@Override
public void onHostDestroy() {
mIsAppInBackground = true;
mIsAppInForeground = false;
}

@Override
public void onHostPause() {
mIsAppInBackground = true;
mIsAppInForeground = false;
}

@Override
public void onHostResume() {
mIsAppInBackground = false;
mIsAppInForeground = true;
shiftNextTask();
}

private void shiftNextTask() {
boolean shouldSkipTick = mStatus == Status.TRANSITIONING
|| mIsAppInBackground
|| mTaskQueue.isEmpty();

if (shouldSkipTick) return;

RNBootSplashTask task = mTaskQueue.remove(0);
hideWithTask(task);
if (mStatus != Status.TRANSITIONING &&
mIsAppInForeground &&
mTaskStack.size() > 0) {
RNBootSplashTask task = mTaskStack.pop();
hideWithTask(task);
}
}

private void waitAndRetry() {
Expand Down Expand Up @@ -170,8 +168,8 @@ public void run() {
@Override
public void run() {
mStatus = Status.HIDDEN;
promise.resolve(true);
timer.cancel();
promise.resolve(true);
shiftNextTask();
}
}, ANIMATION_DURATION);
Expand All @@ -184,7 +182,7 @@ public void hide(final boolean fade, final Promise promise) {
if (mSplashScreen == null || mStatus == Status.HIDDEN) {
promise.resolve(true);
} else {
mTaskQueue.add(new RNBootSplashTask(fade, promise));
mTaskStack.push(new RNBootSplashTask(fade, promise));
shiftNextTask();
}
}
Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ PODS:
- React-jsi (= 0.66.3)
- React-logger (= 0.66.3)
- React-perflogger (= 0.66.3)
- RNBootSplash (4.0.0-beta.3):
- RNBootSplash (4.0.1):
- React-Core
- Yoga (1.14.0)

Expand Down Expand Up @@ -418,7 +418,7 @@ SPEC CHECKSUMS:
React-RCTVibration: 50cfe7049167cfc7e83ac5542c6fff0c76791a9b
React-runtimeexecutor: bbbdb3d8fcf327c6e2249ee71b6ef1764b7dc266
ReactCommon: 9bac022ab71596f2b0fde1268272543184c63971
RNBootSplash: 674c17cd7797501232e64ee6ebc62ab89527ba29
RNBootSplash: 6306e2122044d4a0f4c56df82e1731ca8c97f0fd
Yoga: 32a18c0e845e185f4a2a66ec76e1fd1f958f22fa

PODFILE CHECKSUM: 12b4370ff988cf399f55465f14d3f3ec3665fb62
Expand Down
22 changes: 10 additions & 12 deletions ios/RNBootSplash.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#import <React/RCTBridge.h>
#import <React/RCTUtils.h>

static NSMutableArray<RNBootSplashTask *> *_taskQueue = nil;
static NSMutableArray<RNBootSplashTask *> *_taskStack = nil;
static RCTRootView *_rootView = nil;
static RNBootSplashStatus _status = RNBootSplashStatusHidden;

Expand Down Expand Up @@ -37,7 +37,7 @@ + (void)initWithStoryboard:(NSString * _Nonnull)storyboardName
rootView:(RCTRootView * _Nonnull)rootView {
_rootView = rootView;
_status = RNBootSplashStatusVisible;
_taskQueue = [[NSMutableArray alloc] init];
_taskStack = [[NSMutableArray alloc] init];

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
[_rootView setLoadingView:[[storyboard instantiateInitialViewController] view]];
Expand Down Expand Up @@ -85,16 +85,14 @@ + (void)onJavaScriptDidFailToLoad {
}

+ (void)shiftNextTask {
bool shouldSkipTick = _status == RNBootSplashStatusTransitioning
|| [_taskQueue count] == 0
|| [[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground;
if (_status != RNBootSplashStatusTransitioning &&
[_taskStack count] > 0 &&
[[UIApplication sharedApplication] applicationState] != UIApplicationStateBackground) {
RNBootSplashTask *task = [_taskStack objectAtIndex:0];
[_taskStack removeObjectAtIndex:0];

if (shouldSkipTick) return;

RNBootSplashTask *task = [_taskQueue objectAtIndex:0];
[_taskQueue removeObjectAtIndex:0];

return [self hideWithTask:task];
[self hideWithTask:task];
}
}

+ (void)hideWithTask:(RNBootSplashTask *)task {
Expand Down Expand Up @@ -143,7 +141,7 @@ + (void)hideWithTask:(RNBootSplashTask *)task {
RNBootSplashTask *task = [[RNBootSplashTask alloc] initWithFade:fade
resolver:resolve];

[_taskQueue addObject:task];
[_taskStack addObject:task];
[RNBootSplash shiftNextTask];
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-bootsplash",
"version": "4.0.0",
"version": "4.0.1",
"license": "MIT",
"description": "Display a bootsplash on your app starts. Hide it when you want.",
"author": "Mathieu Acthernoene <zoontek@gmail.com>",
Expand Down

0 comments on commit bc2cd7b

Please sign in to comment.