mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
Scroll-view tests
This commit is contained in:
@ -54,7 +54,7 @@ allTests["WEAK-EVENTS"] = require("./weak-event-listener-tests");
|
|||||||
allTests["CONNECTIVITY"] = require("./connectivity-tests");
|
allTests["CONNECTIVITY"] = require("./connectivity-tests");
|
||||||
|
|
||||||
// allTests["PROXY-VIEW-CONTAINER"] = require("./ui/proxy-view-container/proxy-view-container-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["ACTION-BAR"] = require("./ui/action-bar/action-bar-tests");
|
||||||
// allTests["XML-DECLARATION"] = require("./xml-declaration/xml-declaration-tests");
|
// allTests["XML-DECLARATION"] = require("./xml-declaration/xml-declaration-tests");
|
||||||
// allTests["DOCKLAYOUT"] = require("./ui/layouts/dock-layout-tests");
|
// allTests["DOCKLAYOUT"] = require("./ui/layouts/dock-layout-tests");
|
||||||
|
@ -77,10 +77,15 @@ export abstract class ScrollViewBase extends ContentView implements ScrollViewDe
|
|||||||
|
|
||||||
public abstract scrollToVerticalOffset(value: number, animated: boolean);
|
public abstract scrollToVerticalOffset(value: number, animated: boolean);
|
||||||
public abstract scrollToHorizontalOffset(value: number, animated: boolean);
|
public abstract scrollToHorizontalOffset(value: number, animated: boolean);
|
||||||
|
public abstract _onOrientationChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
export const orientationProperty = new Property<ScrollViewBase, "horizontal" | "vertical">({
|
export const orientationProperty = new Property<ScrollViewBase, "horizontal" | "vertical">({
|
||||||
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") {
|
if (value === "vertical") {
|
||||||
return "vertical";
|
return "vertical";
|
||||||
} else if (value === "horizontal") {
|
} else if (value === "horizontal") {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { ScrollEventData } from "ui/scroll-view";
|
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";
|
export * from "./scroll-view-common";
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ export class ScrollView extends ScrollViewBase {
|
|||||||
|
|
||||||
public _onOrientationChanged() {
|
public _onOrientationChanged() {
|
||||||
if (this._android) {
|
if (this._android) {
|
||||||
var parent = this.parent;
|
const parent = this.parent;
|
||||||
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
parent._removeView(this);
|
parent._removeView(this);
|
||||||
@ -138,11 +138,4 @@ export class ScrollView extends ScrollViewBase {
|
|||||||
this._android.getViewTreeObserver().removeOnScrollChangedListener(this.handler);
|
this._android.getViewTreeObserver().removeOnScrollChangedListener(this.handler);
|
||||||
this.handler = null;
|
this.handler = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
get [orientationProperty.native](): "horizontal" | "vertical" {
|
|
||||||
return "vertical";
|
|
||||||
}
|
|
||||||
set [orientationProperty.native](value: "horizontal" | "vertical") {
|
|
||||||
this._onOrientationChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -64,6 +64,8 @@ declare module "ui/scroll-view" {
|
|||||||
* Raised when a scroll event occurs.
|
* Raised when a scroll event occurs.
|
||||||
*/
|
*/
|
||||||
on(event: "scroll", callback: (args: ScrollEventData) => void, thisArg?: any);
|
on(event: "scroll", callback: (args: ScrollEventData) => void, thisArg?: any);
|
||||||
|
|
||||||
|
_onOrientationChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ScrollEventData extends EventData {
|
interface ScrollEventData extends EventData {
|
||||||
|
@ -28,31 +28,31 @@ class UIScrollViewDelegateImpl extends NSObject implements UIScrollViewDelegate
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ScrollView extends ScrollViewBase {
|
export class ScrollView extends ScrollViewBase {
|
||||||
private _scroll: UIScrollView;
|
public nativeView: UIScrollView;
|
||||||
private _contentMeasuredWidth: number = 0;
|
private _contentMeasuredWidth: number = 0;
|
||||||
private _contentMeasuredHeight: number = 0;
|
private _contentMeasuredHeight: number = 0;
|
||||||
private _delegate: UIScrollViewDelegateImpl;
|
private _delegate: UIScrollViewDelegateImpl;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this._scroll = UIScrollView.new();
|
this.nativeView = UIScrollView.new();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected attachNative() {
|
protected attachNative() {
|
||||||
this._delegate = UIScrollViewDelegateImpl.initWithOwner(new WeakRef(this));
|
this._delegate = UIScrollViewDelegateImpl.initWithOwner(new WeakRef(this));
|
||||||
this._scroll.delegate = this._delegate;
|
this.nativeView.delegate = this._delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected dettachNative() {
|
protected dettachNative() {
|
||||||
this._scroll.delegate = null;
|
this.nativeView.delegate = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
get horizontalOffset(): number {
|
get horizontalOffset(): number {
|
||||||
return this._scroll.contentOffset.x;
|
return this.nativeView.contentOffset.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
get verticalOffset(): number {
|
get verticalOffset(): number {
|
||||||
return this._scroll.contentOffset.y;
|
return this.nativeView.contentOffset.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
get scrollableWidth(): number {
|
get scrollableWidth(): number {
|
||||||
@ -60,7 +60,7 @@ export class ScrollView extends ScrollViewBase {
|
|||||||
return 0;
|
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 {
|
get scrollableHeight(): number {
|
||||||
@ -68,28 +68,28 @@ export class ScrollView extends ScrollViewBase {
|
|||||||
return 0;
|
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 {
|
get ios(): UIView {
|
||||||
return this._scroll;
|
return this.nativeView;
|
||||||
}
|
}
|
||||||
|
|
||||||
get _nativeView(): UIView {
|
get _nativeView(): UIView {
|
||||||
return this._scroll;
|
return this.nativeView;
|
||||||
}
|
}
|
||||||
|
|
||||||
public scrollToVerticalOffset(value: number, animated: boolean) {
|
public scrollToVerticalOffset(value: number, animated: boolean) {
|
||||||
if (this.orientation === "vertical") {
|
if (this.orientation === "vertical") {
|
||||||
const bounds = this._scroll.bounds.size;
|
const bounds = this.nativeView.bounds.size;
|
||||||
this._scroll.scrollRectToVisibleAnimated(CGRectMake(0, value, bounds.width, bounds.height), animated);
|
this.nativeView.scrollRectToVisibleAnimated(CGRectMake(0, value, bounds.width, bounds.height), animated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public scrollToHorizontalOffset(value: number, animated: boolean) {
|
public scrollToHorizontalOffset(value: number, animated: boolean) {
|
||||||
if (this.orientation === "horizontal") {
|
if (this.orientation === "horizontal") {
|
||||||
const bounds = this._scroll.bounds.size;
|
const bounds = this.nativeView.bounds.size;
|
||||||
this._scroll.scrollRectToVisibleAnimated(CGRectMake(value, 0, bounds.width, bounds.height), animated);
|
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);
|
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._contentMeasuredWidth = Math.max(childSize.measuredWidth, style.effectiveMinWidth * density);
|
||||||
this._contentMeasuredHeight = Math.max(childSize.measuredHeight, style.effectiveMinHeight * 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));
|
View.layoutChild(this, this.layoutView, 0, 0, width, Math.max(this._contentMeasuredHeight, height));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public _onOrientationChanged() {
|
||||||
|
// NOOP
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user