FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix: Multiple ScrollViews on one page fires scrollEvent simultaneously by hamorphis · Pull Request #2412 · NativeScript/NativeScript · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
33 changes: 24 additions & 9 deletions tns-core-modules/ui/scroll-view/scroll-view.android.ts
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export class ScrollView extends common.ScrollView implements definition.ScrollVi
private _android: org.nativescript.widgets.VerticalScrollView | org.nativescript.widgets.HorizontalScrollView;
private _androidViewId: number = -1;
private handler: android.view.ViewTreeObserver.OnScrollChangedListener;

get android(): android.view.ViewGroup {
return this._android;
}
Expand Down Expand Up @@ -111,20 +110,36 @@ export class ScrollView extends common.ScrollView implements definition.ScrollVi
var that = new WeakRef(this);
this.handler = new android.view.ViewTreeObserver.OnScrollChangedListener({
onScrollChanged: function () {
var rootScrollView = that.get();
if (rootScrollView && rootScrollView.android) {
rootScrollView.notify(<definition.ScrollEventData>{
object: rootScrollView,
eventName: ScrollView.scrollEvent,
scrollX: rootScrollView.android.getScrollX() / utils.layout.getDisplayDensity(),
scrollY: rootScrollView.android.getScrollY() / utils.layout.getDisplayDensity()
});
var owner: ScrollView = that.get();
if (owner){
owner._onScrollChanged();
}
}
});

this._android.getViewTreeObserver().addOnScrollChangedListener(this.handler);
}

private _lastScrollX: number = -1;
private _lastScrollY: number = -1;
private _onScrollChanged(){
if (this.android) {
// Event is only raised if the scroll values differ from the last time in order to wokraround a native Android bug.
// https://github.com/NativeScript/NativeScript/issues/2362
let newScrollX = this.android.getScrollX();
let newScrollY = this.android.getScrollY();
if (newScrollX !== this._lastScrollX || newScrollY !== this._lastScrollY){
this.notify(<definition.ScrollEventData>{
object: this,
eventName: ScrollView.scrollEvent,
scrollX: newScrollX / utils.layout.getDisplayDensity(),
scrollY: newScrollY / utils.layout.getDisplayDensity()
});
this._lastScrollX = newScrollX;
this._lastScrollY = newScrollY;
}
}
}

protected dettachNative() {
this._android.getViewTreeObserver().removeOnScrollChangedListener(this.handler);
Expand Down

Back | FazBrowse Home | New Git URL