motion-alert 0.1.1 → 0.1.2
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 +4 -4
- data/README.md +3 -3
- data/lib/project/motion_action.rb +7 -1
- data/lib/project/motion_alert.rb +37 -32
- data/lib/project/motion_option.rb +24 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b501540738a246105b52baa7b52baf7271be567d
|
4
|
+
data.tar.gz: 1a82b0b367074926040b30ce2e20889109ddeb97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ed39451a5e97e523fef53636c5587c494a9a6f962c9d2a06dbb98e867af3c5918fdd18b297b0fa9997ac9c8340e1b6f1d807ee2640afd1701daffeb70273cf4
|
7
|
+
data.tar.gz: 8475263610ca21df2e3a04e0a42ca5687c8c9017533a82edd99efc17c153924e9b01e19ba78887e2273d5d011931c4a84399aed98f696915eadc70c8e750e9df
|
data/README.md
CHANGED
@@ -26,9 +26,9 @@ Or install it yourself as:
|
|
26
26
|
## Usage
|
27
27
|
|
28
28
|
def show_alert
|
29
|
-
Motion::Alert.new(
|
30
|
-
a.
|
31
|
-
a.
|
29
|
+
Motion::Alert.new(title: "Alert!", message: "message").tap do |a|
|
30
|
+
a.actions.add("OK", Proc.new { puts 'OK!' })
|
31
|
+
a.actions.add("Cancel")
|
32
32
|
a.show
|
33
33
|
end
|
34
34
|
end
|
@@ -2,9 +2,15 @@ module Motion
|
|
2
2
|
class Action
|
3
3
|
attr_accessor :title, :action
|
4
4
|
|
5
|
-
def initialize(title, action)
|
5
|
+
def initialize(title, action=nil)
|
6
6
|
self.title = title
|
7
7
|
self.action = action
|
8
8
|
end
|
9
|
+
|
10
|
+
def choose
|
11
|
+
if action != nil
|
12
|
+
action.call
|
13
|
+
end
|
14
|
+
end
|
9
15
|
end
|
10
16
|
end
|
data/lib/project/motion_alert.rb
CHANGED
@@ -13,52 +13,62 @@ module Motion
|
|
13
13
|
instance.tap do |i|
|
14
14
|
i.title = options.fetch(:title, nil)
|
15
15
|
i.message = options.fetch(:message, nil)
|
16
|
-
i.actions =
|
16
|
+
i.actions = Option.new
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
def add_action(button_title, action_proc)
|
21
|
-
|
21
|
+
puts "Deprecated: use actions.add will be removed in 0.3.0"
|
22
|
+
actions.add(button_title, &action_proc)
|
22
23
|
end
|
23
24
|
|
24
25
|
def show
|
25
|
-
|
26
|
-
root_controller.presentViewController(alert_view_controller, animated: false, completion: nil)
|
27
|
-
else
|
28
|
-
alert_view.delegate = UIApplication.sharedApplication.delegate
|
29
|
-
alert_view.show
|
30
|
-
end
|
26
|
+
show_as_controller || show_as_alert
|
31
27
|
end
|
32
28
|
|
33
29
|
def selected(index)
|
34
|
-
|
35
|
-
action.call
|
36
|
-
end
|
30
|
+
actions[index].choose
|
37
31
|
end
|
38
32
|
|
39
33
|
private
|
40
34
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
35
|
+
|
36
|
+
def show_as_controller
|
37
|
+
return nil if !can_show_controller?
|
38
|
+
|
39
|
+
alert_controller.tap do |alert|
|
40
|
+
self.actions.actions.each do |a|
|
41
|
+
alert_action = UIAlertAction.actionWithTitle(
|
42
|
+
a.title,
|
43
|
+
style: UIAlertActionStyleDefault,
|
44
|
+
handler: ->(arg) { a.action.call }
|
45
|
+
)
|
46
|
+
alert.addAction(alert_action)
|
47
|
+
end
|
48
|
+
|
49
|
+
root_controller.presentViewController(alert, animated: false, completion: nil)
|
55
50
|
end
|
51
|
+
end
|
56
52
|
|
57
|
-
|
53
|
+
def show_as_alert
|
54
|
+
alert_view.tap do |alert|
|
55
|
+
self.actions.actions.each do |a|
|
56
|
+
alert.addButtonWithTitle(a.title)
|
57
|
+
end
|
58
|
+
alert.show
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def alert_controller
|
63
|
+
UIAlertController.alertControllerWithTitle(
|
64
|
+
title,
|
65
|
+
message: message,
|
66
|
+
preferredStyle: UIAlertControllerStyleAlert
|
67
|
+
)
|
58
68
|
end
|
59
69
|
|
60
70
|
def alert_view
|
61
|
-
|
71
|
+
UIAlertView.alloc.initWithTitle(
|
62
72
|
title,
|
63
73
|
message: message,
|
64
74
|
delegate: UIApplication.sharedApplication.delegate,
|
@@ -66,11 +76,6 @@ module Motion
|
|
66
76
|
otherButtonTitles:
|
67
77
|
nil
|
68
78
|
)
|
69
|
-
self.actions.each do |a|
|
70
|
-
alert_view.addButtonWithTitle(a.title)
|
71
|
-
end
|
72
|
-
|
73
|
-
alert_view
|
74
79
|
end
|
75
80
|
|
76
81
|
def can_show_controller?
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Motion
|
2
|
+
class Option
|
3
|
+
attr_accessor :actions
|
4
|
+
def initialize
|
5
|
+
self.actions = []
|
6
|
+
end
|
7
|
+
|
8
|
+
def add(text, &block)
|
9
|
+
actions << Action.new(text, block)
|
10
|
+
end
|
11
|
+
|
12
|
+
def [](index)
|
13
|
+
actions[index]
|
14
|
+
end
|
15
|
+
|
16
|
+
def count
|
17
|
+
actions.count
|
18
|
+
end
|
19
|
+
|
20
|
+
def first
|
21
|
+
actions.first
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-alert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Larrabee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- lib/project/app_delegate.rb
|
51
51
|
- lib/project/motion_action.rb
|
52
52
|
- lib/project/motion_alert.rb
|
53
|
+
- lib/project/motion_option.rb
|
53
54
|
homepage: https://github.com/squidpunch/motion-alert
|
54
55
|
licenses:
|
55
56
|
- MIT
|