Skip to content

fix(core): iOS app not responding after rotation - #9931

Merged
NathanWalker merged 2 commits into
NativeScript:masterfrom
dgmachado:fix/ios-app-not-responding-after-rotate
Jun 15, 2022
Merged

NathanWalker merged 2 commits into
NativeScript:masterfrom
dgmachado:fix/ios-app-not-responding-after-rotate

Conversation

@dgmachado

@dgmachado dgmachado commented Jun 6, 2022 •

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

The iOS app isn't responding after rotation. The issue is only reproducible on the iOS phone. Cannot be reproduced on an iOS tablet.

The issue can be reproduced immediately (after the first rotation) on the nested tabs scenario.

Could be reproduced on tabs scenario as well after multiple rotations and switch tabs in between.

When the issue happens, the UI appears to be cut into half and it's not responding at all.

iphone_tabs_issue_after_rotate.mov

What is the new behavior?

Fix the infinite loop that was occurring after successive rotations of the app so now the app is no longer getting stuck.

@cla-bot cla-bot Bot added the cla: yes label Jun 6, 2022
@NathanWalker
NathanWalker merged commit aee1d05 into NativeScript:master Jun 15, 2022
@CatchABus

Copy link
Copy Markdown
Contributor

@dgmachado It seems this change causes other issues similar to the one you described.
More specifically, there is a case of infinite loop as described in ticket #9962
I tried the provided sample with an iPhone 12 simulator and confirmed the validity of this report.

It seems there are cases that additionalSafeAreaInsets receive new values over and over resulting in calling viewSafeAreaInsetsDidChange and ending up in an infinite loop.

Is it possible that you post an app sample with your case? Perhaps, we can fix this using another approach.

@dgmachado

dgmachado commented Aug 2, 2022 •

Copy link
Copy Markdown
Contributor Author

@CatchABus I found out last week that my change doesn't fix the infinite loop even for my scenario. It's just a lot harder to reproduce the issue. Let me share with you an app sample with my case testPopover_tabBar5.zip

And about your comment "It seems there are cases that additionalSafeAreaInsets receive new values over and over resulting in calling viewSafeAreaInsetsDidChange and ending up in an infinite loop." that's exactly the same thing I was getting frequently before my change.

Is it possible you also share an app sample with your case?

@CatchABus

CatchABus commented Aug 2, 2022 •

Copy link
Copy Markdown
Contributor

@CatchABus I found out last week that my change doesn't fix the infinite loop even for my scenario. It's just a lot harder to reproduce the issue. Let me share with you an app sample with my case testPopover_tabBar5.zip

And about your comment "It seems there are cases that additionalSafeAreaInsets receive new values over and over resulting in calling viewSafeAreaInsetsDidChange and ending up in an infinite loop." that's exactly the same thing I was getting frequently before my change.

Is it possible you also share an app sample with your case?

Thank you very much for this! I'll also use your sample and see what I can find.
Member who reported the other case has included an app sample and a reproduction video in #9962

NathanWalker added a commit that referenced this pull request Aug 2, 2022
@dgmachado

dgmachado commented Aug 2, 2022 •

Copy link
Copy Markdown
Contributor Author

@CatchABus I just tested your app using the "@nativescript/core@8.2.4" and "@nativescript/core@8.2.0" to ensure the #9931 wasn't included and I could reproduce this same issue using simulator iPhone 8 (iOS 15.2).

