motion-alert 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/project/app_delegate.rb +4 -0
- data/lib/project/motion_action.rb +5 -4
- data/lib/project/motion_alert.rb +33 -24
- data/lib/project/motion_option.rb +34 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97f3260713af60d3f73c7a450284d7e66858772f
|
4
|
+
data.tar.gz: 5a1e3d1a3b6f53d0d93bb20f4325cbe0d37f89cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5e076597768c17a51c4b9c6ac31f9ef9660e50273a6fb254478ada281e90dbc66c089ef7ced475178d66524f7ad574477f396d3ed9bae72594108e9d7561162
|
7
|
+
data.tar.gz: a168079b9e79c86cb35519da6ff17f209cfbc4a2cf49e677b9698355a7dfc52dd8df62801a1de463ed166887f4f784930e0f797c61fed6b10cb0d606d37cc162
|
data/lib/project/app_delegate.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
module Motion
|
2
2
|
class Action
|
3
|
-
attr_accessor :title, :action
|
3
|
+
attr_accessor :title, :action, :style
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
self.title = title
|
7
|
-
self.action = action
|
5
|
+
def initialize(options = {})
|
6
|
+
self.title = options.fetch(:title, nil)
|
7
|
+
self.action = options.fetch(:action, nil)
|
8
|
+
self.style = options.fetch(:style, nil) || UIAlertActionStyleDefault
|
8
9
|
end
|
9
10
|
|
10
11
|
def choose
|
data/lib/project/motion_alert.rb
CHANGED
@@ -3,6 +3,7 @@ module Motion
|
|
3
3
|
attr_accessor :title
|
4
4
|
attr_accessor :message
|
5
5
|
attr_accessor :actions
|
6
|
+
attr_accessor :type
|
6
7
|
|
7
8
|
def self.instance
|
8
9
|
Dispatch.once { @instance ||= alloc.init }
|
@@ -13,17 +14,13 @@ module Motion
|
|
13
14
|
instance.tap do |i|
|
14
15
|
i.title = options.fetch(:title, nil)
|
15
16
|
i.message = options.fetch(:message, nil)
|
17
|
+
i.type = options.fetch(:type, :alert)
|
16
18
|
i.actions = Option.new
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
def add_action(button_title, action_proc)
|
21
|
-
puts "Deprecated: use actions.add will be removed in 0.3.0"
|
22
|
-
actions.add(button_title, &action_proc)
|
23
|
-
end
|
24
|
-
|
25
22
|
def show
|
26
|
-
show_as_controller || show_as_alert
|
23
|
+
show_as_controller || show_as_alert || show_as_action_sheet
|
27
24
|
end
|
28
25
|
|
29
26
|
def selected(index)
|
@@ -32,49 +29,61 @@ module Motion
|
|
32
29
|
|
33
30
|
private
|
34
31
|
|
35
|
-
|
36
32
|
def show_as_controller
|
37
33
|
return nil if !can_show_controller?
|
38
34
|
|
39
35
|
alert_controller.tap do |alert|
|
40
|
-
self.actions.
|
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
|
-
|
36
|
+
self.actions.attach_to(alert)
|
49
37
|
root_controller.presentViewController(alert, animated: false, completion: nil)
|
50
38
|
end
|
51
39
|
end
|
52
40
|
|
53
41
|
def show_as_alert
|
54
|
-
|
55
|
-
self.actions.
|
56
|
-
alert.addButtonWithTitle(a.title)
|
57
|
-
end
|
58
|
-
alert.show
|
42
|
+
if type == :alert
|
43
|
+
self.actions.attach_to(alert_view).show
|
59
44
|
end
|
60
45
|
end
|
61
46
|
|
47
|
+
def show_as_action_sheet
|
48
|
+
self.actions.attach_to(action_sheet).showInView(root_controller.view)
|
49
|
+
end
|
50
|
+
|
62
51
|
def alert_controller
|
63
52
|
UIAlertController.alertControllerWithTitle(
|
64
53
|
title,
|
65
54
|
message: message,
|
66
|
-
preferredStyle:
|
55
|
+
preferredStyle: style
|
67
56
|
)
|
68
57
|
end
|
69
58
|
|
59
|
+
def style
|
60
|
+
case type
|
61
|
+
when :alert
|
62
|
+
UIAlertControllerStyleAlert
|
63
|
+
when :action_sheet
|
64
|
+
UIAlertControllerStyleActionSheet
|
65
|
+
else
|
66
|
+
UIAlertControllerStyleAlert
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
70
|
def alert_view
|
71
71
|
UIAlertView.alloc.initWithTitle(
|
72
72
|
title,
|
73
73
|
message: message,
|
74
74
|
delegate: UIApplication.sharedApplication.delegate,
|
75
75
|
cancelButtonTitle: nil,
|
76
|
-
otherButtonTitles:
|
77
|
-
|
76
|
+
otherButtonTitles: nil
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
def action_sheet
|
81
|
+
UIActionSheet.alloc.initWithTitle(
|
82
|
+
title,
|
83
|
+
delegate: UIApplication.sharedApplication.delegate,
|
84
|
+
cancelButtonTitle: nil,
|
85
|
+
destructiveButtonTitle: nil,
|
86
|
+
otherButtonTitles: nil
|
78
87
|
)
|
79
88
|
end
|
80
89
|
|
@@ -1,12 +1,14 @@
|
|
1
1
|
module Motion
|
2
2
|
class Option
|
3
3
|
attr_accessor :actions
|
4
|
+
|
4
5
|
def initialize
|
5
6
|
self.actions = []
|
7
|
+
self
|
6
8
|
end
|
7
9
|
|
8
|
-
def add(text, &block)
|
9
|
-
actions << Action.new(text, block)
|
10
|
+
def add(text, style=nil, &block)
|
11
|
+
actions << Action.new(title: text, style: style, action: block)
|
10
12
|
end
|
11
13
|
|
12
14
|
def [](index)
|
@@ -20,5 +22,35 @@ module Motion
|
|
20
22
|
def first
|
21
23
|
actions.first
|
22
24
|
end
|
25
|
+
|
26
|
+
def each
|
27
|
+
actions.each
|
28
|
+
end
|
29
|
+
|
30
|
+
def attach_to(view)
|
31
|
+
case view
|
32
|
+
when UIAlertView, UIActionSheet
|
33
|
+
actions.each_with_index do |action, index|
|
34
|
+
view.addButtonWithTitle(action.title)
|
35
|
+
case action.style
|
36
|
+
when UIAlertActionStyleCancel
|
37
|
+
view.cancelButtonIndex = index
|
38
|
+
when UIAlertActionStyleDestructive
|
39
|
+
view.destructiveButtonIndex = index
|
40
|
+
end
|
41
|
+
end
|
42
|
+
when UIAlertController
|
43
|
+
actions.each do |a|
|
44
|
+
alert_action = UIAlertAction.actionWithTitle(
|
45
|
+
a.title,
|
46
|
+
style: a.style,
|
47
|
+
handler: ->(arg) { a.action ? a.action.call : nil }
|
48
|
+
)
|
49
|
+
view.addAction(alert_action)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
view
|
54
|
+
end
|
23
55
|
end
|
24
56
|
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.
|
4
|
+
version: 0.2.0
|
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-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|