RedAlert 0.3 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f57e36c4618ec386f9f961c6d09df821d1a46a2
4
- data.tar.gz: 964e64e00ebe8b9ef7cdadaaf7b60fdbc5a7ac63
3
+ metadata.gz: d5b3222e32adab1455a1dbd9abce3f10ce3466e8
4
+ data.tar.gz: 8ef50348c2fae8fc4afca1b9d6265a255eb133e0
5
5
  SHA512:
6
- metadata.gz: d7a8380d44268eb588f128a47c4dad23d2262f57d2b8ca4e61e2b474dfba15a1bd9bc78913fbe9252b5ea1824a45e558f274a582a9cd21fe722cf0199d6b1799
7
- data.tar.gz: 0e78d9602a02a56ff10de0dc9988f53edf1fdc580b79e3eeb2b3720f402d776e673014c1488dfa209b7d674c21f97e2481139768f3221672fae027cb961504e3
6
+ metadata.gz: 92935d5c9fb5daa8135cc3db5e04bd9747209bae99f8d77754febd10fb425d1b27450b159003afc39d538523145280aecd323bdbf01263c6fa6fbc65f7776d80
7
+ data.tar.gz: 4e99da49d1942c5c9a27c86a060e10e88fe8a846988d015a61f1f560e0df707f5285c7cf6828af496b5d64601acf094884f15c3e2133aaaa67a980dce7a25964
data/README.md CHANGED
@@ -1,22 +1,28 @@
1
1
  <img src="./_art/logo.png" alt="RedAlert Logo" width="100" />