Video showing the infinite loop (Obs: it's an intermittent bug)

@NathanWalker could confirm but I'm almost sure the #9931 was merged into the 8.2.5 version only.

@CatchABus

CatchABus commented Aug 3, 2022 •

Copy link
Copy Markdown
Contributor

@CatchABus I just tested your app using the "@nativescript/core@8.2.4" and "@nativescript/core@8.2.0" to ensure the #9931 wasn't included and I could reproduce this same issue using simulator iPhone 8 (iOS 15.2).

Video showing the infinite loop (Obs: it's an intermittent bug)

@NathanWalker could confirm but I'm almost sure the #9931 was merged into the 8.2.5 version only.

I believe this is a different case.
In #9962, reporter mentioned everything was good until 8.2.4.
He also had the following output:

***** Fatal JavaScript exception - application has been terminated. *****
NativeScript encountered a fatal error: Uncaught RangeError: Maximum call stack size exceeded
at
UILayoutViewController.updateAdditionalSafeAreaInsetsIfNeeded(file: app/webpack:/@nativescript/template-hello-world-ts/node_modules/@nativescript/core/ui/core/view/view-helper/index.ios.js:61:0)
at UILayoutViewController.viewSafeAreaInsetsDidChange(file: app/webpack:/@nativescript/template-hello-world-ts/node_modules/@nativescript/core/ui/core/view/view-helper/index.ios.js:69:0)
at UILayoutViewController.updateAdditionalSafeAreaInsetsIfNeeded(file: app/webpack:/@nativescript/template-hello-world-ts/node_modules/@nativescript/core/ui/core/view/view-helper/index.ios.js:61:0)
at UILayoutViewController.viewSafeAreaInsetsDidChange(file: app/webpack:/@nativescript/template-hello-world-ts/node_modules/@nativescript/core/ui/core/view/view-helper/index.ios.js:69:0)
at UILayoutViewController.updateAdditionalSafeAreaInsetsIfNeeded(file: app/webpack:/@nativescript/template-hello-world-ts/node_modules/@nativescript/core/ui/core/view/view-helper/index.ios.js:61:0)
at UILayoutViewController.viewSafeAreaInsetsDidChange(file: app/webpack:/@nativescript/template-hello-world-ts/node_modules/@nativescript/core/ui/core/view/view-helper/index.ios.js:69:0)
at UILayoutViewController.updateAdditionalSafeAreaInsetsIfNeeded(file: app/webpack:/@nativescript/template-hello-world-ts/node_modules/@nativescript/core/ui/core/view/view-helper/index.ios.js:61:0)
at UILayoutViewController.viewSafeAreaInsetsDidChange(file: app/webpack:/@nativescript/template-hello-world-ts/node_modules/@nativescript/core/ui/core/view/view-helper/index.ios.js:69:0)
at UILayoutViewController.updateAdditionalSafeAreaInsetsIfNeeded(file: app/webpack:/@nativescript/template-hello-world-ts/node_modules/@nativescript/core/ui/core/view/view-helper/index.ios.js:61:0)
at UILayoutViewController.viewSafeAreaInsetsDidChange(file:///app/vendor.js:2524<…>

So reverting this patch helped solve that RangeError (using iPhone 12 simulator) but I understand it still left your case unsolved.
I'll try to reproduce your own case using your sample and post possible solutions here.

@CatchABus

CatchABus commented Aug 3, 2022 •

Copy link
Copy Markdown
Contributor

@dgmachado Thanks for the app, it was really useful.
I also came to realize that your patch made the issue less frequent which makes it easy to get tricked.

After lots of tests, I came up with my first attempt to solve this which I'd like you to try.

Please modify this line: https://github.com/NativeScript/NativeScript/blob/main/packages/core/ui/core/view/index.ios.ts#L291

And update it to look like this:

// View controllers that need insets calculate it on their own
if (this.viewController || this.iosIgnoreSafeArea) {
	return frame;
}

This small change has a big impact as it enforces a rule that we should not expand or shrink insets to views with view controllers by default.

EDITED:

Another solution which may be more accurate (haven't tested this one yet):

// Check if insets are set by view controller
if (this.viewController && this.viewController.additionalSafeAreaInsets && 
    (this.viewController.additionalSafeAreaInsets.top != 0 || this.viewController.additionalSafeAreaInsets.bottom != 0)) {
        return frame;
}

if (this.iosIgnoreSafeArea) {
        return frame;
}

This covers the cases of NS UILayoutViewController and UIViewControllerImpl which modify additionalSafeAreaInsets.
Perhaps, we should also think of removing that code from view controllers completely, and handle those cases inside applySafeAreaInsets, but that could break other things.

I did few tests in the sample app and infinite loop seems to be gone. If possible, please leave some feedback regarding the efficiency of this fix until we find a better solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants