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

fix: check if activityState is nil #714

Merged
merged 4 commits into from
Nov 19, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

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

Would be great to document it somewhere in the code the purpose of special handling nil value and also explain when nil can be provided. That is we should mention that nil will be provided when activityState it is set as an animated value and we change it from JS to be a plain value (non animated). I understand that in this scenario we first trigger the code which resets it to the default, which is nil, and which maps to 0 meaning Inactive. In that case we want to ignore such update as soon after we get the actual state passed from JS.

{
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