2
- [![image](http://ir_wp.s3.amazonaws.com/wp-content/uploads/sites/19/2014/09/rmq_plugin.png)](http://rubymotionquery.com)
2
+ [![image](http://ir_wp.s3.amazonaws.com/wp-content/uploads/sites/19/2014/09/rmq_plugin.png)](http://rubymotionquery.com)
3
3
 
4
4
  # RedAlert
5
5
  [![Gem Version](https://badge.fury.io/rb/RedAlert.svg)](http://badge.fury.io/rb/RedAlert) [![Build Status](https://travis-ci.org/GantMan/RedAlert.svg)](https://travis-ci.org/GantMan/RedAlert) _Alerts and ActionSheets with ease_
6
6
 
7
7
  ### Did you know that UIAlertView and UIActionSheet (as well as their respective delegate protocols) are deprecated in iOS 8?
8
8
 
9
- Apple requests you start using the new `UIAlertController`. This gem is built on `UIAlertController` and RMQ, along with support for antiquated `UIAlertView`s for the gnostalgic.
9
+ Apple requests you start using the new `UIAlertController`. This gem is built on `UIAlertController` and RMQ, along with seemless support for antiquated `UIAlertView`s & `UIActionSheet`s for the gnostalgic.
10
10
 
11
11
  With an emphasis on ease of use, this gem allows you to quickly implement Alerts and Actionsheets in your RMQ RubyMotion applications.
12
12
 
13
+ When run on iOS 8, RedAlert uses `UIAlertController` to present alerts and sheets.
14
+
15
+ When run on iOS 7, RedAlert uses `UIAlertView` present alerts and `UIActionSheet` to present sheets.
16
+
17
+ *:dart: RedAlert Means you don't have to worry about a thing!*
18
+
13
19
  ## Screenshot
14
20
 
15
21
  <img src="./_art/screen.png" alt="Screen Shot" width="500" />
16
22
 
17
23
  ## Installation
18
24
 
19
- **Requires RMQ 1.2.0 or later, and iOS 8 or later**
25
+ **Requires RMQ 1.2.0 or later, and iOS 7 or later**
20
26
 
21
27
  Add the **RedAlert** gem to your Gemfile.
22
28
  ```ruby
@@ -76,33 +82,36 @@ Templates are provided [HERE](https://github.com/GantMan/RedAlert/blob/master/li
76
82
  * `:ok_cancel` = OK button with a separated cancel button.
77
83
  * `:delete_cancel` = Delete button (red) with a separated cancel button.
78
84
 
79
- _More to come:_ be sure to submit a pull-request with your button template needs.
85
+ :heartbeat: _More to come:_ be sure to submit a pull-request with your button template needs.
86
+
87
+
88
+ ## iOS 7 Support
89
+
90
+ If you still need iOS 7, RedAlert has your back.
91
+
92
+ Instead of using iOS 8's UIAlertController, RedAlert will use UIActionSheet to display your sheets and
93
+ UIAlertView to display your views.
94
+
95
+ **With little-to-no changes to your code.**
96
+
97
+ Because capabilities of iOS 7 & 8 alert-components are different, just a few edge cases that might sting you (but nothing critical):
98
+
99
+ * `UIAlertView` doesn't have the concept of :destructive buttons. These will fall back to :default.
100
+ * `UIAlertView` cares about the order of your `:cancel` actions, so `[:ok, :cancel]` is shown different than `[:cancel, :ok]`.
101
+ * `UIActionSheet` also cares about the order. It's possible to put a `:cancel` first, which looks slightly awkward when shown. Try to put `:cancel` last.
102
+ * `UIAlertView`'s `alertViewStyles` are not available through RedAlert as they aren't compatible with iOS 8. You'll have to call that directly.
103
+
80
104
 
81
105
  ## More info
82
106
 
107
+ **i18n support by [Mark Rickert](https://github.com/GantMan/RedAlert/pull/2)**
108
+
109
+ **iOS 7 support by [Steve Kellock](https://github.com/GantMan/RedAlert/pull/3)**
110
+
83
111
  Feel free to read up on UIAlertController to see what all is wrapped up in this gem.
84
112
  * [Hayageek](http://hayageek.com/uialertcontroller-example-ios/)
85
113
  * [NSHipster](http://nshipster.com/uialertcontroller/)
86
114
 
87
- ## Classic UIAlertView Helpers
88
-
89
- If you'd like to still support pre-iOS8, you can easily use `rmq.app.alert_view` with a similar syntax, and instead of actions you'll used the predefined delegates.
90
-
91
- **`UIAlertView` Classic:**
92
- ```ruby
93
- # support the elderly
94
- rmq.app.alert_view("Hey look at this old trick")
95
-
96
- # Still feels like magic!
97
- rmq.app.alert_view({
98
- title: "Hey There",
99
- message: "Check out this complex alert!",
100
- cancel_button: 'Nevermind',
101
- other_buttons: ['Log In'],
102
- delegate: nil,
103
- view_style: UIAlertViewStyleLoginAndPasswordInput
104
- })
105
- ```
106
115
 
107
116
  ## Contributing
108
117
 
@@ -110,4 +119,5 @@ If you'd like to still support pre-iOS8, you can easily use `rmq.app.alert_view`
110
119
  2. Create your feature branch (`git checkout -b my-new-feature`)
111
120
  3. Commit your changes (`git commit -am 'Add some feature'`)
112
121
  4. Push to the branch (`git push origin my-new-feature`)
113
- 5. Create new Pull Request
122
+ 5. Realize no one ever reads this section
123
+ 6. Create new Pull Request
@@ -0,0 +1,62 @@
1
+ module RubyMotionQuery
2
+
3
+ # Brings the "I'm not dead yet" iOS 7 UIActionSheet to RedAlert.
4
+ class ActionSheetProvider
5
+
6
+ attr_reader :action_sheet
7
+
8
+ def build(actions, opts={})
9
+ raise ArgumentError.new "At least 1 action is required." unless actions && actions.length > 0
10
+ @actions = actions
11
+ @opts = opts
12
+
13
+ # grab the first cancel action
14
+ cancel_action = actions.find { |action| action.cancel? }
15
+
16
+ # grab the first destructive action (UIActionSheet only supports one)
17
+ destructive_action = actions.find { |action| action.destructive? }
18
+
19
+ # let's put our actions in the correct display order for our callback
20
+ @actions_in_display_order = actions.find_all { |action| action.default? }
21
+ @actions_in_display_order << destructive_action if destructive_action
22
+ @actions_in_display_order << cancel_action if cancel_action
23
+
24
+ # create our action sheet
25
+ @action_sheet = UIActionSheet.alloc.initWithTitle(
26
+ @opts[:title] || @opts[:message],
27
+ delegate: self,
28
+ cancelButtonTitle: nil,
29
+ destructiveButtonTitle: nil,
30
+ otherButtonTitles: nil
31
+ )
32
+
33
+ # then append our other buttons in later
34
+ @actions_in_display_order.each { |action| @action_sheet.addButtonWithTitle(action.title) }
35
+
36
+ # mark where our special buttons are
37
+ @action_sheet.destructiveButtonIndex = @actions_in_display_order.index { |action| action.destructive? } || -1
38
+ @action_sheet.cancelButtonIndex = @actions_in_display_order.index { |action| action.cancel? } || -1
39
+
40
+ self
41
+ end
42
+
43
+ def show
44
+ # when we show, the view controller will disappear because a different _UIAlertOverlayWindow window will take its place
45
+ @view_controller = rmq.view_controller
46
+ @action_sheet.showInView(@view_controller.view)
47
+ end
48
+
49
+ private
50
+
51
+ # fires when we were dismissed <UIActionSheetDelegate>
52
+ def actionSheet(actionSheet, didDismissWithButtonIndex:buttonIndex)
53
+ # pull from the view controller instance
54
+ @view_controller.dismissViewControllerAnimated @opts[:animated], completion: nil
55
+ action = @actions_in_display_order[buttonIndex]
56
+ action.handler.call(action.tag) if action.handler
57
+ @view_controller = nil # forget the reference
58
+ end
59
+
60
+ end
61
+
62
+ end
@@ -0,0 +1,32 @@
1
+ module RubyMotionQuery
2
+ class AlertAction
3
+
4
+ VALID_STYLES = [:default, :destructive, :cancel]
5
+
6
+ attr_reader :title
7
+ attr_reader :tag
8
+ attr_reader :style
9
+ attr_reader :handler
10
+
11
+ def initialize(opts = {}, &block)
12
+ opts = {title: opts} if opts.is_a? String
13
+ @title = opts[:title] || NSLocalizedString("OK", nil)
14
+ @tag = opts[:tag] || @title.gsub(/\s+/,"_").downcase.to_sym
15
+ @style = VALID_STYLES.include?(opts[:style]) ? opts[:style] : VALID_STYLES.first
16
+ @handler = block if block_given?
17
+ end
18
+
19
+ def default?
20
+ @style == :default
21
+ end
22
+
23
+ def destructive?
24
+ @style == :destructive
25
+ end
26
+
27
+ def cancel?
28
+ @style == :cancel
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,43 @@
1
+ module RubyMotionQuery
2
+
3
+ # The new dual-purpose iOS 8 UIAlertControllerProvider
4
+ class AlertControllerProvider
5
+
6
+ attr_reader :alert_controller
7
+
8
+ def build(actions, opts={})
9
+ raise ArgumentError.new("At least 1 action is required.") unless actions && actions.length > 0
10
+ @actions = actions
11
+ @opts = opts
12
+
13
+ # create our alert controller
14
+ style = RubyMotionQuery::AlertConstants::ALERT_TYPES[@opts[:style]]
15
+ @alert_controller = UIAlertController.alertControllerWithTitle @opts[:title], message:@opts[:message], preferredStyle: style
16
+
17
+ # load up the UIAlertController's actions
18
+ @actions.each do |alert_action|
19
+
20
+ # convert the style
21
+ ios_style = RubyMotionQuery::AlertConstants::ALERT_ACTION_STYLE[alert_action.style]
22
+
23
+ # convert the callback
24
+ handler = lambda do |action|
25
+ alert_action.handler.call(alert_action.tag) unless alert_action.handler.nil?
26
+ end if alert_action.handler
27
+
28
+ # create teh action
29
+ action = UIAlertAction.actionWithTitle alert_action.title, style: ios_style, handler: handler
30
+
31
+ # add it to the UIAlertController
32
+ @alert_controller.addAction action
33
+ end
34
+
35
+ self
36
+ end
37
+
38
+ def show
39
+ rmq.view_controller.presentViewController(@alert_controller, animated: @opts[:animated], completion: nil)
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,50 @@
1
+ module RubyMotionQuery
2
+
3
+ # Brings the venerable iOS 7 AlertView to RedAlert.
4
+ class AlertViewProvider
5
+
6
+ attr_accessor :alert_view
7
+
8
+ def build(actions, opts={})
9
+ raise ArgumentError.new("At least 1 action is required.") unless actions && actions.length > 0
10
+ @actions = actions
11
+ @opts = opts
12
+
13
+ # grab the first cancel action
14
+ cancel_action = actions.find { |action| action.cancel? }
15
+
16
+ # grab all the default & destructive buttons
17
+ @actions_in_display_order = actions.find_all { |action| action.default? || action.destructive? }
18
+ @actions_in_display_order << cancel_action if cancel_action
19
+
20
+ # create a buttonless UIAlertView
21
+ @alert_view = UIAlertView.alloc.initWithTitle @opts[:title], message: @opts[:message], delegate: self, cancelButtonTitle: nil, otherButtonTitles: nil
22
+
23
+ # then bring in our buttons in order
24
+ @actions_in_display_order.each { |action| @alert_view.addButtonWithTitle action.title }
25
+
26
+ # mark where our special buttons are
27
+ @alert_view.cancelButtonIndex = @actions_in_display_order.length-1 if cancel_action
28
+
29
+ self
30
+ end
31
+
32
+ def show
33
+ # NOTE: when we show, the view controller will disappear because a different _UIAlertOverlayWindow window will take its place
34
+ @view_controller = rmq.view_controller
35
+ @alert_view.show
36
+ end
37
+
38
+ private
39
+
40
+ # fires when it is time to dismiss <UIAlertViewDelegate>
41
+ def alertView(alertView, didDismissWithButtonIndex:buttonIndex)
42
+ @view_controller.dismissViewControllerAnimated @opts[:animated], completion: nil
43
+ action = @actions_in_display_order[buttonIndex]
44
+ action.handler.call(action.tag) if action.handler
45
+ @view_controller = nil # forget the reference
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -5,23 +5,41 @@ module RubyMotionQuery
5
5
  # 1 - Add it here
6
6
  # 2 - Add the test
7
7
  # 3 - Add symbol to the README.md list
8
- def self.add_template_actions(uiac, template, &block)
8
+
9
+
10
+ def self.add_template_actions(template, &block)
11
+ yes = NSLocalizedString("Yes", nil)
12
+ no = NSLocalizedString("No", nil)
13
+ cancel = NSLocalizedString("Cancel", nil)
14
+ ok = NSLocalizedString("OK", nil)
15
+ delete = NSLocalizedString("Delete", nil)
16
+
9
17
  case template
10
18
  when :yes_no
11
- uiac.addAction(rmq.app.make_button("Yes", &block))
12
- uiac.addAction(rmq.app.make_button("No", &block))
19
+ [
20
+ rmq.app.make_button(title: yes, tag: :yes, &block),
21
+ rmq.app.make_button(title: no, tag: :no, &block)
22
+ ]
13
23
  when :yes_no_cancel
14
- uiac.addAction(rmq.app.make_button("Yes", &block))
15
- uiac.addAction(rmq.app.make_button("No", &block))
16
- uiac.addAction(rmq.app.make_button({title: "Cancel", style: :cancel}, &block))
24
+ [
25
+ rmq.app.make_button(title: yes, tag: :yes, &block),
26
+ rmq.app.make_button(title: no, tag: :no, &block),
27
+ rmq.app.make_button({title: cancel, tag: :cancel, style: :cancel}, &block)
28
+ ]
17
29
  when :ok_cancel
18
- uiac.addAction(rmq.app.make_button("OK", &block))
19
- uiac.addAction(rmq.app.make_button({title: "Cancel", style: :cancel}, &block))
30
+ [
31
+ rmq.app.make_button(ok, &block),
32
+ rmq.app.make_button({title: cancel, tag: :cancel, style: :cancel}, &block)
33
+ ]
20
34
  when :delete_cancel
21
- uiac.addAction(rmq.app.make_button({title: "Delete", style: :destructive}, &block))
22
- uiac.addAction(rmq.app.make_button({title: "Cancel", style: :cancel}, &block))
35
+ [
36
+ rmq.app.make_button({title: delete, tag: :delete, style: :destructive}, &block),
37
+ rmq.app.make_button({title: cancel, tag: :cancel, style: :cancel}, &block)
38
+ ]
39
+ else
40
+ []
23
41
  end
24
42
  end
25
43
 
26
44
  end
27
- end
45
+ end
@@ -2,21 +2,69 @@ module RubyMotionQuery
2
2
  class App
3
3
  class << self
4
4
 
5
- # Creates and shows the UIAlertController.
5
+ # Creates and shows the UIAlertController (iOS 8) or UIAlertView/UIActionSheet (iOS 7).
6
6
  # Usage Example:
7
7
  # rmq.app.alert(message: "This is a test")
8
8
  # rmq.app.alert(title: "Hey there", message: "Are you happy?")
9
9
  # @return [UIAlertController]
10
- def alert(opts = {}, &block)
11
- # Shortcut: assume a string is the message
12
- opts = {message: opts} if opts.is_a? String
13
-
14
- # An alert is nothing without a message
15
- raise(ArgumentError, "RedAlert alert requires a message") if RubyMotionQuery::RMQ.is_blank?(opts[:message])
16
- # iOS8 and above only for UIAlertController
17
- raise "RedAlert requires iOS8 for alerts. Please try `rmq.app.alert_view`" unless rmq.device.ios_at_least? 8
18
- core_alert(opts, &block)
19
- end
10
+ def alert(opts={}, &block)
11
+
12
+ # ------------------------------------
13
+ # -- Setup sane defaults -------------
14
+ # ------------------------------------
15
+ opts = {message: opts} if opts.is_a? String
16
+ opts = {style: :alert, animated: true, show_now: true}.merge(opts)
17
+ opts[:message] = opts[:message] ? opts[:message].to_s : NSLocalizedString("Alert!", nil)
18
+ opts[:style] = :alert unless opts[:style] == :sheet
19
+ api = rmq.device.ios_at_least?(8) ? :modern : :deprecated
20
+ api = :deprecated if rmq.device.ios_at_least?(8) && opts[:api] == :deprecated
21
+ opts[:api] = api
22
+
23
+ # -----------------------------------------
24
+ # -- Who provides the alerts? -------------
25
+ # -----------------------------------------
26
+ if opts[:api] == :modern
27
+ provider = AlertControllerProvider.new
28
+ else
29
+ if opts[:style] == :alert
30
+ provider = AlertViewProvider.new
31
+ else
32
+ provider = ActionSheetProvider.new
33
+ end
34
+ end
35
+
36
+ # -------------------------------------------------
37
+ # -- Configure the actions (choices) --------------
38
+ # -------------------------------------------------
39
+ actions = []
40
+ if opts[:actions] && opts[:actions].is_a?(Array) && opts[:actions].length > 0
41
+ # caller has pre-defined actions
42
+ actions << opts[:actions]
43
+ elsif opts[:actions] && opts[:actions].is_a?(Symbol)
44
+ # caller wants a template
45
+ actions << add_template_actions(opts[:actions], &block)
46
+ elsif block_given?
47
+ # convert our block into the one & only action
48
+ actions << AlertAction.new(NSLocalizedString("OK", nil), &block)
49
+ else
50
+ # no actions & no block makes alerts a dull boy
51
+ actions << [AlertAction.new(NSLocalizedString("OK", nil))]
52
+ end
53
+ provider.build(actions.flatten.compact, opts)
54
+
55
+ # --------------------------------------------
56
+ # -- Show the modal right away? --------------
57
+ # --------------------------------------------
58
+ provider.show if opts[:show_now]
59
+
60
+ # TODO: find a better way to do this ugly housekeeping... right now, this never gets cleaned, so this is leaky.
61
+ if opts[:api] == :deprecated
62
+ @rmq_red_alert_providers ||= []
63
+ @rmq_red_alert_providers << provider
64
+ end
65
+
66
+ provider
67
+ end # alert
20
68
 
21
69
  # Returns a UIAlertAction from given parameters
22
70
  # Usage Example:
@@ -25,24 +73,11 @@ module RubyMotionQuery
25
73
  # puts "Cancel pressed"
26
74
  # }
27
75
  # @return [UIAlertAction]
28
- def make_button (opts = {}, &block)
29
- # shortcut sending a string
30
- opts = {title: opts} if opts.is_a? String
31
-
32
- opts = {
33
- title: "OK",
34
- style: :default,
35
- }.merge(opts)
36
-
37
- style = RubyMotionQuery::AlertConstants::ALERT_ACTION_STYLE[opts[:style]] || opts[:style]
38
-
39
- UIAlertAction.actionWithTitle(opts[:title], style: style, handler: -> (action) {
40
- title_symbol = action.title.gsub(/\s+/,"_").downcase.to_sym
41
- block.call(title_symbol) unless block.nil?
42
- })
76
+ def make_button(opts={}, &block)
77
+ AlertAction.new(opts, &block)
43
78
  end
44
79
 
45
80
  end # close eigenclass
46
81
 
47
82
  end # close App
48
- end
83
+ 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: '0.3'
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gant
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-29 00:00:00.000000000 Z
11
+ date: 2015-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby_motion_query
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.2.0
19
+ version: 1.3.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.2.0
26
+ version: 1.3.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,7 +38,8 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: RMQ Plugin adds efficient and dynamic alerts/sheets for RubyMotion
41
+ description: RMQ Plugin adds efficient and dynamic alerts/sheets for RubyMotion for
42
+ iOS 7 & 8
42
43
  email:
43
44
  - GantMan@gmail.com
44
45
  executables: []
@@ -47,10 +48,12 @@ extra_rdoc_files: []
47
48
  files:
48
49
  - README.md
49
50
  - lib/RedAlert.rb
51
+ - lib/project/action_sheet_provider.rb
52
+ - lib/project/alert_action.rb
50
53
  - lib/project/alert_constants.rb
54
+ - lib/project/alert_controller_provider.rb
55
+ - lib/project/alert_view_provider.rb
51
56
  - lib/project/button_templates.rb
52
- - lib/project/classic_alert.rb
53
- - lib/project/core_alert.rb
54
57
  - lib/project/red_alert.rb
55
58
  - lib/red_alert.rb
56
59
  homepage: https://github.com/GantMan/RedAlert
@@ -76,5 +79,6 @@ rubyforge_project:
76
79
  rubygems_version: 2.4.5
77
80
  signing_key:
78
81
  specification_version: 4
79
- summary: RMQ Plugin adds efficient and dynamic alerts/sheets for RubyMotion.
82
+ summary: RMQ Plugin adds efficient and dynamic alerts/sheets for RubyMotion for iOS
83
+ 7 & 8.
80
84
  test_files: []
@@ -1,42 +0,0 @@
1
- module RubyMotionQuery
2
- class App
3
-
4
- # Creates and shows the old UIAlertView. Added here for use in fallback.
5
- # Fallback won't run actions, but the old system needed delegates anyhow.
6
- # Usage Example:
7
- # rmq.app.alert_view("This is a test")
8
- # rmq.app.alert_view(title: "Hey there", message: "Enjoying this?")
9
- # @return [UIAlertView]
10
- def self.alert_view(opts = {})
11
-
12
- # shortcut sending a string
13
- opts = {message: opts} if opts.is_a? String
14
- # An alert is nothing without a message
15
- raise(ArgumentError, "RedAlert requires a message") if opts[:message].nil? || opts[:message].empty?
16
-
17
- opts = {
18
- title: "Alert!",
19
- cancel_button: "OK",
20
- other_buttons: [],
21
- delegate: nil,
22
- view_style: UIAlertViewStyleDefault,
23
- show_now: true,
24
- }.merge(opts)
25
-
26
- alert_view = UIAlertView.alloc.initWithTitle(
27
- opts[:title],
28
- message: opts[:message],
29
- delegate: opts[:delegate],
30
- cancelButtonTitle: opts[:cancel_button],
31
- otherButtonTitles: nil
32
- )
33
- Array(opts[:other_buttons]).each { |button| alert_view.addButtonWithTitle(button) }
34
-
35
- alert_view.alertViewStyle = opts[:view_style]
36
-
37
- alert_view.show if opts[:show_now]
38
- alert_view
39
- end
40
-
41
- end
42
- end
@@ -1,44 +0,0 @@
1
- module RubyMotionQuery
2
- class App
3
-
4
- class << self
5
- # UIAlertController Magic
6
- def core_alert(opts = {}, &block)
7
-
8
- opts = {
9
- title: "Alert!",
10
- style: :alert,
11
- actions: [make_button(&block)],
12
- animated: true,
13
- show_now: true,
14
- }.merge(opts)
15
- style = RubyMotionQuery::AlertConstants::ALERT_TYPES[opts[:style]] || opts[:style]
16
-
17
- ac = UIAlertController.alertControllerWithTitle(opts[:title], message:opts[:message], preferredStyle: style)
18
-
19
- # Add correct actions (buttons) to the UIAC
20
- if opts[:actions].is_a? Symbol
21
- template_symbol = opts[:actions]
22
- add_template_actions(ac, template_symbol, &block)
23
- elsif opts[:actions].is_a? Array
24
- opts[:actions].each do |action|
25
- if action.is_a? UIAlertAction
26
- ac.addAction(action)
27
- else
28
- raise ArgumentError, "RedAlert actions array must contain UIAlertAction objects"
29
- end
30
- end
31
- else
32
- raise ArgumentError, "RedAlert actions parameter must be an Array or a Template symbol"
33
- end
34
-
35
- # Present it, if that's what we want
36
- rmq.view_controller.presentViewController(ac, animated: opts[:animated], completion: nil) if opts[:show_now]
37
-
38
- # return controller (should I wrap it in RMQ?)
39
- ac
40
- end
41
- end # close eigenclass
42
-
43
- end
44
- end