RedAlert 1.2 → 1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a17fdee3c942135d661b71f10e02a3fa7c897945
4
- data.tar.gz: 3b1d14668db687b50e4f7f0005246f93dc08b52f
3
+ metadata.gz: 02b0f4505dfe14f9f67e9c99070dff3b86ca4a5c
4
+ data.tar.gz: bf71b9ea2ca435a52add2bf6f55a5072c7a22f1c
5
5
  SHA512:
6
- metadata.gz: d9e215e14fa0911d4c5f5e10226ddf7867457637f255635f4f767faa80604afd86964c9d1dede48e5f0a7e1ea87cac7c281f3174f3eb3ad427e5c31c6b25ad5f
7
- data.tar.gz: 3129e78629f9b47b6ef29dba0cc6e983dfda0cd322885b9a72b96e26325bf84b6e46759c37a9cca57a95dd8723c98db72f58251f3b7a1d20bfc4fa6afa5882d5
6
+ metadata.gz: af89a90bf422ae0cc3fb8047477b6e296b8f23328add78bae48d4053b51fdbf8395db3845e9ef32d351e2f656d0021fb35b338bd5309931ba6d087cf4b9b18f1
7
+ data.tar.gz: 9250c0b48d2d9cf6d5c36b1b988e2299e78ad52d19e0b9e6b5f6557150872dc43fcc32b67f83358e6383615592d3423eb862ceccc904952223238de7d6b8320c
data/README.md CHANGED
@@ -99,6 +99,20 @@ You can even use the `make_button` helper to create custom buttons to add:
99
99
  rmq.app.alert(title: "Actions!", message: "Actions created with `make_button` helper.", actions: button_list)
