File tree Expand file tree Collapse file tree
packages/angular/src/lib/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,11 +12,24 @@ import { Application, View } from '@nativescript/core';
1212 * @param modalView The view that was passed to `showModal()`.
1313 */
1414export function didModalOpen ( parentView : View , modalView : View ) : boolean {
15- // On a successful present, core synchronously sets the parent's `modal` to the modal view.
16- if ( parentView && parentView . modal === modalView ) {
15+ // Fast path: on a successful present, core sets `_modalParent` on the modal view itself,
16+ // so we can confirm in O(1) without walking the view tree in the common (success) case.
17+ if ( modalView && ( modalView as { _modalParent ?: View } ) . _modalParent ) {
1718 return true ;
1819 }
1920
21+ // Slow path (real confirmation): core sets `modal` to the modal view on the parent that owns
22+ // a native view controller/fragment. On Android that's the exact `parentView`, but on iOS core
23+ // walks up to the first ancestor with a view controller and sets it there, so we walk the
24+ // parent chain to cover both platforms.
25+ let view : View = parentView ;
26+ while ( view ) {
27+ if ( view . modal === modalView ) {
28+ return true ;
29+ }
30+ view = view . parent as View ;
31+ }
32+
2033 // On Android, presenting while the app is backgrounded and the parent isn't loaded is
2134 // deferred until the parent loads again rather than failing, so treat it as opened.
2235 if ( global . isAndroid && Application . inBackground && parentView && ! parentView . isLoaded ) {
You can’t perform that action at this time.
0 commit comments