mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
scroll event implemented
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import proxy = require("ui/core/proxy");
|
||||
import enums = require("ui/enums");
|
||||
import definition = require("ui/scroll-view");
|
||||
import contentView = require("ui/content-view");
|
||||
|
||||
function isValidOrientation(value: any): boolean {
|
||||
return value === enums.Orientation.vertical || value === enums.Orientation.horizontal;
|
||||
@@ -13,4 +15,92 @@ export var orientationProperty = new dependencyObservable.Property(
|
||||
dependencyObservable.PropertyMetadataSettings.AffectsLayout,
|
||||
undefined,
|
||||
isValidOrientation)
|
||||
);
|
||||
);
|
||||
|
||||
export class ScrollView extends contentView.ContentView implements definition.ScrollView {
|
||||
private _scrollEventAttached: boolean;
|
||||
public static scrollEvent = "scroll";
|
||||
|
||||
get orientation(): string {
|
||||
return this._getValue(orientationProperty);
|
||||
}
|
||||
set orientation(value: string) {
|
||||
this._setValue(orientationProperty, value);
|
||||
}
|
||||
|
||||
public addEventListener(arg: string, callback: any, thisArg?: any) {
|
||||
super.addEventListener(arg, callback, thisArg);
|
||||
|
||||
if (arg === definition.ScrollView.scrollEvent) {
|
||||
this.attach();
|
||||
}
|
||||
}
|
||||
|
||||
public removeEventListener(arg: string, callback: any, thisArg?: any) {
|
||||
super.addEventListener(arg, callback, thisArg);
|
||||
|
||||
if (arg === definition.ScrollView.scrollEvent) {
|
||||
this.dettach();
|
||||
}
|
||||
}
|
||||
|
||||
public onLoaded() {
|
||||
super.onLoaded();
|
||||
|
||||
this.attach();
|
||||
}
|
||||
|
||||
public onUnloaded() {
|
||||
super.onUnloaded();
|
||||
|
||||
this.dettach();
|
||||
}
|
||||
|
||||
private attach() {
|
||||
if (!this._scrollEventAttached && this.isLoaded) {
|
||||
this._scrollEventAttached = true;
|
||||
|
||||
this.attachNative();
|
||||
}
|
||||
}
|
||||
|
||||
private dettach() {
|
||||
if (this._scrollEventAttached && this.isLoaded) {
|
||||
this._scrollEventAttached = false;
|
||||
|
||||
this.dettachNative();
|
||||
}
|
||||
}
|
||||
|
||||
protected attachNative() {
|
||||
//
|
||||
}
|
||||
|
||||
protected dettachNative() {
|
||||
//
|
||||
}
|
||||
|
||||
get horizontalOffset(): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
get verticalOffset(): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
get scrollableWidth(): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
get scrollableHeight(): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public scrollToVerticalOffset(value: number, animated: boolean) {
|
||||
//
|
||||
}
|
||||
|
||||
public scrollToHorizontalOffset(value: number, animated: boolean) {
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user