diff --git a/tests/app/testRunner.ts b/tests/app/testRunner.ts index 5dab96928..6c55643f1 100644 --- a/tests/app/testRunner.ts +++ b/tests/app/testRunner.ts @@ -54,7 +54,7 @@ allTests["WEAK-EVENTS"] = require("./weak-event-listener-tests"); allTests["CONNECTIVITY"] = require("./connectivity-tests"); // allTests["PROXY-VIEW-CONTAINER"] = require("./ui/proxy-view-container/proxy-view-container-tests") -// allTests["SCROLL-VIEW"] = require("./ui/scroll-view/scroll-view-tests"); +allTests["SCROLL-VIEW"] = require("./ui/scroll-view/scroll-view-tests"); // allTests["ACTION-BAR"] = require("./ui/action-bar/action-bar-tests"); // allTests["XML-DECLARATION"] = require("./xml-declaration/xml-declaration-tests"); // allTests["DOCKLAYOUT"] = require("./ui/layouts/dock-layout-tests"); diff --git a/tns-core-modules/ui/scroll-view/scroll-view-common.ts b/tns-core-modules/ui/scroll-view/scroll-view-common.ts index ec7c7710b..7fb96ea3c 100644 --- a/tns-core-modules/ui/scroll-view/scroll-view-common.ts +++ b/tns-core-modules/ui/scroll-view/scroll-view-common.ts @@ -77,10 +77,15 @@ export abstract class ScrollViewBase extends ContentView implements ScrollViewDe public abstract scrollToVerticalOffset(value: number, animated: boolean); public abstract scrollToHorizontalOffset(value: number, animated: boolean); + public abstract _onOrientationChanged(); } export const orientationProperty = new Property({ - name: "orientation", defaultValue: "vertical", affectsLayout: true, valueConverter: (value) => { + name: "orientation", defaultValue: "vertical", affectsLayout: true, + valueChanged: (target: ScrollViewBase, oldValue: "horizontal" | "vertical", newValue: "horizontal" | "vertical") => { + target._onOrientationChanged(); + }, + valueConverter: (value) => { if (value === "vertical") { return "vertical"; } else if (value === "horizontal") { diff --git a/tns-core-modules/ui/scroll-view/scroll-view.android.ts b/tns-core-modules/ui/scroll-view/scroll-view.android.ts index 56505333f..c51680508 100644 --- a/tns-core-modules/ui/scroll-view/scroll-view.android.ts +++ b/tns-core-modules/ui/scroll-view/scroll-view.android.ts @@ -1,5 +1,5 @@ import { ScrollEventData } from "ui/scroll-view"; -import { ScrollViewBase, orientationProperty, layout } from "./scroll-view-common"; +import { ScrollViewBase, layout } from "./scroll-view-common"; export * from "./scroll-view-common"; @@ -87,7 +87,7 @@ export class ScrollView extends ScrollViewBase { public _onOrientationChanged() { if (this._android) { - var parent = this.parent; + const parent = this.parent; if (parent) { parent._removeView(this); @@ -138,11 +138,4 @@ export class ScrollView extends ScrollViewBase { this._android.getViewTreeObserver().removeOnScrollChangedListener(this.handler); this.handler = null; } - - get [orientationProperty.native](): "horizontal" | "vertical" { - return "vertical"; - } - set [orientationProperty.native](value: "horizontal" | "vertical") { - this._onOrientationChanged(); - } } \ No newline at end of file diff --git a/tns-core-modules/ui/scroll-view/scroll-view.d.ts b/tns-core-modules/ui/scroll-view/scroll-view.d.ts index c92f26723..408d46d7c 100644 --- a/tns-core-modules/ui/scroll-view/scroll-view.d.ts +++ b/tns-core-modules/ui/scroll-view/scroll-view.d.ts @@ -64,6 +64,8 @@ declare module "ui/scroll-view" { * Raised when a scroll event occurs. */ on(event: "scroll", callback: (args: ScrollEventData) => void, thisArg?: any); + + _onOrientationChanged(); } interface ScrollEventData extends EventData { diff --git a/tns-core-modules/ui/scroll-view/scroll-view.ios.ts b/tns-core-modules/ui/scroll-view/scroll-view.ios.ts index 5419eaf49..745f2338a 100644 --- a/tns-core-modules/ui/scroll-view/scroll-view.ios.ts +++ b/tns-core-modules/ui/scroll-view/scroll-view.ios.ts @@ -28,31 +28,31 @@ class UIScrollViewDelegateImpl extends NSObject implements UIScrollViewDelegate } export class ScrollView extends ScrollViewBase { - private _scroll: UIScrollView; + public nativeView: UIScrollView; private _contentMeasuredWidth: number = 0; private _contentMeasuredHeight: number = 0; private _delegate: UIScrollViewDelegateImpl; constructor() { super(); - this._scroll = UIScrollView.new(); + this.nativeView = UIScrollView.new(); } protected attachNative() { this._delegate = UIScrollViewDelegateImpl.initWithOwner(new WeakRef(this)); - this._scroll.delegate = this._delegate; + this.nativeView.delegate = this._delegate; } protected dettachNative() { - this._scroll.delegate = null; + this.nativeView.delegate = null; } get horizontalOffset(): number { - return this._scroll.contentOffset.x; + return this.nativeView.contentOffset.x; } get verticalOffset(): number { - return this._scroll.contentOffset.y; + return this.nativeView.contentOffset.y; } get scrollableWidth(): number { @@ -60,7 +60,7 @@ export class ScrollView extends ScrollViewBase { return 0; } - return Math.max(0, this._scroll.contentSize.width - this._scroll.bounds.size.width) / layout.getDisplayDensity(); + return Math.max(0, this.nativeView.contentSize.width - this.nativeView.bounds.size.width) / layout.getDisplayDensity(); } get scrollableHeight(): number { @@ -68,28 +68,28 @@ export class ScrollView extends ScrollViewBase { return 0; } - return Math.max(0, this._scroll.contentSize.height - this._scroll.bounds.size.height) / layout.getDisplayDensity(); + return Math.max(0, this.nativeView.contentSize.height - this.nativeView.bounds.size.height) / layout.getDisplayDensity(); } get ios(): UIView { - return this._scroll; + return this.nativeView; } get _nativeView(): UIView { - return this._scroll; + return this.nativeView; } public scrollToVerticalOffset(value: number, animated: boolean) { if (this.orientation === "vertical") { - const bounds = this._scroll.bounds.size; - this._scroll.scrollRectToVisibleAnimated(CGRectMake(0, value, bounds.width, bounds.height), animated); + const bounds = this.nativeView.bounds.size; + this.nativeView.scrollRectToVisibleAnimated(CGRectMake(0, value, bounds.width, bounds.height), animated); } } public scrollToHorizontalOffset(value: number, animated: boolean) { if (this.orientation === "horizontal") { - const bounds = this._scroll.bounds.size; - this._scroll.scrollRectToVisibleAnimated(CGRectMake(value, 0, bounds.width, bounds.height), animated); + const bounds = this.nativeView.bounds.size; + this.nativeView.scrollRectToVisibleAnimated(CGRectMake(value, 0, bounds.width, bounds.height), animated); } } @@ -117,7 +117,7 @@ export class ScrollView extends ScrollViewBase { childSize = View.measureChild(this, child, layout.makeMeasureSpec(0, layout.UNSPECIFIED), heightMeasureSpec); } - this._scroll.contentSize = CGSizeMake(childSize.measuredWidth, childSize.measuredHeight); + this.nativeView.contentSize = CGSizeMake(childSize.measuredWidth, childSize.measuredHeight); this._contentMeasuredWidth = Math.max(childSize.measuredWidth, style.effectiveMinWidth * density); this._contentMeasuredHeight = Math.max(childSize.measuredHeight, style.effectiveMinHeight * density); } @@ -140,4 +140,8 @@ export class ScrollView extends ScrollViewBase { View.layoutChild(this, this.layoutView, 0, 0, width, Math.max(this._contentMeasuredHeight, height)); } } + + public _onOrientationChanged() { + // NOOP + } } \ No newline at end of file