Last active
September 28, 2018 07:30
-
-
Save marcel-ploch/4561505aa5c57066c77a4f26d2a06f54 to your computer and use it in GitHub Desktop.
Own UITableViewDelegate
This file contains hidden or 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
import {NewUITableViewDelegateImpl as NewUITableViewDelegateImplBase} from './NewUITableViewDelegateImpl'; | |
export class NewUITableViewDelegateImpl extends NSObject implements UITableViewDelegate { | |
public static ObjCProtocols: any = [ UITableViewDelegate ]; | |
private _originalDelegate: UITableViewDelegate; | |
private _callback: any; | |
private _isLoading: Boolean = false; | |
public static initWithOriginalDelegate(originalDelegate: UITableViewDelegate, loadMorePlayers: any): NewUITableViewDelegateImpl { | |
const delegate: any = <NewUITableViewDelegateImpl>NewUITableViewDelegateImpl.new(); | |
delegate._originalDelegate = originalDelegate; | |
delegate._callback = loadMorePlayers; | |
delegate._isLoading = false; | |
return delegate; | |
} | |
public tableViewWillDisplayCellForRowAtIndexPath(tableView: UITableView, cell: UITableViewCell, indexPath: NSIndexPath): void { | |
return this._originalDelegate.tableViewWillDisplayCellForRowAtIndexPath(tableView, cell, indexPath); | |
} | |
public tableViewWillSelectRowAtIndexPath(tableView: UITableView, indexPath: NSIndexPath): NSIndexPath { | |
return this._originalDelegate.tableViewWillSelectRowAtIndexPath(tableView, indexPath); | |
} | |
public tableViewDidSelectRowAtIndexPath(tableView: UITableView, indexPath: NSIndexPath): NSIndexPath { | |
tableView.deselectRowAtIndexPathAnimated(indexPath, true); | |
return indexPath; | |
} | |
public tableViewHeightForRowAtIndexPath(tableView: UITableView, indexPath: NSIndexPath): number { | |
return this._originalDelegate.tableViewHeightForRowAtIndexPath(tableView, indexPath); | |
} | |
public scrollViewDidScroll(scrollView: UIScrollView): void { | |
if (scrollView.contentOffset.y < -20 && !this._isLoading) { | |
// Call from here load more players up | |
this._isLoading = true; | |
setTimeout(() => { | |
this._callback(); | |
}, 0) | |
} | |
} | |
public setDataLoaded(): void { | |
// this._isLoading = false; | |
this._isLoading = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment