mirror of
https://github.com/zhigang1992/ProMotion.git
synced 2026-04-28 20:25:26 +08:00
Initial moveable cells functionality.
This commit is contained in:
@@ -5,6 +5,8 @@ class TestTableScreen < ProMotion::TableScreen
|
||||
tab_bar_item title: 'Test tab title', item: 'test'
|
||||
|
||||
def on_load
|
||||
UIView.animationsEnabled = false if RUBYMOTION_ENV == 'test'
|
||||
|
||||
self.tap_counter = 0
|
||||
set_attributes self.view, { backgroundView: nil, backgroundColor: UIColor.whiteColor }
|
||||
set_nav_bar_button :right, title: UIImage.imageNamed("list.png"), action: :return_to_some_other_screen, type: UIBarButtonItemStylePlain
|
||||
@@ -64,6 +66,23 @@ class TestTableScreen < ProMotion::TableScreen
|
||||
action: :increment_counter_by,
|
||||
arguments: { number: 10 }
|
||||
}]
|
||||
},{
|
||||
title: "Moveable Tests",
|
||||
cells: [{
|
||||
title: 'Cell 1',
|
||||
moveable: true
|
||||
},{
|
||||
title: 'Cell 2',
|
||||
moveable: true
|
||||
},{
|
||||
title: 'Cell 3'
|
||||
},{
|
||||
title: 'Cell 4',
|
||||
moveable: true
|
||||
},{
|
||||
title: 'Cell 5',
|
||||
moveable: false
|
||||
}]
|
||||
}]
|
||||
end
|
||||
|
||||
@@ -120,4 +139,8 @@ class TestTableScreen < ProMotion::TableScreen
|
||||
end
|
||||
end
|
||||
|
||||
def cell_moved(args={})
|
||||
update_table_data
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -23,7 +23,7 @@ module ProMotion
|
||||
|
||||
# TODO: Remove this in ProMotion 2.1. Just for migration purposes.
|
||||
def check_deprecated_styles
|
||||
whitelist = [ :title, :subtitle, :image, :remote_image, :accessory, :selection_style, :action, :long_press_action, :arguments, :cell_style, :cell_class, :cell_identifier, :editing_style, :search_text, :keep_selection, :height, :accessory_type, :style, :properties ]
|
||||
whitelist = [ :title, :subtitle, :image, :remote_image, :accessory, :selection_style, :action, :long_press_action, :arguments, :cell_style, :cell_class, :cell_identifier, :editing_style, :moveable, :search_text, :keep_selection, :height, :accessory_type, :style, :properties ]
|
||||
if (data_cell.keys - whitelist).length > 0
|
||||
PM.logger.deprecated("In #{self.table_screen.class.to_s}#table_data, you should set :#{(data_cell.keys - whitelist).join(", :")} in a `properties:` hash. See TableScreen documentation.")
|
||||
end
|
||||
|
||||
@@ -138,6 +138,21 @@ module ProMotion
|
||||
self.promotion_table_data.search(search_string) if searching?
|
||||
end
|
||||
|
||||
def toggle_edit_mode(animated = true)
|
||||
edit_mode({enabled: !editing?, animated: animated})
|
||||
end
|
||||
|
||||
def edit_mode(args = {})
|
||||
args[:enabled] ||= false
|
||||
args[:animated] ||= true
|
||||
|
||||
setEditing(args[:enabled], animated:args[:animated])
|
||||
end
|
||||
|
||||
def editing?
|
||||
!!isEditing
|
||||
end
|
||||
|
||||
########## Cocoa touch methods #################
|
||||
def numberOfSectionsInTableView(table_view)
|
||||
self.promotion_table_data.sections.length
|
||||
@@ -192,6 +207,28 @@ module ProMotion
|
||||
end
|
||||
end
|
||||
|
||||
def tableView(tableView, canMoveRowAtIndexPath:index_path)
|
||||
data_cell = self.promotion_table_data.cell(index_path: index_path, unfiltered: true)
|
||||
data_cell[:moveable] || false
|
||||
end
|
||||
|
||||
def tableView(tableView, moveRowAtIndexPath:from_index_path, toIndexPath:to_index_path)
|
||||
# TODO - Make this more readable
|
||||
self.promotion_table_data.section(to_index_path.section)[:cells].insert(to_index_path.row, self.promotion_table_data.section(from_index_path.section)[:cells].delete_at(from_index_path.row))
|
||||
|
||||
args = {
|
||||
paths: {
|
||||
from: from_index_path,
|
||||
to: to_index_path
|
||||
},
|
||||
cells: {
|
||||
from: self.promotion_table_data.section(from_index_path.section)[:cells][from_index_path.row],
|
||||
to: self.promotion_table_data.section(to_index_path.section)[:cells][to_index_path.row]
|
||||
}
|
||||
}
|
||||
try(:cell_moved, args)
|
||||
end
|
||||
|
||||
def tableView(tableView, sectionForSectionIndexTitle: title, atIndex: index)
|
||||
return index unless ["{search}", UITableViewIndexSearch].include?(self.table_data_index[0])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user