diff --git a/ui/scroll-view/scroll-view.android.ts b/ui/scroll-view/scroll-view.android.ts index 76ee084f7..db5a36cb6 100644 --- a/ui/scroll-view/scroll-view.android.ts +++ b/ui/scroll-view/scroll-view.android.ts @@ -101,6 +101,17 @@ export class ScrollView extends contentView.ContentView implements definition.Sc } this._android.setId(this._androidViewId); + + var that = new WeakRef(this); + this._android.getViewTreeObserver().addOnScrollChangedListener(new android.view.ViewTreeObserver.OnScrollChangedListener({ + onScrollChanged: function () { + var rootScrollView = that.get(); + if (rootScrollView && rootScrollView.android) { + var scrollX = rootScrollView.android.getScrollX(); //for horizontalScrollView + var scrollY = rootScrollView.android.getScrollY(); //for verticalScrollView + } + } + }); } public _onOrientationChanged(oldValue: string, newValue: string) { diff --git a/ui/scroll-view/scroll-view.d.ts b/ui/scroll-view/scroll-view.d.ts index c6b2542a7..a69d750f5 100644 --- a/ui/scroll-view/scroll-view.d.ts +++ b/ui/scroll-view/scroll-view.d.ts @@ -46,5 +46,18 @@ declare module "ui/scroll-view" { * Gets or sets direction in which the content can be scrolled. */ orientation: string; + + /** + * A basic method signature to hook an event listener (shortcut alias to the addEventListener method). + * @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change"). + * @param callback - Callback function which will be executed when event is raised. + * @param thisArg - An optional parameter which will be used as `this` context for callback execution. + */ + on(eventNames: string, callback: (data: observable.EventData) => void, thisArg?: any); + + /** + * Raised when a tap event occurs. + */ + on(event: "scroll", callback: (args: observable.EventData) => void, thisArg?: any); } } \ No newline at end of file diff --git a/ui/scroll-view/scroll-view.ios.ts b/ui/scroll-view/scroll-view.ios.ts index 43e3385de..dfe97584d 100644 --- a/ui/scroll-view/scroll-view.ios.ts +++ b/ui/scroll-view/scroll-view.ios.ts @@ -7,14 +7,46 @@ import utils = require("utils/utils"); global.moduleMerge(common, exports); +class UIScrollViewDelegateImpl extends NSObject implements UIScrollViewDelegate { + public static ObjCProtocols = [UIScrollViewDelegate]; + + static new(): UIScrollViewDelegateImpl { + return super.new(); + } + + private _owner: ScrollView; + + public initWithOwner(owner: ScrollView): UIScrollViewDelegateImpl { + this._owner = owner; + return this; + } + + public scrollViewDidScroll(textView: UIScrollView): void { + + } +} + export class ScrollView extends contentView.ContentView implements definition.ScrollView { private _scroll: UIScrollView; private _contentMeasuredWidth: number = 0; private _contentMeasuredHeight: number = 0; + private _delegate: UIScrollViewDelegateImpl; constructor() { super(); this._scroll = new UIScrollView(); + + this._delegate = UIScrollViewDelegateImpl.new().initWithOwner(this); + } + + public onLoaded() { + super.onLoaded(); + this._scroll.delegate = this._delegate; + } + + public onUnloaded() { + this._scroll.delegate = null; + super.onUnloaded(); } get orientation(): string {