-
-
Notifications
You must be signed in to change notification settings - Fork 241
feat(modals): easier ViewContainerRef handling #1546
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
Comments
This is the dreaded error that occurs on iOS:
Which means your app is now dead and you can no longer open modals at all and in most cases you can't use the app anymore. |
Fundamentally I think part of the issue is in core modules and could be an iOS race condition: |
@NathanWalker The ability to pass different We all agree that opening a modal right now brings with itself a lot of boilerplate code that is not really needed. At the same time we want to provide openness to the API, so that a lot of modal and navigation patterns are supported. Perhaps we should rethink this approach and provide different APIs for the different scenarios. That being said, the error you get "ViewHierarchy: Parent page is not part of the window hierarchy. Close the current modal page before showing another one!" means that you are passing a |
See comments in the PR @MartoYankov thanks for investigating with me 👍 |
Does this mean that if I have the following configuration:
the modal presents correctly and the The most common use case I see for this is a login modal which has registration and password recovery as accessory pages. You'd want for the modal to be able to display all of these and hence setup routing. |
@tiagoblackcode The component that you pass to the |
Yes, I understand that. The However, what I was trying to ask was if the modal routes ( IIRC the issue I encountered if the modal routes were not under the caller tree was that when the modal was opened, the underlying page was destroyed and when the modal closed there was a blank page. |
@tiagoblackcode To achieve this you must use angular's named/aux router outlet concept. See this playground example - https://play.nativescript.org/?template=play-ng&id=E6WyBS&v=2. |
And that's what I've been doing. However, you lose two features: 1) animations between modal page transitions; 2) the ability to pass query parameters around. The 2nd one is not that important but the first one has some impact in the user experience IMHO. |
@tiagoblackcode You can navigate between pages in the modal view and there are transitions. I've updated the playground with a navigation inside the modal. See https://play.nativescript.org/?template=play-ng&id=E6WyBS&v=2 . |
@MartoYankov can confirm the animations are working in the playground. I've updated the playground with the navigation within modals: https://play.nativescript.org/?template=play-ng&id=E6WyBS&v=9 . I'm going to double-check what's happening in the project I'm working. Thank you very much for taking the time. |
So, in my previous configuration I had modal pages lazy-loaded with the following configuration:
With this configuration, the "root" route has the outlet declaration while the child routes don't. While the modals work just fine, the animations don't. Later, I tried eager loading the routes still nested under a "root" route similar to the above, but with the e.g.
Lastly, I've added the So, in conclusion:
Edit: updated a use case Kind Regards, |
@tiagoblackcode The issues you reported are known. They all boil down to nesting named/aux outlets. There is a PR that should fix them - #1556. The issue with lazy loading aux/named outlets is a curios one. The reason why you don't have animations is because Angular is injecting a basic router-outlet in this case. This outlet doesn't have a page, action bar or transitions. The PR will allow a workaround for that. |
Makes sense it doesn't work like that. I didn't know Angular added a Nice one! Gonna see if I can test it :) |
I have a fix for error "ViewHierarchy: Parent page is not part of the window hierarchy." with no previous modal open - just warp your showModal line with a setTimeout. Here's a working example. setTimeout(() => {
view.showModal('path-to-your-modal', optionsShow) // WATCHOUT - no error if page doesn't exist and no modal will open
}, 0) |
Is your feature request related to a problem? Please describe.
Not yet but may create a problem for it (likely related to several other reported issues in all sorts of subtle ways).
Describe the solution you'd like
Right now in order to open a modal you must pass the proper
ViewContainerRef
. This is simply error prone, not versatile and frustrating for sophisticated app development at scale.Describe alternatives you've considered
Keeping track of the current
ViewContainerRef
via a service. This works in a majority of cases but due to race conditions and various asynchronous contexts this has been found to be not reliable. Simply put: requiring developers to use aViewContainerRef
to simply open a modal is highly frustrating.Additional context
I haven't investigated refactoring modal handling just yet but plan to. There must be a way to handle modals without dealing with
ViewContainerRef
at all or rather the framework could open modals in the right context all the time without leaving it up for the developer to keep track of it since it has been found to be so error prone./cc @ADjenkov @vakrilov @sis0k0
The text was updated successfully, but these errors were encountered: