motion/mail/mail.rb in bubble-wrap-1.6.0 vs motion/mail/mail.rb in bubble-wrap-1.7.0

- old
+ new

@@ -4,48 +4,56 @@ module_function # Base method to create your in-app mail # --------------------------------------- # EX - # BW::Mail.compose { + # BW::Mail.compose( # delegate: self, # optional, will use root view controller by default # to: [ "tom@example.com" ], # cc: [ "itchy@example.com", "scratchy@example.com" ], # bcc: [ "jerry@example.com" ], # html: false, # subject: "My Subject", # message: "This is my message. It isn't very long.", # animated: false - # } do |result, error| + # ) do |result, error| # result.sent? # => boolean # result.canceled? # => boolean # result.saved? # => boolean # result.failed? # => boolean # error # => NSError # end - def compose(options={}, &callback) - @delegate = options[:delegate] || App.window.rootViewController + def compose(options = {}, &callback) + options = { + delegate: App.window.rootViewController, + animated: true, + html: false, + to: [], + cc: [], + bcc: [], + subject: 'Contact' + }.merge(options) + @delegate = options[:delegate] + @mailer_is_animated = options[:animated] @callback = callback @callback.weak! if @callback && BubbleWrap.use_weak_callbacks? - + @mail_controller = create_mail_controller(options) - - @mailer_is_animated = options[:animated] == false ? false : true + @delegate.presentViewController(@mail_controller, animated: @mailer_is_animated, completion: options[:completion]) end - - def create_mail_controller(options={}) + + def create_mail_controller(options = {}) mail_controller = MFMailComposeViewController.alloc.init - + mail_controller.mailComposeDelegate = self mail_controller.setToRecipients(Array(options[:to])) mail_controller.setCcRecipients(Array(options[:cc])) mail_controller.setBccRecipients(Array(options[:bcc])) - mail_controller.setSubject(options[:subject] || "Contact") - is_html = !!options[:html] - mail_controller.setMessageBody(options[:message], isHTML: is_html) - + mail_controller.setSubject(options[:subject]) + mail_controller.setMessageBody(options[:message], isHTML: !!options[:html]) + mail_controller end # Event when the MFMailComposeViewController is closed # -------------------------------------------------------------