mirror of
https://github.com/zhigang1992/ProMotion.git
synced 2026-06-04 19:45:35 +08:00
Initial pass at a refreshable table.
This commit is contained in:
57
lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb
Normal file
57
lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb
Normal file
@@ -0,0 +1,57 @@
|
||||
module ProMotion::MotionTable
|
||||
module RefreshableTable
|
||||
def make_refreshable
|
||||
@refresh = UIRefreshControl.alloc.init
|
||||
@refresh.attributedTitle = NSAttributedString.alloc.initWithString("Pull to Refresh")
|
||||
@refresh.addTarget(self, action:'refreshView:', forControlEvents:UIControlEventValueChanged)
|
||||
self.refreshControl = @refresh
|
||||
# @on_refresh = get_refreshable_block
|
||||
|
||||
|
||||
# params[:content_controller] ||= params[:contentController]
|
||||
# params[:data_source] ||= params[:searchResultsDataSource]
|
||||
# params[:search_results_delegate] ||= params[:searchResultsDelegate]
|
||||
|
||||
# params[:frame] ||= CGRectMake(0, 0, 320, 44) # TODO: Don't hardcode this...
|
||||
# params[:content_controller] ||= self
|
||||
# params[:delegate] ||= self
|
||||
# params[:data_source] ||= self
|
||||
# params[:search_results_delegate] ||= self
|
||||
|
||||
# search_bar = UISearchBar.alloc.initWithFrame(params[:frame])
|
||||
# search_bar.autoresizingMask = UIViewAutoresizingFlexibleWidth
|
||||
|
||||
# if params[:search_bar] && params[:search_bar][:placeholder]
|
||||
# search_bar.placeholder = params[:search_bar][:placeholder]
|
||||
# end
|
||||
|
||||
# @contacts_search_display_controller = UISearchDisplayController.alloc.initWithSearchBar(search_bar, contentsController: params[:content_controller])
|
||||
# @contacts_search_display_controller.delegate = params[:delegate]
|
||||
# @contacts_search_display_controller.searchResultsDataSource = params[:data_source]
|
||||
# @contacts_search_display_controller.searchResultsDelegate = params[:search_results_delegate]
|
||||
|
||||
# self.table_view.tableHeaderView = search_bar
|
||||
end
|
||||
alias :makeRefreshable :make_refreshable
|
||||
|
||||
######### iOS methods, headless camel case #######
|
||||
|
||||
# UIRefreshControl Delegates
|
||||
def refreshView(refresh)
|
||||
refresh.attributedTitle = NSAttributedString.alloc.initWithString("Refreshing data...")
|
||||
@on_refresh.call if @on_refresh
|
||||
end
|
||||
|
||||
def on_refresh(&block)
|
||||
@on_refresh = block
|
||||
end
|
||||
|
||||
def end_refreshing
|
||||
return unless @refresh
|
||||
|
||||
@refresh.attributedTitle = NSAttributedString.alloc.initWithString("Last updated on #{Time.now.strftime("%H:%M:%S")}")
|
||||
@refresh.endRefreshing
|
||||
self.update_table_data
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -7,6 +7,9 @@ module ProMotion::MotionTable
|
||||
if self.class.respond_to?(:get_searchable) && self.class.get_searchable
|
||||
self.make_searchable(content_controller: self, search_bar: self.class.get_searchable_params)
|
||||
end
|
||||
if self.class.respond_to?(:get_refreshable) && self.class.get_refreshable
|
||||
self.make_refreshable
|
||||
end
|
||||
end
|
||||
|
||||
# @param [Array] Array of table data
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module ProMotion::MotionTable
|
||||
module GroupedTable
|
||||
include SectionedTable
|
||||
include RefreshableTable
|
||||
|
||||
def table_view
|
||||
@table_view ||= UITableView.alloc.initWithFrame(self.view.frame, style:UITableViewStyleGrouped)
|
||||
|
||||
@@ -2,6 +2,7 @@ module ProMotion::MotionTable
|
||||
module PlainTable
|
||||
include SectionedTable
|
||||
include SearchableTable
|
||||
include RefreshableTable
|
||||
|
||||
def table_view
|
||||
@table_view ||= UITableView.alloc.initWithFrame(self.view.frame, style:UITableViewStylePlain)
|
||||
|
||||
@@ -2,6 +2,7 @@ module ProMotion
|
||||
module TableScreenModule
|
||||
include MotionTable::PlainTable
|
||||
include MotionTable::SearchableTable
|
||||
include MotionTable::RefreshableTable
|
||||
include ProMotion::ScreenModule
|
||||
|
||||
def update_table_data
|
||||
@@ -9,6 +10,7 @@ module ProMotion
|
||||
end
|
||||
|
||||
module TableClassMethods
|
||||
# Searchable
|
||||
def searchable(params={})
|
||||
@searchable_params = params
|
||||
@searchable = true
|
||||
@@ -21,6 +23,17 @@ module ProMotion
|
||||
def get_searchable
|
||||
@searchable ||= false
|
||||
end
|
||||
|
||||
# Refreshable
|
||||
def refreshable(&block)
|
||||
@refreshable_block = block
|
||||
@refreshable = true
|
||||
end
|
||||
|
||||
def get_refreshable
|
||||
@refreshable ||= false
|
||||
end
|
||||
|
||||
end
|
||||
def self.included(base)
|
||||
base.extend(ClassMethods)
|
||||
|
||||
Reference in New Issue
Block a user