Skip to content

Commit

Permalink
fix: check if activityState is nil (#714)
Browse files Browse the repository at this point in the history
Changed the logic of resolving activityState to take into account the initial nil value of it by passing the NSNumber instead of int (which was resolved to 0) on iOS. The logic for restoring user interaction in ScreenContainer had to be changed too since it did not take into account going from value 1 to 2 for one of Screens. It worked before because, at the end of the transition, the activityState of all Screens was changed to 0 due to the initial nil pass, and then switched back to the proper value in the next evaluation, which resulted in screenAdded being set to YES. A similar situation, but without the need for change in ScreenContainer applies to Android.
  • Loading branch information
WoLewicki committed Nov 19, 2020
1 parent 0b78508 commit 9358d45
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ protected Screen createViewInstance(ThemedReactContext reactContext) {
}

@ReactProp(name = "activityState")
public void setActivityState(Screen view, int activityState) {
public void setActivityState(Screen view, Integer activityState) {
if (activityState == null) {
// Null will be provided when activityState is set as an animated value and we change
// it from JS to be a plain value (non animated).
// In case when null is received, we want to ignore such value and not make
// any updates as the actual non-null value will follow immediately.
return;
}
if (activityState == 0) {
view.setActivityState(Screen.ActivityState.INACTIVE);
} else if (activityState == 1) {
Expand Down
14 changes: 10 additions & 4 deletions ios/RNSScreen.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ - (void)updateBounds
[_bridge.uiManager setSize:self.bounds.size forView:self];
}

- (void)setActivityState:(int)activityState
{
if (activityState != _activityState) {
// Nil will be provided when activityState is set as an animated value and we change
// it from JS to be a plain value (non animated).
// In case when nil is received, we want to ignore such value and not make
// any updates as the actual non-nil value will follow immediately.
- (void)setActivityStateOrNil:(NSNumber *)activityStateOrNil
{
int activityState = [activityStateOrNil intValue];
if (activityStateOrNil != nil && activityState != _activityState) {
_activityState = activityState;
[_reactSuperview markChildUpdated];
}
Expand Down Expand Up @@ -476,7 +481,8 @@ @implementation RNSScreenManager

RCT_EXPORT_MODULE()

RCT_EXPORT_VIEW_PROPERTY(activityState, int)
// we want to handle the case when activityState is nil
RCT_REMAP_VIEW_PROPERTY(activityState, activityStateOrNil, NSNumber)
RCT_EXPORT_VIEW_PROPERTY(gestureEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(replaceAnimation, RNSScreenReplaceAnimation)
RCT_EXPORT_VIEW_PROPERTY(stackPresentation, RNSScreenStackPresentation)
Expand Down
14 changes: 7 additions & 7 deletions ios/RNSScreenContainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,13 @@ - (void)updateContainer
if (screenRemoved || screenAdded) {
// we disable interaction for the duration of the transition until one of the screens changes its state to "onTop"
self.userInteractionEnabled = NO;
for (RNSScreenView *screen in _reactSubviews) {
if (screen.activityState == RNSActivityStateOnTop) {
// if there is an "onTop" screen it means the transition has ended so we restore interactions
self.userInteractionEnabled = YES;
[screen notifyFinishTransitioning];
}
}

for (RNSScreenView *screen in _reactSubviews) {
if (screen.activityState == RNSActivityStateOnTop) {
// if there is an "onTop" screen it means the transition has ended so we restore interactions
self.userInteractionEnabled = YES;
[screen notifyFinishTransitioning];
}
}

Expand Down

0 comments on commit 9358d45

Please sign in to comment.