-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #679 from clearsightstudio/extract-table-methods
Extract methods from tablescreen for reuse in modules for redpotion.
- Loading branch information
Showing
8 changed files
with
154 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module ProMotion | ||
module TableDataBuilder | ||
def set_data_cell_defaults(data_cell) | ||
data_cell[:cell_style] ||= begin | ||
data_cell[:subtitle] ? UITableViewCellStyleSubtitle : UITableViewCellStyleDefault | ||
end | ||
data_cell[:cell_class] ||= PM::TableViewCell | ||
data_cell[:cell_identifier] ||= build_cell_identifier(data_cell) | ||
data_cell[:properties] ||= data_cell[:style] || data_cell[:styles] | ||
|
||
data_cell[:accessory] = { | ||
view: data_cell[:accessory], | ||
value: data_cell[:accessory_value], | ||
action: data_cell[:accessory_action], | ||
arguments: data_cell[:accessory_arguments] | ||
} unless data_cell[:accessory].nil? || data_cell[:accessory].is_a?(Hash) | ||
|
||
data_cell | ||
end | ||
|
||
def build_cell_identifier(data_cell) | ||
ident = "#{data_cell[:cell_class].to_s}" | ||
ident << "-#{data_cell[:stylename].to_s}" if data_cell[:stylename] # For Teacup | ||
ident << "-accessory" if data_cell[:accessory] | ||
ident << "-subtitle" if data_cell[:subtitle] | ||
ident << "-remoteimage" if data_cell[:remote_image] | ||
ident << "-image" if data_cell[:image] | ||
ident | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module ProMotion | ||
module TableBuilder | ||
def trigger_action(action, arguments, index_path) | ||
return PM.logger.info "Action not implemented: #{action.to_s}" unless self.respond_to?(action) | ||
case self.method(action).arity | ||
when 0 then self.send(action) # Just call the method | ||
when 2 then self.send(action, arguments, index_path) # Send arguments and index path | ||
else self.send(action, arguments) # Send arguments | ||
end | ||
end | ||
|
||
def create_table_cell(data_cell) | ||
new_cell = nil | ||
table_cell = table_view.dequeueReusableCellWithIdentifier(data_cell[:cell_identifier]) || begin | ||
new_cell = data_cell[:cell_class].alloc.initWithStyle(data_cell[:cell_style], reuseIdentifier:data_cell[:cell_identifier]) | ||
new_cell.extend(PM::TableViewCellModule) unless new_cell.is_a?(PM::TableViewCellModule) | ||
new_cell.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin | ||
new_cell.clipsToBounds = true # fix for changed default in 7.1 | ||
on_cell_created new_cell, data_cell | ||
new_cell | ||
end | ||
table_cell.setup(data_cell, self) if table_cell.respond_to?(:setup) | ||
on_cell_reused(table_cell, data_cell) if !new_cell | ||
table_cell | ||
end | ||
|
||
def on_cell_created(new_cell, data_cell) | ||
new_cell.send(:on_load) if new_cell.respond_to?(:on_load) | ||
end | ||
|
||
def on_cell_reused(cell, data) | ||
cell.send(:on_reuse) if cell.respond_to?(:on_reuse) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
module TableClassMethods | ||
def table_style | ||
UITableViewStylePlain | ||
end | ||
|
||
def row_height(height, args={}) | ||
if height == :auto | ||
if UIDevice.currentDevice.systemVersion.to_f < 8.0 | ||
height = args[:estimated] || 44.0 | ||
PM.logger.warn "Using `row_height :auto` is not supported in iOS 7 apps. Setting to #{height}." | ||
else | ||
height = UITableViewAutomaticDimension | ||
end | ||
end | ||
args[:estimated] ||= height unless height == UITableViewAutomaticDimension | ||
@row_height = { height: height, estimated: args[:estimated] || 44.0 } | ||
end | ||
|
||
def get_row_height | ||
@row_height ||= nil | ||
end | ||
|
||
# Searchable | ||
def searchable(params={}) | ||
@searchable_params = params | ||
@searchable = true | ||
end | ||
|
||
def get_searchable_params | ||
@searchable_params ||= nil | ||
end | ||
|
||
def get_searchable | ||
@searchable ||= false | ||
end | ||
|
||
# Refreshable | ||
def refreshable(params = {}) | ||
@refreshable_params = params | ||
@refreshable = true | ||
end | ||
|
||
def get_refreshable | ||
@refreshable ||= false | ||
end | ||
|
||
def get_refreshable_params | ||
@refreshable_params ||= nil | ||
end | ||
|
||
# Indexable | ||
def indexable(params = {}) | ||
@indexable_params = params | ||
@indexable = true | ||
end | ||
|
||
def get_indexable | ||
@indexable ||= false | ||
end | ||
|
||
def get_indexable_params | ||
@indexable_params ||= nil | ||
end | ||
|
||
# Longpressable | ||
def longpressable(params = {}) | ||
@longpressable_params = params | ||
@longpressable = true | ||
end | ||
|
||
def get_longpressable | ||
@longpressable ||= false | ||
end | ||
|
||
def get_longpressable_params | ||
@longpressable_params ||= nil | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
module ProMotion | ||
class TableScreen < TableViewController | ||
include ProMotion::ScreenModule | ||
include ProMotion::TableBuilder | ||
include ProMotion::Table | ||
end | ||
end |