lib/ios/sugarcube-factories/uialertcontroller.rb in sugarcube-3.4.2 vs lib/ios/sugarcube-factories/uialertcontroller.rb in sugarcube-3.5.0

- old
+ new

@@ -93,9 +93,26 @@ handler: proc { |_| sugarcube_handler.call(title) unless sugarcube_handler.nil? }) addAction action end + + def self.prompt(controller, title, options = {}, more_options = {}, &block) + text_fields = [] + + alert = UIAlertController.alert(controller, title, options.merge(show: false), more_options) do |result| + next block.call(text_fields.first.text) if result == 'OK' + next block.call(nil) + end + + alert.addTextFieldWithConfigurationHandler(->(s){ text_fields << s }) + + if options.fetch(:show, true) + controller.presentViewController(alert, animated: true, completion: nil) + end + + alert + end end module SugarCube class UIAlertControllerCallbackHelper