class Motion::Alert
Attributes
actions[RW]
message[RW]
presenter[RW]
title[RW]
type[RW]
Public Class Methods
instance()
click to toggle source
# File lib/project/motion_alert.rb, line 9 def self.instance Dispatch.once { @instance ||= alloc.init } @instance end
new(options = {})
click to toggle source
# File lib/project/motion_alert.rb, line 14 def self.new(options = {}) instance.tap do |i| i.title = options.fetch(:title, nil) i.message = options.fetch(:message, nil) i.type = options.fetch(:type, :alert) i.presenter = options.fetch(:presenter, UIApplication.sharedApplication.keyWindow.rootViewController) i.actions = Option.new end end
Public Instance Methods
selected(index)
click to toggle source
# File lib/project/motion_alert.rb, line 28 def selected(index) actions[index].choose end
show()
click to toggle source
# File lib/project/motion_alert.rb, line 24 def show show_as_controller || show_as_alert || show_as_action_sheet end
Private Instance Methods
action_sheet()
click to toggle source
# File lib/project/motion_alert.rb, line 82 def action_sheet UIActionSheet.alloc.initWithTitle( title, delegate: UIApplication.sharedApplication.delegate, cancelButtonTitle: nil, destructiveButtonTitle: nil, otherButtonTitles: nil ) end
alert_controller()
click to toggle source
# File lib/project/motion_alert.rb, line 53 def alert_controller UIAlertController.alertControllerWithTitle( title, message: message, preferredStyle: style ) end
alert_view()
click to toggle source
# File lib/project/motion_alert.rb, line 72 def alert_view UIAlertView.alloc.initWithTitle( title, message: message, delegate: UIApplication.sharedApplication.delegate, cancelButtonTitle: nil, otherButtonTitles: nil ) end
can_show_controller?()
click to toggle source
# File lib/project/motion_alert.rb, line 92 def can_show_controller? !!UIDevice.currentDevice.systemVersion.match("^8") end
show_as_action_sheet()
click to toggle source
# File lib/project/motion_alert.rb, line 49 def show_as_action_sheet self.actions.attach_to(action_sheet).showInView(presenter.view) end
show_as_alert()
click to toggle source
# File lib/project/motion_alert.rb, line 43 def show_as_alert if type == :alert self.actions.attach_to(alert_view).show end end
show_as_controller()
click to toggle source
# File lib/project/motion_alert.rb, line 34 def show_as_controller return nil if !can_show_controller? alert_controller.tap do |alert| self.actions.attach_to(alert) presenter.presentViewController(alert, animated: false, completion: nil) end end
style()
click to toggle source
# File lib/project/motion_alert.rb, line 61 def style case type when :alert UIAlertControllerStyleAlert when :action_sheet UIAlertControllerStyleActionSheet else UIAlertControllerStyleAlert end end