ProMotion 0.6.5 → 0.7.0
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.
- data/README.md +79 -502
- data/Rakefile +30 -0
- data/app/app_delegate.rb +3 -1
- data/lib/ProMotion.rb +1 -1
- data/lib/ProMotion/cocoatouch/TableViewCell.rb +5 -1
- data/lib/ProMotion/delegate/delegate.rb +16 -0
- data/lib/ProMotion/delegate/delegate_helper.rb +88 -0
- data/lib/ProMotion/delegate/delegate_notifications.rb +61 -0
- data/lib/ProMotion/helpers/console.rb +3 -3
- data/lib/ProMotion/helpers/logger.rb +15 -15
- data/lib/ProMotion/helpers/view_helper.rb +7 -5
- data/lib/ProMotion/push_notifications/push_notification.rb +51 -0
- data/lib/ProMotion/screen_helpers/screen_elements.rb +2 -2
- data/lib/ProMotion/screen_helpers/screen_navigation.rb +5 -1
- data/lib/ProMotion/screen_helpers/screen_tabs.rb +2 -2
- data/lib/ProMotion/screens/_compatibility/formotion_screen.rb +65 -0
- data/lib/ProMotion/screens/_screen_module.rb +33 -20
- data/lib/ProMotion/screens/_table_screen_module.rb +4 -4
- data/lib/ProMotion/{screen_helpers → screens}/_tables/_refreshable_table.rb +2 -2
- data/lib/ProMotion/{screen_helpers → screens}/_tables/_searchable_table.rb +27 -34
- data/lib/ProMotion/screens/_tables/_sectioned_table.rb +5 -0
- data/lib/ProMotion/screens/_tables/_table.rb +149 -0
- data/lib/ProMotion/screens/_tables/grouped_table.rb +16 -0
- data/lib/ProMotion/screens/_tables/plain_table.rb +17 -0
- data/lib/ProMotion/screens/_tables/table_data.rb +148 -0
- data/lib/ProMotion/screens/_tables/table_view_cell_module.rb +156 -0
- data/lib/ProMotion/screens/table_screen.rb +3 -2
- data/lib/ProMotion/version.rb +1 -1
- data/spec/functional/func_screen_spec.rb +66 -0
- data/spec/functional/func_split_screen_spec.rb +66 -0
- data/spec/functional/func_table_screen_spec.rb +52 -0
- data/spec/helpers/functional_screen.rb +15 -0
- data/spec/helpers/table_screen.rb +32 -8
- data/spec/helpers/table_screen_refreshable.rb +1 -1
- data/spec/helpers/table_screen_searchable.rb +1 -1
- data/spec/helpers/test_delegate.rb +2 -0
- data/spec/unit/delegate_spec.rb +38 -0
- data/spec/{ios_version_spec.rb → unit/ios_version_spec.rb} +0 -0
- data/spec/{logger_spec.rb → unit/logger_spec.rb} +0 -0
- data/spec/{main_spec.rb → unit/main_spec.rb} +0 -0
- data/spec/{screen_helpers_spec.rb → unit/screen_helpers_spec.rb} +14 -6
- data/spec/{screen_module_spec.rb → unit/screen_module_spec.rb} +0 -0
- data/spec/{screen_spec.rb → unit/screen_spec.rb} +21 -3
- data/spec/{split_screen_in_tab_bar_spec.rb → unit/split_screen_in_tab_bar_spec.rb} +0 -0
- data/spec/{split_screen_open_screen_spec.rb → unit/split_screen_open_screen_spec.rb} +0 -0
- data/spec/{split_screen_spec.rb → unit/split_screen_spec.rb} +0 -0
- data/spec/unit/tables/table_module_spec.rb +108 -0
- data/spec/unit/tables/table_screen_spec.rb +92 -0
- data/spec/unit/tables/table_view_cell_spec.rb +106 -0
- data/spec/{view_helper_spec.rb → unit/view_helper_spec.rb} +0 -0
- metadata +50 -29
- data/lib/ProMotion/delegate.rb +0 -63
- data/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb +0 -270
- data/lib/ProMotion/screen_helpers/_tables/grouped_table.rb +0 -14
- data/lib/ProMotion/screen_helpers/_tables/plain_table.rb +0 -15
- data/spec/table_screen_spec.rb +0 -72
@@ -0,0 +1,106 @@
|
|
1
|
+
describe "PM::TableViewCellModule" do
|
2
|
+
|
3
|
+
def custom_cell
|
4
|
+
{
|
5
|
+
title: "Crazy Full Featured Cell",
|
6
|
+
subtitle: "This is way too huge...",
|
7
|
+
arguments: { data: [ "lots", "of", "data" ] },
|
8
|
+
action: :tapped_cell_1,
|
9
|
+
height: 50, # manually changes the cell's height
|
10
|
+
cell_style: UITableViewCellStyleSubtitle,
|
11
|
+
cell_identifier: "Cell",
|
12
|
+
cell_class: PM::TableViewCell,
|
13
|
+
layer: { masks_to_bounds: true },
|
14
|
+
background_color: UIColor.redColor,
|
15
|
+
selection_style: UITableViewCellSelectionStyleGray,
|
16
|
+
accessory: :switch, # currently only :switch is supported
|
17
|
+
accessory_checked: true, # whether it's "checked" or not
|
18
|
+
image: { image: UIImage.imageNamed("list"), radius: 15 },
|
19
|
+
subviews: [ UIView.alloc.initWithFrame(CGRectZero), UILabel.alloc.initWithFrame(CGRectZero) ] # arbitrary views added to the cell
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
before do
|
24
|
+
@screen = TestTableScreen.new
|
25
|
+
button = UIButton.buttonWithType(UIButtonTypeRoundedRect).tap{|b| b.titleLabel.text = "ACC" }
|
26
|
+
@screen.mock! :table_data do
|
27
|
+
[
|
28
|
+
{ title: "", cells: [] },
|
29
|
+
{ title: "", cells: [
|
30
|
+
{title: "Test 1", accessory_type: UITableViewCellStateShowingEditControlMask },
|
31
|
+
custom_cell,
|
32
|
+
{ title: "Test2", accessory_view: button } ] }
|
33
|
+
]
|
34
|
+
end
|
35
|
+
|
36
|
+
@screen.on_load
|
37
|
+
|
38
|
+
custom_ip = NSIndexPath.indexPathForRow(1, inSection: 1) # Cell "Crazy Full Featured Cell"
|
39
|
+
|
40
|
+
@screen.update_table_data
|
41
|
+
|
42
|
+
@subject = @screen.tableView(@screen.table_view, cellForRowAtIndexPath: custom_ip)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should be a PM::TableViewCell" do
|
46
|
+
@subject.should.be.kind_of(PM::TableViewCell)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should have the right title" do
|
50
|
+
@subject.textLabel.text.should == "Crazy Full Featured Cell"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should have the right subtitle" do
|
54
|
+
@subject.detailTextLabel.text.should == "This is way too huge..."
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should have the right re-use identifier" do
|
58
|
+
@subject.reuseIdentifier.should == "Cell"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should set the layer.masksToBounds" do
|
62
|
+
@subject.layer.masksToBounds.should == true
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should set the background color" do
|
66
|
+
@subject.backgroundView.backgroundColor.should == UIColor.redColor
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should set the selection color style" do
|
70
|
+
@subject.selectionStyle.should == UITableViewCellSelectionStyleGray
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should set the accessory view to a switch" do
|
74
|
+
@subject.accessoryView.should.be.kind_of(UISwitch)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should set the accessory view to a button" do
|
78
|
+
ip = NSIndexPath.indexPathForRow(2, inSection: 1)
|
79
|
+
subject = @screen.tableView(@screen.table_view, cellForRowAtIndexPath: ip)
|
80
|
+
subject.accessoryView.should.be.kind_of(UIRoundedRectButton)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should set the accessory type to edit" do
|
84
|
+
ip = NSIndexPath.indexPathForRow(0, inSection: 1)
|
85
|
+
subject = @screen.tableView(@screen.table_view, cellForRowAtIndexPath: ip)
|
86
|
+
subject.accessoryView.should.be.nil
|
87
|
+
subject.accessoryType.should == UITableViewCellStateShowingEditControlMask
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should set an image with a radius" do
|
91
|
+
@subject.imageView.should.be.kind_of(UIImageView)
|
92
|
+
@subject.imageView.image.should == UIImage.imageNamed("list")
|
93
|
+
@subject.imageView.layer.cornerRadius.should == 15.0
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should create two extra subviews" do
|
97
|
+
@subject.subviews.length.should == 4
|
98
|
+
@subject.subviews[2].class.should == UIView
|
99
|
+
@subject.subviews[3].class.should == UILabel
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ProMotion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -89,32 +89,43 @@ files:
|
|
89
89
|
- lib/ProMotion/cocoatouch/TableViewCell.rb
|
90
90
|
- lib/ProMotion/cocoatouch/TableViewController.rb
|
91
91
|
- lib/ProMotion/cocoatouch/ViewController.rb
|
92
|
-
- lib/ProMotion/delegate.rb
|
92
|
+
- lib/ProMotion/delegate/delegate.rb
|
93
|
+
- lib/ProMotion/delegate/delegate_helper.rb
|
94
|
+
- lib/ProMotion/delegate/delegate_notifications.rb
|
93
95
|
- lib/ProMotion/helpers/console.rb
|
94
96
|
- lib/ProMotion/helpers/logger.rb
|
95
97
|
- lib/ProMotion/helpers/measure_helper.rb
|
96
98
|
- lib/ProMotion/helpers/system_helper.rb
|
97
99
|
- lib/ProMotion/helpers/view_helper.rb
|
98
100
|
- lib/ProMotion/pro_motion.rb
|
99
|
-
- lib/ProMotion/
|
100
|
-
- lib/ProMotion/screen_helpers/_tables/_searchable_table.rb
|
101
|
-
- lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb
|
102
|
-
- lib/ProMotion/screen_helpers/_tables/grouped_table.rb
|
103
|
-
- lib/ProMotion/screen_helpers/_tables/plain_table.rb
|
101
|
+
- lib/ProMotion/push_notifications/push_notification.rb
|
104
102
|
- lib/ProMotion/screen_helpers/screen_elements.rb
|
105
103
|
- lib/ProMotion/screen_helpers/screen_navigation.rb
|
106
104
|
- lib/ProMotion/screen_helpers/screen_tabs.rb
|
107
105
|
- lib/ProMotion/screen_helpers/split_screen.rb
|
106
|
+
- lib/ProMotion/screens/_compatibility/formotion_screen.rb
|
108
107
|
- lib/ProMotion/screens/_screen_module.rb
|
109
108
|
- lib/ProMotion/screens/_table_screen_module.rb
|
109
|
+
- lib/ProMotion/screens/_tables/_refreshable_table.rb
|
110
|
+
- lib/ProMotion/screens/_tables/_searchable_table.rb
|
111
|
+
- lib/ProMotion/screens/_tables/_sectioned_table.rb
|
112
|
+
- lib/ProMotion/screens/_tables/_table.rb
|
113
|
+
- lib/ProMotion/screens/_tables/grouped_table.rb
|
114
|
+
- lib/ProMotion/screens/_tables/plain_table.rb
|
115
|
+
- lib/ProMotion/screens/_tables/table_data.rb
|
116
|
+
- lib/ProMotion/screens/_tables/table_view_cell_module.rb
|
110
117
|
- lib/ProMotion/screens/behaves_like_screen.rb
|
111
118
|
- lib/ProMotion/screens/screen.rb
|
112
119
|
- lib/ProMotion/screens/table_screen.rb
|
113
120
|
- lib/ProMotion/version.rb
|
114
121
|
- resources/list.png
|
122
|
+
- spec/functional/func_screen_spec.rb
|
123
|
+
- spec/functional/func_split_screen_spec.rb
|
124
|
+
- spec/functional/func_table_screen_spec.rb
|
115
125
|
- spec/helpers/basic_screen.rb
|
116
126
|
- spec/helpers/detail_screen.rb
|
117
127
|
- spec/helpers/dummy_class.rb
|
128
|
+
- spec/helpers/functional_screen.rb
|
118
129
|
- spec/helpers/home_screen.rb
|
119
130
|
- spec/helpers/master_screen.rb
|
120
131
|
- spec/helpers/screen_module_view_controller.rb
|
@@ -122,17 +133,20 @@ files:
|
|
122
133
|
- spec/helpers/table_screen_refreshable.rb
|
123
134
|
- spec/helpers/table_screen_searchable.rb
|
124
135
|
- spec/helpers/test_delegate.rb
|
125
|
-
- spec/
|
126
|
-
- spec/
|
127
|
-
- spec/
|
128
|
-
- spec/
|
129
|
-
- spec/
|
130
|
-
- spec/
|
131
|
-
- spec/
|
132
|
-
- spec/
|
133
|
-
- spec/
|
134
|
-
- spec/
|
135
|
-
- spec/
|
136
|
+
- spec/unit/delegate_spec.rb
|
137
|
+
- spec/unit/ios_version_spec.rb
|
138
|
+
- spec/unit/logger_spec.rb
|
139
|
+
- spec/unit/main_spec.rb
|
140
|
+
- spec/unit/screen_helpers_spec.rb
|
141
|
+
- spec/unit/screen_module_spec.rb
|
142
|
+
- spec/unit/screen_spec.rb
|
143
|
+
- spec/unit/split_screen_in_tab_bar_spec.rb
|
144
|
+
- spec/unit/split_screen_open_screen_spec.rb
|
145
|
+
- spec/unit/split_screen_spec.rb
|
146
|
+
- spec/unit/tables/table_module_spec.rb
|
147
|
+
- spec/unit/tables/table_screen_spec.rb
|
148
|
+
- spec/unit/tables/table_view_cell_spec.rb
|
149
|
+
- spec/unit/view_helper_spec.rb
|
136
150
|
homepage: https://github.com/clearsightstudio/ProMotion
|
137
151
|
licenses: []
|
138
152
|
post_install_message:
|
@@ -161,9 +175,13 @@ summary: ProMotion is a new way to organize RubyMotion apps. Instead of dealing
|
|
161
175
|
your app and include a ton of great utilities to make iOS development more like
|
162
176
|
Ruby and less like Objective-C.
|
163
177
|
test_files:
|
178
|
+
- spec/functional/func_screen_spec.rb
|
179
|
+
- spec/functional/func_split_screen_spec.rb
|
180
|
+
- spec/functional/func_table_screen_spec.rb
|
164
181
|
- spec/helpers/basic_screen.rb
|
165
182
|
- spec/helpers/detail_screen.rb
|
166
183
|
- spec/helpers/dummy_class.rb
|
184
|
+
- spec/helpers/functional_screen.rb
|
167
185
|
- spec/helpers/home_screen.rb
|
168
186
|
- spec/helpers/master_screen.rb
|
169
187
|
- spec/helpers/screen_module_view_controller.rb
|
@@ -171,14 +189,17 @@ test_files:
|
|
171
189
|
- spec/helpers/table_screen_refreshable.rb
|
172
190
|
- spec/helpers/table_screen_searchable.rb
|
173
191
|
- spec/helpers/test_delegate.rb
|
174
|
-
- spec/
|
175
|
-
- spec/
|
176
|
-
- spec/
|
177
|
-
- spec/
|
178
|
-
- spec/
|
179
|
-
- spec/
|
180
|
-
- spec/
|
181
|
-
- spec/
|
182
|
-
- spec/
|
183
|
-
- spec/
|
184
|
-
- spec/
|
192
|
+
- spec/unit/delegate_spec.rb
|
193
|
+
- spec/unit/ios_version_spec.rb
|
194
|
+
- spec/unit/logger_spec.rb
|
195
|
+
- spec/unit/main_spec.rb
|
196
|
+
- spec/unit/screen_helpers_spec.rb
|
197
|
+
- spec/unit/screen_module_spec.rb
|
198
|
+
- spec/unit/screen_spec.rb
|
199
|
+
- spec/unit/split_screen_in_tab_bar_spec.rb
|
200
|
+
- spec/unit/split_screen_open_screen_spec.rb
|
201
|
+
- spec/unit/split_screen_spec.rb
|
202
|
+
- spec/unit/tables/table_module_spec.rb
|
203
|
+
- spec/unit/tables/table_screen_spec.rb
|
204
|
+
- spec/unit/tables/table_view_cell_spec.rb
|
205
|
+
- spec/unit/view_helper_spec.rb
|
data/lib/ProMotion/delegate.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
module ProMotion
|
2
|
-
class Delegate
|
3
|
-
include ProMotion::ScreenTabs
|
4
|
-
include ProMotion::SplitScreen if NSBundle.mainBundle.infoDictionary["UIDeviceFamily"].include?("2") # Only with iPad
|
5
|
-
attr_accessor :window
|
6
|
-
|
7
|
-
def application(application, didFinishLaunchingWithOptions:launch_options)
|
8
|
-
unless self.respond_to?(:on_load)
|
9
|
-
PM.logger.error "Your AppDelegate (usually in app_delegate.rb) needs an on_load(application, options) method."
|
10
|
-
end
|
11
|
-
|
12
|
-
on_load(application, launch_options)
|
13
|
-
|
14
|
-
true
|
15
|
-
end
|
16
|
-
|
17
|
-
def app_delegate
|
18
|
-
UIApplication.sharedApplication.delegate
|
19
|
-
end
|
20
|
-
|
21
|
-
def app_window
|
22
|
-
self.app_delegate.window
|
23
|
-
end
|
24
|
-
|
25
|
-
def home(screen)
|
26
|
-
screen = screen.new if screen.respond_to?(:new)
|
27
|
-
@home_screen = screen
|
28
|
-
end
|
29
|
-
|
30
|
-
def load_root_screen(new_screen)
|
31
|
-
new_screen = new_screen.pm_main_controller
|
32
|
-
|
33
|
-
self.window ||= self.ui_window.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
34
|
-
self.window.rootViewController = new_screen
|
35
|
-
self.window.makeKeyAndVisible
|
36
|
-
end
|
37
|
-
|
38
|
-
def ui_window
|
39
|
-
(defined?(Motion) && defined?(Motion::Xray) && defined?(Motion::Xray::XrayWindow)) ? Motion::Xray::XrayWindow : UIWindow
|
40
|
-
end
|
41
|
-
|
42
|
-
def open_screen(screen, args={})
|
43
|
-
home(screen)
|
44
|
-
open_home_screen
|
45
|
-
end
|
46
|
-
alias :open :open_screen
|
47
|
-
alias :open_root_screen :open_screen
|
48
|
-
|
49
|
-
def open_home_screen
|
50
|
-
get_home_screen.send(:on_load) if get_home_screen.respond_to?(:on_load)
|
51
|
-
load_root_screen get_home_screen
|
52
|
-
end
|
53
|
-
|
54
|
-
def get_home_screen
|
55
|
-
@home_screen
|
56
|
-
end
|
57
|
-
|
58
|
-
def has_home_screen
|
59
|
-
@home_screen.nil? == false
|
60
|
-
end
|
61
|
-
end
|
62
|
-
class AppDelegateParent < Delegate; end # For backwards compatibility
|
63
|
-
end
|
@@ -1,270 +0,0 @@
|
|
1
|
-
module ProMotion::MotionTable
|
2
|
-
module SectionedTable
|
3
|
-
include ProMotion::ViewHelper
|
4
|
-
|
5
|
-
def table_setup
|
6
|
-
PM.logger.error "Missing #table_data method in TableScreen #{self.class.to_s}." unless self.respond_to?(:table_data)
|
7
|
-
|
8
|
-
self.view = self.create_table_view_from_data(self.table_data)
|
9
|
-
|
10
|
-
if self.class.respond_to?(:get_searchable) && self.class.get_searchable
|
11
|
-
self.make_searchable(content_controller: self, search_bar: self.class.get_searchable_params)
|
12
|
-
end
|
13
|
-
if self.class.respond_to?(:get_refreshable) && self.class.get_refreshable
|
14
|
-
if defined?(UIRefreshControl)
|
15
|
-
self.make_refreshable(self.class.get_refreshable_params)
|
16
|
-
else
|
17
|
-
PM.logger.warn "To use the refresh control on < iOS 6, you need to include the CocoaPod 'CKRefreshControl'."
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# @param [Array] Array of table data
|
23
|
-
# @returns [UITableView] delegated to self
|
24
|
-
def create_table_view_from_data(data)
|
25
|
-
set_table_view_data data
|
26
|
-
return table_view
|
27
|
-
end
|
28
|
-
alias :createTableViewFromData :create_table_view_from_data
|
29
|
-
|
30
|
-
def update_table_view_data(data)
|
31
|
-
set_table_view_data data
|
32
|
-
self.table_view.reloadData
|
33
|
-
end
|
34
|
-
alias :updateTableViewData :update_table_view_data
|
35
|
-
|
36
|
-
def set_table_view_data(data)
|
37
|
-
@mt_table_view_groups = data
|
38
|
-
end
|
39
|
-
alias :setTableViewData :set_table_view_data
|
40
|
-
|
41
|
-
def section_at_index(index)
|
42
|
-
if @mt_filtered
|
43
|
-
@mt_filtered_data.at(index)
|
44
|
-
else
|
45
|
-
@mt_table_view_groups.at(index)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def cell_at_section_and_index(section, index)
|
50
|
-
if section_at_index(section) && section_at_index(section)[:cells]
|
51
|
-
return section_at_index(section)[:cells].at(index)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
alias :cellAtSectionAndIndex :cell_at_section_and_index
|
55
|
-
|
56
|
-
def trigger_action(action, arguments)
|
57
|
-
if self.respond_to?(action)
|
58
|
-
expected_arguments = self.method(action).arity
|
59
|
-
if expected_arguments == 0
|
60
|
-
self.send(action)
|
61
|
-
elsif expected_arguments == 1 || expected_arguments == -1
|
62
|
-
self.send(action, arguments)
|
63
|
-
else
|
64
|
-
PM.logger.warn "#{action} expects #{expected_arguments} arguments. Maximum number of required arguments for an action is 1."
|
65
|
-
end
|
66
|
-
else
|
67
|
-
PM.logger.info "Action not implemented: #{action.to_s}"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def accessory_toggled_switch(switch)
|
72
|
-
table_cell = switch.superview
|
73
|
-
index_path = table_cell.superview.indexPathForCell(table_cell)
|
74
|
-
|
75
|
-
data_cell = cell_at_section_and_index(index_path.section, index_path.row)
|
76
|
-
data_cell[:arguments] = {} unless data_cell[:arguments]
|
77
|
-
data_cell[:arguments][:value] = switch.isOn if data_cell[:arguments].is_a? Hash
|
78
|
-
data_cell[:accessory_action] ||= data_cell[:accessoryAction] # For legacy support
|
79
|
-
|
80
|
-
trigger_action(data_cell[:accessory_action], data_cell[:arguments]) if data_cell[:accessory_action]
|
81
|
-
end
|
82
|
-
|
83
|
-
########## Cocoa touch methods, leave as-is #################
|
84
|
-
def numberOfSectionsInTableView(table_view)
|
85
|
-
if @mt_filtered
|
86
|
-
return @mt_filtered_data.length if @mt_filtered_data
|
87
|
-
else
|
88
|
-
return @mt_table_view_groups.length if @mt_table_view_groups
|
89
|
-
end
|
90
|
-
0
|
91
|
-
end
|
92
|
-
|
93
|
-
# Number of cells
|
94
|
-
def tableView(table_view, numberOfRowsInSection:section)
|
95
|
-
return section_at_index(section)[:cells].length if section_at_index(section) && section_at_index(section)[:cells]
|
96
|
-
0
|
97
|
-
end
|
98
|
-
|
99
|
-
def tableView(table_view, titleForHeaderInSection:section)
|
100
|
-
return section_at_index(section)[:title] if section_at_index(section) && section_at_index(section)[:title]
|
101
|
-
end
|
102
|
-
|
103
|
-
# Set table_data_index if you want the right hand index column (jumplist)
|
104
|
-
def sectionIndexTitlesForTableView(table_view)
|
105
|
-
if self.respond_to?(:table_data_index)
|
106
|
-
self.table_data_index
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def remap_data_cell(data_cell)
|
111
|
-
# Re-maps legacy data cell calls
|
112
|
-
mappings = {
|
113
|
-
cell_style: :cellStyle,
|
114
|
-
cell_identifier: :cellIdentifier,
|
115
|
-
cell_class: :cellClass,
|
116
|
-
masks_to_bounds: :masksToBounds,
|
117
|
-
background_color: :backgroundColor,
|
118
|
-
selection_style: :selectionStyle,
|
119
|
-
cell_class_attributes: :cellClassAttributes,
|
120
|
-
accessory_view: :accessoryView,
|
121
|
-
accessory_type: :accessoryType,
|
122
|
-
accessory_checked: :accessoryDefault,
|
123
|
-
remote_image: :remoteImage,
|
124
|
-
subviews: :subViews
|
125
|
-
}
|
126
|
-
mappings.each_pair do |n, old|
|
127
|
-
if data_cell[old]
|
128
|
-
warn "[DEPRECATION] `:#{old}` is deprecated in TableScreens. Use `:#{n}`"
|
129
|
-
data_cell[n] = data_cell[old]
|
130
|
-
end
|
131
|
-
end
|
132
|
-
if data_cell[:styles] && data_cell[:styles][:textLabel]
|
133
|
-
warn "[DEPRECATION] `:textLabel` is deprecated in TableScreens. Use `:label`"
|
134
|
-
data_cell[:styles][:label] = data_cell[:styles][:textLabel]
|
135
|
-
end
|
136
|
-
data_cell
|
137
|
-
end
|
138
|
-
|
139
|
-
def tableView(table_view, cellForRowAtIndexPath:index_path)
|
140
|
-
data_cell = cell_at_section_and_index(index_path.section, index_path.row)
|
141
|
-
return UITableViewCell.alloc.init unless data_cell
|
142
|
-
|
143
|
-
data_cell = self.remap_data_cell(data_cell)
|
144
|
-
|
145
|
-
data_cell[:cell_style] ||= UITableViewCellStyleDefault
|
146
|
-
data_cell[:cell_identifier] ||= "Cell"
|
147
|
-
cell_identifier = data_cell[:cell_identifier]
|
148
|
-
data_cell[:cell_class] ||= ProMotion::TableViewCell
|
149
|
-
|
150
|
-
table_cell = table_view.dequeueReusableCellWithIdentifier(cell_identifier)
|
151
|
-
unless table_cell
|
152
|
-
table_cell = data_cell[:cell_class].alloc.initWithStyle(data_cell[:cell_style], reuseIdentifier:cell_identifier)
|
153
|
-
|
154
|
-
# Add optimizations here
|
155
|
-
table_cell.layer.masksToBounds = true if data_cell[:masks_to_bounds]
|
156
|
-
table_cell.backgroundColor = data_cell[:background_color] if data_cell[:background_color]
|
157
|
-
table_cell.selectionStyle = data_cell[:selection_style] if data_cell[:selection_style]
|
158
|
-
table_cell.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin
|
159
|
-
end
|
160
|
-
|
161
|
-
if data_cell[:cell_class_attributes]
|
162
|
-
set_attributes table_cell, data_cell[:cell_class_attributes]
|
163
|
-
end
|
164
|
-
|
165
|
-
if data_cell[:accessory_view]
|
166
|
-
table_cell.accessoryView = data_cell[:accessory_view]
|
167
|
-
table_cell.accessoryView.autoresizingMask = UIViewAutoresizingFlexibleWidth
|
168
|
-
end
|
169
|
-
|
170
|
-
if data_cell[:accessory_type]
|
171
|
-
table_cell.accessoryType = data_cell[:accessory_type]
|
172
|
-
end
|
173
|
-
|
174
|
-
if data_cell[:accessory] && data_cell[:accessory] == :switch
|
175
|
-
switch_view = UISwitch.alloc.initWithFrame(CGRectZero)
|
176
|
-
switch_view.addTarget(self, action: "accessory_toggled_switch:", forControlEvents:UIControlEventValueChanged)
|
177
|
-
switch_view.on = true if data_cell[:accessory_checked]
|
178
|
-
table_cell.accessoryView = switch_view
|
179
|
-
end
|
180
|
-
|
181
|
-
if data_cell[:subtitle] and table_cell.detailTextLabel
|
182
|
-
table_cell.detailTextLabel.text = data_cell[:subtitle]
|
183
|
-
table_cell.detailTextLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth
|
184
|
-
end
|
185
|
-
|
186
|
-
table_cell.selectionStyle = UITableViewCellSelectionStyleNone if data_cell[:no_select]
|
187
|
-
|
188
|
-
if data_cell[:remote_image]
|
189
|
-
if table_cell.imageView.respond_to?("setImageWithURL:placeholderImage:")
|
190
|
-
url = data_cell[:remote_image][:url]
|
191
|
-
url = NSURL.URLWithString(url) unless url.is_a?(NSURL)
|
192
|
-
placeholder = data_cell[:remote_image][:placeholder]
|
193
|
-
placeholder = UIImage.imageNamed(placeholder) if placeholder.is_a?(String)
|
194
|
-
|
195
|
-
table_cell.image_size = data_cell[:remote_image][:size] if data_cell[:remote_image][:size] && table_cell.respond_to?("image_size=")
|
196
|
-
table_cell.imageView.setImageWithURL(url, placeholderImage: placeholder)
|
197
|
-
table_cell.imageView.layer.masksToBounds = true
|
198
|
-
table_cell.imageView.layer.cornerRadius = data_cell[:remote_image][:radius] if data_cell[:remote_image].has_key?(:radius)
|
199
|
-
else
|
200
|
-
PM.logger.error "ProMotion Warning: to use remote_image with TableScreen you need to include the CocoaPod 'SDWebImage'."
|
201
|
-
end
|
202
|
-
elsif data_cell[:image]
|
203
|
-
table_cell.imageView.layer.masksToBounds = true
|
204
|
-
table_cell.imageView.image = data_cell[:image][:image]
|
205
|
-
table_cell.imageView.layer.cornerRadius = data_cell[:image][:radius] if data_cell[:image][:radius]
|
206
|
-
end
|
207
|
-
|
208
|
-
if data_cell[:subviews]
|
209
|
-
tag_number = 0
|
210
|
-
data_cell[:subviews].each do |view|
|
211
|
-
# Remove an existing view at that tag number
|
212
|
-
tag_number += 1
|
213
|
-
existing_view = table_cell.viewWithTag(tag_number)
|
214
|
-
existing_view.removeFromSuperview if existing_view
|
215
|
-
|
216
|
-
# Add the subview if it exists
|
217
|
-
if view
|
218
|
-
view.tag = tag_number
|
219
|
-
table_cell.addSubview view
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
if data_cell[:details]
|
225
|
-
table_cell.addSubview data_cell[:details][:image]
|
226
|
-
end
|
227
|
-
|
228
|
-
if data_cell[:styles] && data_cell[:styles][:label] && data_cell[:styles][:label][:frame]
|
229
|
-
ui_label = false
|
230
|
-
table_cell.contentView.subviews.each do |view|
|
231
|
-
if view.is_a? UILabel
|
232
|
-
ui_label = true
|
233
|
-
view.text = data_cell[:styles][:label][:text]
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
unless ui_label == true
|
238
|
-
label ||= UILabel.alloc.initWithFrame(CGRectZero)
|
239
|
-
set_attributes label, data_cell[:styles][:label]
|
240
|
-
table_cell.contentView.addSubview label
|
241
|
-
end
|
242
|
-
# hackery
|
243
|
-
table_cell.textLabel.textColor = UIColor.clearColor
|
244
|
-
else
|
245
|
-
cell_title = data_cell[:title]
|
246
|
-
cell_title ||= ""
|
247
|
-
table_cell.textLabel.text = cell_title
|
248
|
-
end
|
249
|
-
|
250
|
-
return table_cell
|
251
|
-
end
|
252
|
-
|
253
|
-
def tableView(tableView, heightForRowAtIndexPath:index_path)
|
254
|
-
cell = cell_at_section_and_index(index_path.section, index_path.row)
|
255
|
-
if cell[:height]
|
256
|
-
cell[:height].to_f
|
257
|
-
else
|
258
|
-
tableView.rowHeight
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
def tableView(table_view, didSelectRowAtIndexPath:index_path)
|
263
|
-
cell = cell_at_section_and_index(index_path.section, index_path.row)
|
264
|
-
table_view.deselectRowAtIndexPath(index_path, animated: true)
|
265
|
-
cell[:arguments] ||= {}
|
266
|
-
cell[:arguments][:cell] = cell if cell[:arguments].is_a?(Hash)
|
267
|
-
trigger_action(cell[:action], cell[:arguments]) if cell[:action]
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|