100
100
  ```
101
101
 
102
+
103
+ If you want to present your alert in :sheet style and you are on iPad, you have to provide the `:source` for the popover (either a UIView or a UIBarButtonItem)
104
+ ```ruby
105
+ rmq.append(UIButton, :my_button).on(:tap) do |sender|
106
+ rmq.app.alert(title: "Actions!", message: "Alert from a Popover.", actions: [:ok, :cancel], style:sheet, source: sender)
107
+ end
108
+ ```
109
+
110
+ *iOS 8+ options*
111
+ These options work only on iOS 8+
112
+ * `:modal` will prevent the popover to be close by tapping outside the popover
113
+ * `:arrow_direction` will force the direction of the popover arrow. Valid values are `:up`, `:down`, `:left`, `:right` or `:any`
114
+
115
+
102
116
  ## Available Templates
103
117
 
104
118
  Button templates are provided [HERE](https://github.com/GantMan/RedAlert/blob/master/lib/project/button_templates.rb)
@@ -143,6 +157,8 @@ Because capabilities of iOS 7 & 8 alert-components are different, just a few edg
143
157
 
144
158
  **Ability to add textfields to alerts (Like Username/Password) by [Derek Greenberg](https://github.com/GantMan/RedAlert/pull/10) and notable work by [Jon Silverman](https://github.com/GantMan/RedAlert/pull/9)**
145
159
 
160
+ **iPad and popover support by [Benjamin Michotte](https://github.com/GantMan/RedAlert/pull/17)**
161
+
146
162
  Feel free to read up on UIAlertController to see what all is wrapped up in this gem.
147
163
  * [Hayageek](http://hayageek.com/uialertcontroller-example-ios/)
148
164
  * [NSHipster](http://nshipster.com/uialertcontroller/)
@@ -10,6 +10,8 @@ module RubyMotionQuery
10
10
  @actions = actions
11
11
  @opts = opts
12
12
 
13
+ raise ArgumentError.new "Please provide a :source view to use :sheet on iPad" if rmq.device.ipad? and !@opts[:source]
14
+
13
15
  # grab the first cancel action
14
16
  cancel_action = actions.find { |action| action.cancel? }
15
17
 
@@ -43,7 +45,17 @@ module RubyMotionQuery
43
45
  def show
44
46
  # when we show, the view controller will disappear because a different _UIAlertOverlayWindow window will take its place
45
47
  @view_controller = rmq.view_controller
46
- @action_sheet.showInView(@view_controller.view)
48
+
49
+ if rmq.device.ipad?
50
+ source = @opts[:source]
51
+ if source.is_a?(UIBarButtonItem)
52
+ @action_sheet.showFromBarButtonItem(source, animated: true)
53
+ else
54
+ @action_sheet.showFromRect(source.frame, inView: @view_controller.view, animated: true)
55
+ end
56
+ else
57
+ @action_sheet.showInView(@view_controller.view)
58
+ end
47
59
  end
48
60
 
49
61
  private
@@ -12,5 +12,13 @@ module RubyMotionQuery
12
12
  destructive: UIAlertActionStyleDestructive
13
13
  }
14
14
 
15
+ ALERT_POPOVER_ARROW_DIRECTION = {
16
+ up: UIPopoverArrowDirectionUp,
17
+ down: UIPopoverArrowDirectionDown,
18
+ left: UIPopoverArrowDirectionLeft,
19
+ right: UIPopoverArrowDirectionRight,
20
+ any: UIPopoverArrowDirectionAny
21
+ }
22
+
15
23
  end
16
- end
24
+ end
@@ -47,6 +47,34 @@ module RubyMotionQuery
47
47
  @alert_controller.addAction action
48
48
  end
49
49
 
50
+ # popover
51
+ if @opts[:style] == :sheet and rmq.device.ipad?
52
+ raise ArgumentError.new "Please provide a :source view to use :sheet on iPad" unless @opts[:source]
53
+ source = @opts[:source]
54
+ @alert_controller.setModalPresentationStyle(UIModalPresentationPopover)
55
+ if @opts[:modal]
56
+ @alert_controller.setModalInPopover(true)
57
+ end
58
+ if source.is_a?(UIBarButtonItem)
59
+ @alert_controller.popoverPresentationController.barButtonItem = source
60
+ else
61
+ @alert_controller.popoverPresentationController.sourceView = source
62
+ end
63
+ @alert_controller.popoverPresentationController.sourceRect = source.bounds
64
+
65
+ if @opts[:arrow_direction]
66
+ directions = @opts[:arrow_direction]
67
+ unless directions.is_a?(Array)
68
+ directions = [directions]
69
+ end
70
+ arrow_direction = 0
71
+ directions.each do |direction|
72
+ arrow_direction |= RubyMotionQuery::AlertConstants::ALERT_POPOVER_ARROW_DIRECTION[direction]
73
+ end
74
+ @alert_controller.popoverPresentationController.permittedArrowDirections = arrow_direction
75
+ end
76
+ end
77
+
50
78
  self
51
79
  end
52
80
 
@@ -6,7 +6,7 @@ module RubyMotionQuery
6
6
  # 2 - Add the test
7
7
  # 3 - Add symbol to the README.md list
8
8
 
9
- def self.add_template_fieldset(template)
9
+ def self.add_template_fieldset(template, opts={})
10
10
 
11
11
  login = NSLocalizedString("Login", nil)
12
12
  password = NSLocalizedString("Password", nil)
@@ -19,13 +19,13 @@ module RubyMotionQuery
19
19
  fieldset[:alert_view_style] = UIAlertViewStylePlainTextInput
20
20
  fieldset[:fields] =
21
21
  [
22
- rmq.app.make_field(:text, keyboard_type: :default, secure_text_entry: false, placeholder: '')
22
+ rmq.app.make_field(:text, keyboard_type: :default, secure_text_entry: false, placeholder: opts.fetch(:placeholder,''))
23
23
  ]
24
24
  when :secure
25
25
  fieldset[:alert_view_style] = UIAlertViewStyleSecureTextInput
26
26
  fieldset[:fields] =
27
27
  [
28
- rmq.app.make_field(:text, keyboard_type: :default, secure_text_entry: true, placeholder: '')
28
+ rmq.app.make_field(:text, keyboard_type: :default, secure_text_entry: true, placeholder: opts.fetch(:placeholder,''))
29
29
  ]
30
30
  when :login
31
31
  fieldset[:alert_view_style] = UIAlertViewStyleLoginAndPasswordInput
@@ -19,8 +19,17 @@ module RubyMotionQuery
19
19
  # ------------------------------------
20
20
  opts = {message: opts} if opts.is_a? String
21
21
  opts = {style: :alert, animated: true, show_now: true}.merge(opts)
22
- opts[:message] = opts[:message] ? opts[:message].to_s : NSLocalizedString("Alert!", nil)
22
+ # Ability to make no message
23
+ opts[:message] = if opts.has_key?(:message)
24
+ opts[:message].nil? ? nil : opts[:message].to_s
25
+ else
26
+ NSLocalizedString("Alert!", nil)
27
+ end
28
+
23
29
  opts[:style] = VALID_STYLES.include?(opts[:style]) ? opts[:style] : :alert
30
+ if opts[:style] == :sheet and rmq.device.ipad? and opts[:source].nil?
31
+ raise ArgumentError.new "Please provide a :source view to use :sheet on iPad"
32
+ end
24
33
  opts[:fields] = opts[:style] == :custom && opts[:fields] ? opts[:fields] : {text: {placeholder: ''}}
25
34
  api = rmq.device.ios_at_least?(8) ? :modern : :deprecated
26
35
  api = :deprecated if rmq.device.ios_at_least?(8) && opts[:api] == :deprecated
@@ -47,7 +56,7 @@ module RubyMotionQuery
47
56
  fieldset = {alert_view_style: UIAlertViewStyleDefault, fields: []}
48
57
 
49
58
  if TEMPLATE_FIELD_STYLES.include?(opts[:style])
50
- fieldset = add_template_fieldset(opts[:style])
59
+ fieldset = add_template_fieldset(opts[:style], opts)
51
60
  elsif opts[:style] == :custom
52
61
  fieldset = custom_fieldset(opts[:api], opts[:fields])
53
62
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: RedAlert
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: '1.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gant Laborde
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-23 00:00:00.000000000 Z
11
+ date: 2015-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby_motion_query