lib/ProMotion/table/table.rb in ProMotion-2.3.0 vs lib/ProMotion/table/table.rb in ProMotion-2.3.1
- old
+ new
@@ -18,10 +18,11 @@
set_up_header_footer_views
set_up_searchable
set_up_refreshable
set_up_longpressable
set_up_row_height
+ set_up_accessibility
end
def check_table_data
PM.logger.error "Missing #table_data method in TableScreen #{self.class.to_s}." unless self.respond_to?(:table_data)
end
@@ -87,10 +88,23 @@
self.view.rowHeight = params[:height]
self.view.estimatedRowHeight = params[:estimated]
end
end
+ def editable?
+ self.promotion_table_data.sections.each do |section|
+ section[:cells].each do |cell|
+ return true if [:insert,:delete].include?(cell[:editing_style])
+ end
+ end
+ false
+ end
+
+ def set_up_accessibility
+ self.extend(Editable) if editable?
+ end
+
def searching?
self.promotion_table_data.filtered
end
def original_search_string
@@ -153,18 +167,26 @@
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
- new_cell.send(:on_load) if new_cell.respond_to?(:on_load)
+ on_cell_created new_cell, data_cell
new_cell
end
table_cell.setup(data_cell, self) if table_cell.respond_to?(:setup)
- table_cell.send(:on_reuse) if !new_cell && table_cell.respond_to?(:on_reuse)
+ 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
+
def update_table_data(args = {})
args = { index_paths: args } unless args.is_a?(Hash)
self.update_table_view_data(self.table_data, args)
self.promotion_table_data.search(search_string) if searching?
@@ -233,12 +255,14 @@
def tableView(_, editingStyleForRowAtIndexPath: index_path)
data_cell = self.promotion_table_data.cell(index_path: index_path, unfiltered: true)
map_cell_editing_style(data_cell[:editing_style])
end
- def tableView(_, commitEditingStyle: editing_style, forRowAtIndexPath: index_path)
- if editing_style == UITableViewCellEditingStyleDelete
- delete_row(index_path)
+ module Editable
+ def tableView(_, commitEditingStyle: editing_style, forRowAtIndexPath: index_path)
+ if editing_style == UITableViewCellEditingStyleDelete
+ delete_row(index_path)
+ end
end
end
def tableView(_, canMoveRowAtIndexPath:index_path)
data_cell = self.promotion_table_data.cell(index_path: index_path, unfiltered: true)