Class: RubyMotionQuery::AlertViewProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/project/alert_view_provider.rb

Overview

Brings the venerable iOS 7 AlertView to RedAlert.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#alert_viewObject

Returns the value of attribute alert_view.



6
7
8
# File 'lib/project/alert_view_provider.rb', line 6

def alert_view
  @alert_view
end

Instance Method Details

#build(actions, fieldset = nil, opts = {}) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/project/alert_view_provider.rb', line 8

def build(actions, fieldset=nil, opts={})
  raise ArgumentError.new("At least 1 action is required.") unless actions && actions.length > 0
  @actions = actions
  @opts = opts

  # grab the first cancel action
  cancel_action = actions.find { |action| action.cancel? }

  # grab all the default & destructive buttons
  @actions_in_display_order = actions.find_all { |action| action.default? || action.destructive? }
  @actions_in_display_order << cancel_action if cancel_action

  # create a buttonless UIAlertView
  @alert_view = UIAlertView.alloc.initWithTitle @opts[:title], message: @opts[:message], delegate: self, cancelButtonTitle: nil, otherButtonTitles: nil

  # then bring in our buttons in order
  @actions_in_display_order.each { |action| @alert_view.addButtonWithTitle action.title }

  # mark where our special buttons are
  @alert_view.cancelButtonIndex = @actions_in_display_order.length-1 if cancel_action

  # add our text fields and build up the callback hash
  @text_fields = {}

  if fieldset
    @alert_view.alertViewStyle = fieldset[:alert_view_style]
    fieldset[:fields].each_with_index do |field, index|
      text_field = @alert_view.textFieldAtIndex index
      text_field.placeholder = field.placeholder
      text_field.secureTextEntry = field.secure_text_entry
      text_field.keyboardType = RubyMotionQuery::Stylers::KEYBOARD_TYPES[field.keyboard_type]
      @text_fields[field.name] = text_field
    end
  end

  self
end

#showObject



46
47
48
49
50
# File 'lib/project/alert_view_provider.rb', line 46

def show
  # NOTE: when we show, the view controller will disappear because a different _UIAlertOverlayWindow window will take its place
  @view_controller = rmq.view_controller
  @alert_view.show
end