Skip to content

Commit

Permalink
Merge pull request #33 from msaravitz/fix-compose-from-modal-ios
Browse files Browse the repository at this point in the history
fix(ios-compose): allow compose modal to open from a modal
  • Loading branch information
EddyVerbruggen authored Jun 17, 2019
2 parents d1180d5 + 07dd198 commit 45c10c8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions email.ios.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var fs = require("tns-core-modules/file-system");
var utils = require("tns-core-modules/utils/utils");
var frame = require("tns-core-modules/ui/frame");

var _isEmailAvailable = null;

Expand Down Expand Up @@ -45,6 +46,19 @@ exports.compose = function (arg) {
return;
}

var topMostFrame = frame.topmost();
if (topMostFrame) {
var viewController = topMostFrame.currentPage && topMostFrame.currentPage.ios;
if (viewController) {
while (viewController.parentViewController) {
viewController = viewController.parentViewController;
}
while (viewController.presentedViewController) {
viewController = viewController.presentedViewController;
}
}
}

var mail = MFMailComposeViewController.new();

var message = arg.body;
Expand Down Expand Up @@ -84,7 +98,7 @@ exports.compose = function (arg) {
// invoke the callback / promise
resolve(result == MFMailComposeResultSent);
// close the mail
app.keyWindow.rootViewController.dismissViewControllerAnimatedCompletion(true, null);
viewController.dismissViewControllerAnimatedCompletion(true, null);
// release the delegate instance
CFRelease(delegate);
});
Expand All @@ -94,7 +108,7 @@ exports.compose = function (arg) {

mail.mailComposeDelegate = delegate;

app.keyWindow.rootViewController.presentViewControllerAnimatedCompletion(mail, true, null);
viewController.presentViewControllerAnimatedCompletion(mail, true, null);

} catch (ex) {
console.log("Error in email.compose: " + ex);
Expand Down

0 comments on commit 45c10c8

Please sign in to comment.