ProMotion 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +5 -1
- data/README.md +237 -138
- data/Rakefile +4 -9
- data/app/app_delegate.rb +3 -0
- data/app/screens/basic_screen.rb +27 -0
- data/lib/ProMotion.rb +3 -5
- data/lib/ProMotion/cocoatouch/SplitViewController.rb +25 -0
- data/lib/ProMotion/cocoatouch/TableViewController.rb +5 -5
- data/lib/ProMotion/cocoatouch/ViewController.rb +5 -5
- data/lib/ProMotion/{app_delegate.rb → delegate.rb} +23 -23
- data/lib/ProMotion/helpers/console.rb +6 -4
- data/lib/ProMotion/helpers/logger.rb +73 -0
- data/lib/ProMotion/helpers/view_helper.rb +45 -13
- data/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb +42 -0
- data/lib/ProMotion/screen_helpers/_tables/_searchable_table.rb +2 -2
- data/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb +46 -41
- data/lib/ProMotion/screen_helpers/_tables/grouped_table.rb +2 -1
- data/lib/ProMotion/screen_helpers/_tables/plain_table.rb +1 -0
- data/lib/ProMotion/screen_helpers/screen_elements.rb +16 -11
- data/lib/ProMotion/screen_helpers/screen_navigation.rb +15 -16
- data/lib/ProMotion/screen_helpers/screen_tabs.rb +20 -16
- data/lib/ProMotion/screen_helpers/split_screen.rb +42 -0
- data/lib/ProMotion/screens/_screen_module.rb +44 -35
- data/lib/ProMotion/screens/_table_screen_module.rb +18 -1
- data/lib/ProMotion/screens/screen.rb +1 -1
- data/lib/ProMotion/version.rb +1 -1
- data/spec/helpers/table_screen.rb +48 -0
- data/spec/helpers/table_screen_refreshable.rb +11 -0
- data/spec/helpers/table_screen_searchable.rb +5 -0
- data/spec/helpers/test_delegate.rb +9 -0
- data/spec/ios_version_spec.rb +6 -6
- data/spec/logger_spec.rb +68 -0
- data/spec/main_spec.rb +1 -1
- data/spec/screen_helpers_spec.rb +35 -6
- data/spec/{view_controller_spec.rb → screen_spec.rb} +1 -1
- data/spec/split_screen_in_tab_bar_spec.rb +49 -0
- data/spec/split_screen_open_screen_spec.rb +46 -0
- data/spec/split_screen_spec.rb +35 -0
- data/spec/table_screen_spec.rb +72 -0
- data/spec/view_helper_spec.rb +112 -8
- metadata +29 -8
- data/lib/ProMotion/helpers/tab_bar.rb +0 -115
- data/spec/helpers/.gitkeep +0 -0
@@ -4,21 +4,22 @@ module ProMotion
|
|
4
4
|
include ProMotion::ScreenElements
|
5
5
|
include ProMotion::SystemHelper
|
6
6
|
include ProMotion::ScreenTabs
|
7
|
+
include ProMotion::SplitScreen if NSBundle.mainBundle.infoDictionary["UIDeviceFamily"].include?("2")
|
7
8
|
|
8
|
-
attr_accessor :parent_screen, :first_screen, :tab_bar_item, :tab_bar, :modal
|
9
|
+
attr_accessor :parent_screen, :first_screen, :tab_bar_item, :tab_bar, :modal, :split_screen
|
9
10
|
|
10
11
|
def on_create(args = {})
|
11
12
|
unless self.is_a?(UIViewController)
|
12
13
|
raise StandardError.new("ERROR: Screens must extend UIViewController or a subclass of UIViewController.")
|
13
14
|
end
|
14
|
-
|
15
|
+
|
15
16
|
args.each do |k, v|
|
16
17
|
self.send("#{k}=", v) if self.respond_to?("#{k}=")
|
17
18
|
end
|
18
19
|
|
19
20
|
self.add_nav_bar if args[:nav_bar]
|
20
|
-
self.table_setup if self.respond_to?(:table_setup)
|
21
21
|
self.on_init if self.respond_to?(:on_init)
|
22
|
+
self.table_setup if self.respond_to?(:table_setup)
|
22
23
|
self
|
23
24
|
end
|
24
25
|
|
@@ -54,28 +55,33 @@ module ProMotion
|
|
54
55
|
end
|
55
56
|
|
56
57
|
def add_nav_bar
|
57
|
-
self.navigation_controller
|
58
|
-
|
58
|
+
self.navigation_controller ||= begin
|
59
|
+
self.first_screen = true if self.respond_to?(:first_screen=)
|
60
|
+
NavigationController.alloc.initWithRootViewController(self)
|
61
|
+
end
|
59
62
|
end
|
60
63
|
|
61
64
|
def set_nav_bar_right_button(title, args={})
|
62
|
-
args[:
|
63
|
-
|
64
|
-
args[:action] ||= nil
|
65
|
-
|
66
|
-
right_button = UIBarButtonItem.alloc.initWithTitle(title, style: args[:style], target: args[:target], action: args[:action])
|
67
|
-
self.navigationItem.rightBarButtonItem = right_button
|
68
|
-
right_button
|
65
|
+
args[:title] = title
|
66
|
+
set_nav_bar_button :right, args
|
69
67
|
end
|
70
68
|
|
71
69
|
def set_nav_bar_left_button(title, args={})
|
70
|
+
args[:title] = title
|
71
|
+
set_nav_bar_button :left, args
|
72
|
+
end
|
73
|
+
|
74
|
+
def set_nav_bar_button(side, args={})
|
72
75
|
args[:style] ||= UIBarButtonItemStyleBordered
|
73
76
|
args[:target] ||= self
|
74
77
|
args[:action] ||= nil
|
75
78
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
+
button = UIBarButtonItem.alloc.initWithTitle(args[:title], style: args[:style], target: args[:target], action: args[:action])
|
80
|
+
|
81
|
+
self.navigationItem.leftBarButtonItem = button if side == :left
|
82
|
+
self.navigationItem.rightBarButtonItem = button if side == :right
|
83
|
+
|
84
|
+
button
|
79
85
|
end
|
80
86
|
|
81
87
|
# [DEPRECATED]
|
@@ -99,13 +105,11 @@ module ProMotion
|
|
99
105
|
end
|
100
106
|
|
101
107
|
def view_will_appear(animated)
|
102
|
-
# ProMotion::Screen.current_screen = self
|
103
108
|
self.will_appear
|
104
109
|
end
|
105
110
|
def will_appear; end
|
106
111
|
|
107
112
|
def view_did_appear(animated)
|
108
|
-
# ProMotion::Screen.current_screen = self
|
109
113
|
self.on_appear
|
110
114
|
end
|
111
115
|
def on_appear; end
|
@@ -116,7 +120,6 @@ module ProMotion
|
|
116
120
|
def will_disappear; end
|
117
121
|
|
118
122
|
def view_did_disappear(animated)
|
119
|
-
# ProMotion::Screen.current_screen = self.parent_screen if self.parent_screen
|
120
123
|
self.on_disappear
|
121
124
|
end
|
122
125
|
def on_disappear; end
|
@@ -131,8 +134,7 @@ module ProMotion
|
|
131
134
|
end
|
132
135
|
|
133
136
|
def main_controller
|
134
|
-
|
135
|
-
self
|
137
|
+
self.navigation_controller || self
|
136
138
|
end
|
137
139
|
|
138
140
|
def view_controller
|
@@ -170,20 +172,35 @@ module ProMotion
|
|
170
172
|
end
|
171
173
|
|
172
174
|
def supported_orientations
|
173
|
-
|
175
|
+
orientations = 0
|
174
176
|
NSBundle.mainBundle.infoDictionary["UISupportedInterfaceOrientations"].each do |ori|
|
175
177
|
case ori
|
176
178
|
when "UIInterfaceOrientationPortrait"
|
177
|
-
|
179
|
+
orientations |= UIInterfaceOrientationMaskPortrait
|
178
180
|
when "UIInterfaceOrientationLandscapeLeft"
|
179
|
-
|
181
|
+
orientations |= UIInterfaceOrientationMaskLandscapeLeft
|
180
182
|
when "UIInterfaceOrientationLandscapeRight"
|
181
|
-
|
183
|
+
orientations |= UIInterfaceOrientationMaskLandscapeRight
|
182
184
|
when "UIInterfaceOrientationPortraitUpsideDown"
|
183
|
-
|
185
|
+
orientations |= UIInterfaceOrientationMaskPortraitUpsideDown
|
184
186
|
end
|
185
187
|
end
|
186
|
-
|
188
|
+
orientations
|
189
|
+
end
|
190
|
+
|
191
|
+
def supported_device_families
|
192
|
+
NSBundle.mainBundle.infoDictionary["UIDeviceFamily"].map do |m|
|
193
|
+
case m
|
194
|
+
when "1"
|
195
|
+
:iphone
|
196
|
+
when "2"
|
197
|
+
:ipad
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def supported_device_family?(family)
|
203
|
+
supported_device_families.include?(family)
|
187
204
|
end
|
188
205
|
|
189
206
|
# Class methods
|
@@ -196,14 +213,6 @@ module ProMotion
|
|
196
213
|
@debug_mode = v
|
197
214
|
end
|
198
215
|
|
199
|
-
def current_screen=(s)
|
200
|
-
@current_screen = s
|
201
|
-
end
|
202
|
-
|
203
|
-
def current_screen
|
204
|
-
@current_screen
|
205
|
-
end
|
206
|
-
|
207
216
|
def title(t)
|
208
217
|
@title = t
|
209
218
|
end
|
@@ -219,4 +228,4 @@ module ProMotion
|
|
219
228
|
base.extend(ClassMethods)
|
220
229
|
end
|
221
230
|
end
|
222
|
-
end
|
231
|
+
end
|
@@ -2,13 +2,15 @@ module ProMotion
|
|
2
2
|
module TableScreenModule
|
3
3
|
include MotionTable::PlainTable
|
4
4
|
include MotionTable::SearchableTable
|
5
|
+
include MotionTable::RefreshableTable
|
5
6
|
include ProMotion::ScreenModule
|
6
|
-
|
7
|
+
|
7
8
|
def update_table_data
|
8
9
|
self.update_table_view_data(table_data)
|
9
10
|
end
|
10
11
|
|
11
12
|
module TableClassMethods
|
13
|
+
# Searchable
|
12
14
|
def searchable(params={})
|
13
15
|
@searchable_params = params
|
14
16
|
@searchable = true
|
@@ -21,6 +23,21 @@ module ProMotion
|
|
21
23
|
def get_searchable
|
22
24
|
@searchable ||= false
|
23
25
|
end
|
26
|
+
|
27
|
+
# Refreshable
|
28
|
+
def refreshable(params = {})
|
29
|
+
@refreshable_params = params
|
30
|
+
@refreshable = true
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_refreshable
|
34
|
+
@refreshable ||= false
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_refreshable_params
|
38
|
+
@refreshable_params ||= nil
|
39
|
+
end
|
40
|
+
|
24
41
|
end
|
25
42
|
def self.included(base)
|
26
43
|
base.extend(ClassMethods)
|
data/lib/ProMotion/version.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
class TableScreen < ProMotion::SectionedTableScreen
|
2
|
+
|
3
|
+
def on_load
|
4
|
+
@tap_counter ||= 0
|
5
|
+
end
|
6
|
+
|
7
|
+
def table_data
|
8
|
+
[{
|
9
|
+
title: "Your Account",
|
10
|
+
cells: [
|
11
|
+
{ title: "Increment", action: :increment_counter_by, arguments: { number: 3 } },
|
12
|
+
{ title: "Add New Row", action: :add_tableview_row, accessibilityLabel: "Add New Row" },
|
13
|
+
{ title: "Just another blank row" }
|
14
|
+
]
|
15
|
+
}, {
|
16
|
+
title: "App Stuff",
|
17
|
+
cells: [
|
18
|
+
{ title: "Increment One", action: :increment_counter },
|
19
|
+
{ title: "Feedback", remote_image: { url: "http://placekitten.com/100/100", placeholder: "some-local-image", size: 50, radius: 15 } }
|
20
|
+
]
|
21
|
+
}]
|
22
|
+
end
|
23
|
+
|
24
|
+
def edit_profile(args={})
|
25
|
+
args[:id]
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_tableview_row
|
29
|
+
@data[0][:cells] << {
|
30
|
+
title: "Dynamically Added"
|
31
|
+
}
|
32
|
+
update_table_data
|
33
|
+
end
|
34
|
+
|
35
|
+
def increment_counter
|
36
|
+
@tap_counter += 1
|
37
|
+
end
|
38
|
+
|
39
|
+
def increment_counter_by(args)
|
40
|
+
@tap_counter = @tap_counter + args[:number]
|
41
|
+
end
|
42
|
+
|
43
|
+
def tap_counter
|
44
|
+
@tap_counter
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
end
|
data/spec/ios_version_spec.rb
CHANGED
@@ -6,23 +6,23 @@ describe "ios version" do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "#ios_version_is?" do
|
9
|
-
@dummy.ios_version_is?(@dummy.ios_version).should
|
9
|
+
@dummy.ios_version_is?(@dummy.ios_version).should.be.true
|
10
10
|
end
|
11
11
|
|
12
12
|
it "#ios_version_greater?" do
|
13
|
-
@dummy.ios_version_greater?('1.0').should
|
13
|
+
@dummy.ios_version_greater?('1.0').should.be.true
|
14
14
|
end
|
15
15
|
|
16
16
|
it "#ios_version_greater_eq?" do
|
17
|
-
@dummy.ios_version_greater_eq?(@dummy.ios_version).should
|
17
|
+
@dummy.ios_version_greater_eq?(@dummy.ios_version).should.be.true
|
18
18
|
end
|
19
19
|
|
20
20
|
it "#ios_version_less?" do
|
21
|
-
@dummy.ios_version_less?('9.0').should
|
21
|
+
@dummy.ios_version_less?('9.0').should.be.true
|
22
22
|
end
|
23
23
|
|
24
24
|
it "#ios_version_less_eq?" do
|
25
|
-
@dummy.ios_version_less_eq?(@dummy.ios_version).should
|
25
|
+
@dummy.ios_version_less_eq?(@dummy.ios_version).should.be.true
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
end
|
data/spec/logger_spec.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
describe "logger functionality" do
|
2
|
+
|
3
|
+
describe "basic logger" do
|
4
|
+
it "should respond to PM.logger with a logger instance" do
|
5
|
+
PM.logger.is_a?(PM::Logger).should == true
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should allow setting the log level" do
|
9
|
+
PM.logger.level = :warn
|
10
|
+
PM.logger.level.should == :warn
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "testing levels" do
|
15
|
+
|
16
|
+
before do
|
17
|
+
PM.logger.stub! :log {|a, b, c| "It worked" }
|
18
|
+
end
|
19
|
+
|
20
|
+
after do
|
21
|
+
PM.logger.level = :debug
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should not log if level is set to :none" do
|
25
|
+
|
26
|
+
PM.logger.stub! :log do |label, message_text, color|
|
27
|
+
should.flunk "should not log if logging is turned off!"
|
28
|
+
end
|
29
|
+
|
30
|
+
PM.logger.level = :none
|
31
|
+
PM.logger.warn("I'm giving you a warning that you should ignore.").should == nil
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
it "#error should log if set to :error level or above" do
|
36
|
+
|
37
|
+
PM.logger.level = :error
|
38
|
+
PM.logger.error("test message").should == "It worked"
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
it "#deprecated should log if set to :warn level or above" do
|
43
|
+
|
44
|
+
PM.logger.level = :warn
|
45
|
+
PM.logger.deprecated("test message").should == "It worked"
|
46
|
+
|
47
|
+
end
|
48
|
+
it "#warn should log if set to :warn level or above" do
|
49
|
+
|
50
|
+
PM.logger.level = :warn
|
51
|
+
PM.logger.warn("test message").should == "It worked"
|
52
|
+
|
53
|
+
end
|
54
|
+
it "#debug should log if set to :debug level or above" do
|
55
|
+
|
56
|
+
PM.logger.level = :debug
|
57
|
+
PM.logger.debug("test message").should == "It worked"
|
58
|
+
|
59
|
+
end
|
60
|
+
it "#info should log if set to :info level or above" do
|
61
|
+
|
62
|
+
PM.logger.level = :info
|
63
|
+
PM.logger.info("test message").should == "It worked"
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
data/spec/main_spec.rb
CHANGED
data/spec/screen_helpers_spec.rb
CHANGED
@@ -24,8 +24,37 @@ describe "screen helpers" do
|
|
24
24
|
@screen.view.subviews.count.should == 0
|
25
25
|
end
|
26
26
|
|
27
|
+
it "should add a subview to another element" do
|
28
|
+
sub_subview = UIView.alloc.initWithFrame CGRectZero
|
29
|
+
@screen.add_to @subview, sub_subview
|
30
|
+
@subview.subviews.include?(sub_subview).should == true
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should add a subview to another element with attributes" do
|
34
|
+
sub_subview = UIView.alloc.initWithFrame CGRectZero
|
35
|
+
@screen.add_to @subview, sub_subview, { backgroundColor: UIColor.redColor }
|
36
|
+
@subview.subviews.last.backgroundColor.should == UIColor.redColor
|
37
|
+
end
|
38
|
+
|
27
39
|
end
|
28
40
|
|
41
|
+
describe "nav bar buttons" do
|
42
|
+
|
43
|
+
before do
|
44
|
+
@screen = HomeScreen.new(nav_bar: true)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should add a left nav bar button" do
|
48
|
+
@screen.set_nav_bar_left_button "Save", action: :save_something, type: UIBarButtonItemStyleDone
|
49
|
+
@screen.navigationItem.leftBarButtonItem.class.should == UIBarButtonItem
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should add a right nav bar button" do
|
53
|
+
@screen.set_nav_bar_right_button "Cancel", action: :return_to_some_other_screen, type: UIBarButtonItemStylePlain
|
54
|
+
@screen.navigationItem.rightBarButtonItem.class.should == UIBarButtonItem
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
29
58
|
|
30
59
|
describe "screen navigation" do
|
31
60
|
|
@@ -79,13 +108,13 @@ describe "screen helpers" do
|
|
79
108
|
@screen.send(:present_modal_view_controller, new_screen, true)
|
80
109
|
end
|
81
110
|
|
82
|
-
it "should push screen onto nav controller stack inside a tab bar" do
|
83
|
-
|
84
|
-
end
|
111
|
+
# it "should push screen onto nav controller stack inside a tab bar" do
|
112
|
+
# # TODO: Implement this test
|
113
|
+
# end
|
85
114
|
|
86
|
-
it "should set the tab bar selectedIndex when opening a screen inside a tab bar" do
|
87
|
-
|
88
|
-
end
|
115
|
+
# it "should set the tab bar selectedIndex when opening a screen inside a tab bar" do
|
116
|
+
# # TODO: Implement this test
|
117
|
+
# end
|
89
118
|
|
90
119
|
it "should open a root screen if :close_all is provided" do
|
91
120
|
@screen.mock!(:open_root_screen) { |screen| screen.should.be.instance_of BasicScreen }
|