mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
more code + tests updates
This commit is contained in:
@@ -285,7 +285,7 @@ class ScrollLayoutTest extends testModule.UITest<scrollViewModule.ScrollView> {
|
||||
|
||||
this.testView.scrollToVerticalOffset(100, false);
|
||||
TKUnit.waitUntilReady(function () { return scrollY > 0; });
|
||||
TKUnit.assertEqual(this.testView.verticalOffset, scrollY);
|
||||
TKUnit.assertEqual(scrollY, this.testView.verticalOffset);
|
||||
}
|
||||
|
||||
public test_scrollView_horizontal_raised_scroll_event() {
|
||||
@@ -307,7 +307,55 @@ class ScrollLayoutTest extends testModule.UITest<scrollViewModule.ScrollView> {
|
||||
|
||||
this.testView.scrollToHorizontalOffset(100, false);
|
||||
TKUnit.waitUntilReady(function () { return scrollX > 0; });
|
||||
TKUnit.assertEqual(this.testView.horizontalOffset, scrollX);
|
||||
TKUnit.assertEqual(scrollX, this.testView.horizontalOffset);
|
||||
}
|
||||
|
||||
public test_scrollView_vertical_raised_scroll_event_after_loaded() {
|
||||
this.testView.orientation = enums.Orientation.vertical;
|
||||
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
|
||||
var scrollY: number;
|
||||
this.testView.on(scrollViewModule.ScrollView.scrollEvent, (args: scrollViewModule.ScrollEventData) => {
|
||||
scrollY = args.scrollY;
|
||||
});
|
||||
|
||||
this.testView.width = 200;
|
||||
this.testView.height = 300;
|
||||
|
||||
var btn = new button.Button();
|
||||
btn.text = "test";
|
||||
btn.height = 500;
|
||||
this.testView.content = btn;
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
this.testView.scrollToVerticalOffset(100, false);
|
||||
TKUnit.waitUntilReady(function () { return scrollY > 0; });
|
||||
TKUnit.assertEqual(scrollY, this.testView.verticalOffset);
|
||||
}
|
||||
|
||||
public test_scrollView_horizontal_raised_scroll_event_after_loaded() {
|
||||
this.testView.orientation = enums.Orientation.horizontal;
|
||||
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
|
||||
var scrollX: number;
|
||||
this.testView.on(scrollViewModule.ScrollView.scrollEvent, (args: scrollViewModule.ScrollEventData) => {
|
||||
scrollX = args.scrollX;
|
||||
});
|
||||
|
||||
this.testView.width = 200;
|
||||
this.testView.height = 300;
|
||||
|
||||
var btn = new button.Button();
|
||||
btn.text = "test";
|
||||
btn.width = 500;
|
||||
this.testView.content = btn;
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
this.testView.scrollToHorizontalOffset(100, false);
|
||||
TKUnit.waitUntilReady(function () { return scrollX > 0; });
|
||||
TKUnit.assertEqual(scrollX, this.testView.horizontalOffset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ export var orientationProperty = new dependencyObservable.Property(
|
||||
);
|
||||
|
||||
export class ScrollView extends contentView.ContentView implements definition.ScrollView {
|
||||
private _scrollEventAttached: boolean;
|
||||
private _scrollChangeCount: number = 0;
|
||||
public static scrollEvent = "scroll";
|
||||
|
||||
get orientation(): string {
|
||||
@@ -32,6 +32,7 @@ export class ScrollView extends contentView.ContentView implements definition.Sc
|
||||
super.addEventListener(arg, callback, thisArg);
|
||||
|
||||
if (arg === definition.ScrollView.scrollEvent) {
|
||||
this._scrollChangeCount++;
|
||||
this.attach();
|
||||
}
|
||||
}
|
||||
@@ -40,6 +41,7 @@ export class ScrollView extends contentView.ContentView implements definition.Sc
|
||||
super.addEventListener(arg, callback, thisArg);
|
||||
|
||||
if (arg === definition.ScrollView.scrollEvent) {
|
||||
this._scrollChangeCount--;
|
||||
this.dettach();
|
||||
}
|
||||
}
|
||||
@@ -57,23 +59,19 @@ export class ScrollView extends contentView.ContentView implements definition.Sc
|
||||
}
|
||||
|
||||
private attach() {
|
||||
if (!this._scrollEventAttached && this.isLoaded) {
|
||||
this._scrollEventAttached = true;
|
||||
|
||||
if (this._scrollChangeCount > 0 && this.isLoaded) {
|
||||
this.attachNative();
|
||||
}
|
||||
}
|
||||
|
||||
private dettach() {
|
||||
if (this._scrollEventAttached && this.isLoaded) {
|
||||
this._scrollEventAttached = false;
|
||||
|
||||
if (this._scrollChangeCount === 0 && this.isLoaded) {
|
||||
this.dettachNative();
|
||||
}
|
||||
}
|
||||
|
||||
protected attachNative() {
|
||||
//
|
||||
//
|
||||
}
|
||||
|
||||
protected dettachNative() {
|
||||
|
||||
Reference in New Issue
Block a user