-
-
Notifications
You must be signed in to change notification settings - Fork 241
Update modal to allow use of ios presentationStyle #1767
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { | |
ReflectiveInjector, | ||
Type, | ||
ViewContainerRef, | ||
ElementRef, | ||
} from "@angular/core"; | ||
|
||
import { NSLocationStrategy } from "../router/ns-location-strategy"; | ||
|
@@ -26,6 +27,8 @@ export interface ModalDialogOptions { | |
stretched?: boolean; | ||
viewContainerRef?: ViewContainerRef; | ||
moduleRef?: NgModuleRef<any>; | ||
sourceView?: ElementRef; | ||
ios?: any; | ||
} | ||
|
||
export class ModalDialogParams { | ||
|
@@ -46,15 +49,17 @@ interface ShowDialogOptions { | |
parentView: ViewBase; | ||
resolver: ComponentFactoryResolver; | ||
type: Type<any>; | ||
ios?: any; | ||
} | ||
|
||
@Injectable() | ||
export class ModalDialogService { | ||
private componentView: View; | ||
constructor(private location: NSLocationStrategy) { | ||
} | ||
|
||
public showModal(type: Type<any>, | ||
{ viewContainerRef, moduleRef, context, fullscreen, animated, stretched }: ModalDialogOptions | ||
{ viewContainerRef, moduleRef, context, fullscreen, animated, stretched, sourceView, ios }: ModalDialogOptions | ||
): Promise<any> { | ||
if (!viewContainerRef) { | ||
throw new Error( | ||
|
@@ -63,7 +68,11 @@ export class ModalDialogService { | |
); | ||
} | ||
|
||
let parentView = viewContainerRef.element.nativeElement; | ||
if (sourceView) { | ||
this.closeModal(); | ||
} | ||
|
||
let parentView = sourceView ? sourceView.nativeElement : viewContainerRef.element.nativeElement; | ||
if (parentView instanceof AppHostView && parentView.ngAppRoot) { | ||
parentView = parentView.ngAppRoot; | ||
} | ||
|
@@ -103,6 +112,7 @@ export class ModalDialogService { | |
parentView, | ||
resolver, | ||
type, | ||
ios | ||
}); | ||
} catch (err) { | ||
reject(err); | ||
|
@@ -111,6 +121,13 @@ export class ModalDialogService { | |
}); | ||
} | ||
|
||
public closeModal() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remove this method. After locally testing and reviewing this PR I discovered a bug (NativeScript/NativeScript#7050) that when fixed will resolve this issue you are working around with this code so it is not needed. |
||
if (this.componentView) { | ||
this.componentView.closeModal(); | ||
this.location._closeModalNavigation(); | ||
} | ||
} | ||
|
||
private _showDialog({ | ||
containerRef, | ||
context, | ||
|
@@ -122,6 +139,7 @@ export class ModalDialogService { | |
parentView, | ||
resolver, | ||
type, | ||
ios | ||
}: ShowDialogOptions): void { | ||
let componentView: View; | ||
let detachedLoaderRef: ComponentRef<DetachedLoader>; | ||
|
@@ -159,7 +177,13 @@ export class ModalDialogService { | |
|
||
// TODO: remove <any> cast after https://github.com/NativeScript/NativeScript/pull/5734 | ||
// is in a published version of tns-core-modules. | ||
(<any>parentView).showModal(componentView, context, closeCallback, fullscreen, animated, stretched); | ||
if (ios) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As already mentioned, the code in the else is being deprecated and is not longer needed. You could simply do:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've made the changes but based it on this PR #1769 as I think that's a better way to do it and will mean we don't have to keep adding options to match the core. |
||
// tslint:disable-next-line:max-line-length | ||
(<any>parentView).showModal(componentView, { context, closeCallback, fullscreen, animated, stretched, ios }); | ||
} else { | ||
(<any>parentView).showModal(componentView, context, closeCallback, fullscreen, animated, stretched); | ||
} | ||
this.componentView = componentView; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remove this method. After locally testing and reviewing this PR I discovered a bug (NativeScript/NativeScript#7050) that when fixed will resolve this issue you are working around with this code so it is not needed. |
||
}); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this probably breaks multiple modals, as it stores only one componentview