Add infinite scrolling and pull to refresh to timeline
This commit is contained in:
parent
a6f8565ab3
commit
8526613189
|
@ -68,6 +68,12 @@
|
||||||
</tableView>
|
</tableView>
|
||||||
<navigationItem key="navigationItem" id="SQS-FM-ReS"/>
|
<navigationItem key="navigationItem" id="SQS-FM-ReS"/>
|
||||||
<simulatedTabBarMetrics key="simulatedBottomBarMetrics"/>
|
<simulatedTabBarMetrics key="simulatedBottomBarMetrics"/>
|
||||||
|
<refreshControl key="refreshControl" opaque="NO" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" id="K3b-fx-67z">
|
||||||
|
<autoresizingMask key="autoresizingMask"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="refreshStatuses:" destination="6nb-nb-cMm" eventType="valueChanged" id="ndM-Yv-ISu"/>
|
||||||
|
</connections>
|
||||||
|
</refreshControl>
|
||||||
</tableViewController>
|
</tableViewController>
|
||||||
<placeholder placeholderIdentifier="IBFirstResponder" id="5GO-2u-UCr" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
<placeholder placeholderIdentifier="IBFirstResponder" id="5GO-2u-UCr" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||||
</objects>
|
</objects>
|
||||||
|
|
|
@ -20,10 +20,18 @@ class StatusesTableViewController: UITableViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var newer: RequestRange?
|
||||||
|
var older: RequestRange?
|
||||||
|
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
MastodonController.shared.client.run(Timelines.home()) { result in
|
MastodonController.shared.client.run(Timelines.home()) { result in
|
||||||
guard case let .success(statuses, _) = result else { fatalError() }
|
guard case let .success(statuses, pagination) = result else { fatalError() }
|
||||||
self.statuses = statuses
|
self.statuses = statuses
|
||||||
|
self.newer = pagination?.previous
|
||||||
|
self.older = pagination?.next
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.tableView.reloadData()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,14 +40,18 @@ class StatusesTableViewController: UITableViewController {
|
||||||
|
|
||||||
tableView.rowHeight = UITableView.automaticDimension
|
tableView.rowHeight = UITableView.automaticDimension
|
||||||
tableView.estimatedRowHeight = 140
|
tableView.estimatedRowHeight = 140
|
||||||
|
|
||||||
// Uncomment the following line to preserve selection between presentations
|
|
||||||
// self.clearsSelectionOnViewWillAppear = false
|
|
||||||
|
|
||||||
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
|
|
||||||
// self.navigationItem.rightBarButtonItem = self.editButtonItem
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// MARK: - Navigation
|
||||||
|
|
||||||
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
||||||
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
||||||
|
// Get the new view controller using segue.destination.
|
||||||
|
// Pass the selected object to the new view controller.
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// MARK: - Table view data source
|
// MARK: - Table view data source
|
||||||
|
|
||||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
|
@ -47,7 +59,6 @@ class StatusesTableViewController: UITableViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
// #warning Incomplete implementation, return the number of rows
|
|
||||||
return statuses.count
|
return statuses.count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,50 +75,32 @@ class StatusesTableViewController: UITableViewController {
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
|
||||||
|
if indexPath.row == statuses.count - 1 {
|
||||||
|
guard let older = older else { return }
|
||||||
|
|
||||||
/*
|
MastodonController.shared.client.run(Timelines.home(range: older)) { result in
|
||||||
// Override to support conditional editing of the table view.
|
guard case let .success(newStatuses, pagination) = result else { fatalError() }
|
||||||
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
|
self.older = pagination?.next
|
||||||
// Return false if you do not want the specified item to be editable.
|
self.statuses.append(contentsOf: newStatuses)
|
||||||
return true
|
}
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
// Override to support editing the table view.
|
|
||||||
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
|
|
||||||
if editingStyle == .delete {
|
|
||||||
// Delete the row from the data source
|
|
||||||
tableView.deleteRows(at: [indexPath], with: .fade)
|
|
||||||
} else if editingStyle == .insert {
|
|
||||||
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
@IBAction func refreshStatuses(_ sender: Any) {
|
||||||
// Override to support rearranging the table view.
|
guard let newer = newer else { return }
|
||||||
override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
|
|
||||||
|
MastodonController.shared.client.run(Timelines.home(range: newer)) { result in
|
||||||
}
|
guard case let .success(newStatuses, pagination) = result else { fatalError() }
|
||||||
*/
|
self.newer = pagination?.previous
|
||||||
|
self.statuses.insert(contentsOf: newStatuses, at: 0)
|
||||||
/*
|
DispatchQueue.main.async {
|
||||||
// Override to support conditional rearranging of the table view.
|
self.refreshControl?.endRefreshing()
|
||||||
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
|
|
||||||
// Return false if you do not want the item to be re-orderable.
|
// maintain the current position in the list (don't scroll to the top)
|
||||||
return true
|
self.tableView.scrollToRow(at: IndexPath(row: newStatuses.count, section: 0), at: .top, animated: false)
|
||||||
}
|
}
|
||||||
*/
|
}
|
||||||
|
}
|
||||||
/*
|
|
||||||
// MARK: - Navigation
|
|
||||||
|
|
||||||
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
||||||
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
|
||||||
// Get the new view controller using segue.destination.
|
|
||||||
// Pass the selected object to the new view controller.
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue