From cea78d679f8245a1efd9cd85425535cb695a22e7 Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Tue, 10 Nov 2015 10:35:16 +0200 Subject: [PATCH] UIScrollViewDelegateImpl improved --- ui/scroll-view/scroll-view.ios.ts | 34 ++++++++++++++++--------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/ui/scroll-view/scroll-view.ios.ts b/ui/scroll-view/scroll-view.ios.ts index a3e1c1d8b..700f6aca8 100644 --- a/ui/scroll-view/scroll-view.ios.ts +++ b/ui/scroll-view/scroll-view.ios.ts @@ -7,29 +7,31 @@ import utils = require("utils/utils"); global.moduleMerge(common, exports); class UIScrollViewDelegateImpl extends NSObject implements UIScrollViewDelegate { - public static ObjCProtocols = [UIScrollViewDelegate]; + private _owner: WeakRef; - static new(): UIScrollViewDelegateImpl { - return super.new(); + public static initWithOwner(owner: WeakRef): UIScrollViewDelegateImpl { + let impl = UIScrollViewDelegateImpl.new(); + impl._owner = owner; + return impl; } - private _owner: ScrollView; + public scrollViewDidScroll(sv: UIScrollView): void { + let owner = this._owner.get(); + if (!owner) { + return; + } - public initWithOwner(owner: ScrollView): UIScrollViewDelegateImpl { - this._owner = owner; - return this; - } - - public scrollViewDidScroll(textView: UIScrollView): void { - if (this._owner) { - this._owner.notify({ - object: this._owner, + if (owner) { + owner.notify({ + object: owner, eventName: definition.ScrollView.scrollEvent, - scrollX: this._owner.horizontalOffset, - scrollY: this._owner.verticalOffset + scrollX: owner.horizontalOffset, + scrollY: owner.verticalOffset }); } } + + public static ObjCProtocols = [UIScrollViewDelegate]; } export class ScrollView extends common.ScrollView implements definition.ScrollView { @@ -44,7 +46,7 @@ export class ScrollView extends common.ScrollView implements definition.ScrollVi } protected attachNative() { - this._delegate = UIScrollViewDelegateImpl.new().initWithOwner(this); + this._delegate = UIScrollViewDelegateImpl.initWithOwner(new WeakRef(this)); this._scroll.delegate = this._delegate; }