EddyVerbruggen / nativescript-email

:envelope: NativeScript plugin for opening draft e-mails
MIT License
47 stars 15 forks source link

IOS: Email compose not opening when called from modal #30

Closed FBorgonjen closed 5 years ago

FBorgonjen commented 6 years ago

When trying to open the email window from within a modal window we are getting an error and no email window. Our app is using a TabView as bootstrap component. From the tabview component a modal is opened showing a login page. From this page we have a button which calls the email.compose method. The error we get is: Warning: Attempt to present <MFMailComposeViewController: 0x103cfc400> on <UITabBarControllerImpl: 0x103caac00> whose view is not in the window hierarchy!

It looks like there is a clash betwee the window that opens the login-modal and the email-window.

If we call the exact same code from outside a modal window (inside one of the tabview pages) the code works as expected.

We are on:

EddyVerbruggen commented 6 years ago

Interesting find. Try playing around with this line in node_modules/nativescript-email.. perhaps you can find a way to fix it:

https://github.com/EddyVerbruggen/nativescript-email/blob/6d6880c5db755628eb1ef76ef40bc9d2105fa4ec/email.ios.js#L97

FBorgonjen commented 6 years ago

Thanks for your quick response. I will fiddle with this piece of code and post my findings here

Robsta84 commented 5 years ago

It's not the default behavior of an iOS app to call the mail composer from a modal view. A workaround is to dismiss the modal view after tapping on the mail button and in the closeCallback() you can now open the mail composer.

msaravitz commented 5 years ago

Fixed in version 1.5.4

buuhuu commented 5 years ago

This only works when the modal was opened using the topmost() frame as parent. If it was opened differently it will fail. For example we open a Modal based on an event in our AppComponent

const options: ModalDialogOptions = {
  context: { config },
   fullscreen: true,
   viewContainerRef: this._vcRef, // ViewContainerRef injected into AppComponent
   target: topmost() // this needs to be added otherwise it doesn't work 
};

this._modalService.showModal(MyModalComponent, options);