chore: default tabs

This commit is contained in:
Nathan Walker
2020-07-09 23:46:02 -07:00
parent 8100cf7089
commit 41f0573d8e
353 changed files with 55344 additions and 55344 deletions

View File

@@ -6,161 +6,161 @@ import { isUserInteractionEnabledProperty } from '../core/view';
export * from './scroll-view-common';
export class ScrollView extends ScrollViewBase {
nativeViewProtected: org.nativescript.widgets.VerticalScrollView | org.nativescript.widgets.HorizontalScrollView;
private _androidViewId: number = -1;
private handler: android.view.ViewTreeObserver.OnScrollChangedListener;
nativeViewProtected: org.nativescript.widgets.VerticalScrollView | org.nativescript.widgets.HorizontalScrollView;
private _androidViewId: number = -1;
private handler: android.view.ViewTreeObserver.OnScrollChangedListener;
get horizontalOffset(): number {
const nativeView = this.nativeViewProtected;
if (!nativeView) {
return 0;
}
get horizontalOffset(): number {
const nativeView = this.nativeViewProtected;
if (!nativeView) {
return 0;
}
return nativeView.getScrollX() / layout.getDisplayDensity();
}
return nativeView.getScrollX() / layout.getDisplayDensity();
}
get verticalOffset(): number {
const nativeView = this.nativeViewProtected;
if (!nativeView) {
return 0;
}
get verticalOffset(): number {
const nativeView = this.nativeViewProtected;
if (!nativeView) {
return 0;
}
return nativeView.getScrollY() / layout.getDisplayDensity();
}
return nativeView.getScrollY() / layout.getDisplayDensity();
}
get scrollableWidth(): number {
const nativeView = this.nativeViewProtected;
if (!nativeView || this.orientation !== 'horizontal') {
return 0;
}
get scrollableWidth(): number {
const nativeView = this.nativeViewProtected;
if (!nativeView || this.orientation !== 'horizontal') {
return 0;
}
return nativeView.getScrollableLength() / layout.getDisplayDensity();
}
return nativeView.getScrollableLength() / layout.getDisplayDensity();
}
get scrollableHeight(): number {
const nativeView = this.nativeViewProtected;
if (!nativeView || this.orientation !== 'vertical') {
return 0;
}
get scrollableHeight(): number {
const nativeView = this.nativeViewProtected;
if (!nativeView || this.orientation !== 'vertical') {
return 0;
}
return nativeView.getScrollableLength() / layout.getDisplayDensity();
}
return nativeView.getScrollableLength() / layout.getDisplayDensity();
}
[isUserInteractionEnabledProperty.setNative](value: boolean) {
// NOTE: different behavior on iOS & Android:
// iOS disables user interaction recursively for all subviews as well
this.nativeViewProtected.setClickable(value);
this.nativeViewProtected.setFocusable(value);
this.nativeViewProtected.setScrollEnabled(value);
}
[isUserInteractionEnabledProperty.setNative](value: boolean) {
// NOTE: different behavior on iOS & Android:
// iOS disables user interaction recursively for all subviews as well
this.nativeViewProtected.setClickable(value);
this.nativeViewProtected.setFocusable(value);
this.nativeViewProtected.setScrollEnabled(value);
}
[isScrollEnabledProperty.getDefault](): boolean {
return this.nativeViewProtected.getScrollEnabled();
}
[isScrollEnabledProperty.setNative](value: boolean) {
this.nativeViewProtected.setScrollEnabled(value);
}
[isScrollEnabledProperty.getDefault](): boolean {
return this.nativeViewProtected.getScrollEnabled();
}
[isScrollEnabledProperty.setNative](value: boolean) {
this.nativeViewProtected.setScrollEnabled(value);
}
[scrollBarIndicatorVisibleProperty.getDefault](): boolean {
return true;
}
[scrollBarIndicatorVisibleProperty.setNative](value: boolean) {
if (this.orientation === 'horizontal') {
this.nativeViewProtected.setHorizontalScrollBarEnabled(value);
} else {
this.nativeViewProtected.setVerticalScrollBarEnabled(value);
}
}
[scrollBarIndicatorVisibleProperty.getDefault](): boolean {
return true;
}
[scrollBarIndicatorVisibleProperty.setNative](value: boolean) {
if (this.orientation === 'horizontal') {
this.nativeViewProtected.setHorizontalScrollBarEnabled(value);
} else {
this.nativeViewProtected.setVerticalScrollBarEnabled(value);
}
}
public scrollToVerticalOffset(value: number, animated: boolean) {
const nativeView = this.nativeViewProtected;
if (nativeView && this.orientation === 'vertical' && this.isScrollEnabled) {
value *= layout.getDisplayDensity();
public scrollToVerticalOffset(value: number, animated: boolean) {
const nativeView = this.nativeViewProtected;
if (nativeView && this.orientation === 'vertical' && this.isScrollEnabled) {
value *= layout.getDisplayDensity();
if (animated) {
nativeView.smoothScrollTo(0, value);
} else {
nativeView.scrollTo(0, value);
}
}
}
if (animated) {
nativeView.smoothScrollTo(0, value);
} else {
nativeView.scrollTo(0, value);
}
}
}
public scrollToHorizontalOffset(value: number, animated: boolean) {
const nativeView = this.nativeViewProtected;
if (nativeView && this.orientation === 'horizontal' && this.isScrollEnabled) {
value *= layout.getDisplayDensity();
public scrollToHorizontalOffset(value: number, animated: boolean) {
const nativeView = this.nativeViewProtected;
if (nativeView && this.orientation === 'horizontal' && this.isScrollEnabled) {
value *= layout.getDisplayDensity();
if (animated) {
nativeView.smoothScrollTo(value, 0);
} else {
nativeView.scrollTo(value, 0);
}
}
}
if (animated) {
nativeView.smoothScrollTo(value, 0);
} else {
nativeView.scrollTo(value, 0);
}
}
}
public createNativeView() {
return this.orientation === 'horizontal' ? new org.nativescript.widgets.HorizontalScrollView(this._context) : new org.nativescript.widgets.VerticalScrollView(this._context);
}
public createNativeView() {
return this.orientation === 'horizontal' ? new org.nativescript.widgets.HorizontalScrollView(this._context) : new org.nativescript.widgets.VerticalScrollView(this._context);
}
public initNativeView(): void {
super.initNativeView();
if (this._androidViewId < 0) {
this._androidViewId = android.view.View.generateViewId();
}
public initNativeView(): void {
super.initNativeView();
if (this._androidViewId < 0) {
this._androidViewId = android.view.View.generateViewId();
}
this.nativeViewProtected.setId(this._androidViewId);
}
this.nativeViewProtected.setId(this._androidViewId);
}
public _onOrientationChanged() {
if (this.nativeViewProtected) {
const parent = this.parent;
if (parent) {
parent._removeView(this);
parent._addView(this);
}
}
}
public _onOrientationChanged() {
if (this.nativeViewProtected) {
const parent = this.parent;
if (parent) {
parent._removeView(this);
parent._addView(this);
}
}
}
protected attachNative() {
const that = new WeakRef(this);
this.handler = new android.view.ViewTreeObserver.OnScrollChangedListener({
onScrollChanged: function () {
const owner: ScrollView = that.get();
if (owner) {
owner._onScrollChanged();
}
},
});
protected attachNative() {
const that = new WeakRef(this);
this.handler = new android.view.ViewTreeObserver.OnScrollChangedListener({
onScrollChanged: function () {
const owner: ScrollView = that.get();
if (owner) {
owner._onScrollChanged();
}
},
});
this.nativeViewProtected.getViewTreeObserver().addOnScrollChangedListener(this.handler);
}
this.nativeViewProtected.getViewTreeObserver().addOnScrollChangedListener(this.handler);
}
private _lastScrollX: number = -1;
private _lastScrollY: number = -1;
private _onScrollChanged() {
const nativeView = this.nativeViewProtected;
if (nativeView) {
// 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 = nativeView.getScrollX();
let newScrollY = nativeView.getScrollY();
if (newScrollX !== this._lastScrollX || newScrollY !== this._lastScrollY) {
this.notify(<ScrollEventData>{
object: this,
eventName: ScrollView.scrollEvent,
scrollX: newScrollX / layout.getDisplayDensity(),
scrollY: newScrollY / layout.getDisplayDensity(),
});
this._lastScrollX = newScrollX;
this._lastScrollY = newScrollY;
}
}
}
private _lastScrollX: number = -1;
private _lastScrollY: number = -1;
private _onScrollChanged() {
const nativeView = this.nativeViewProtected;
if (nativeView) {
// 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 = nativeView.getScrollX();
let newScrollY = nativeView.getScrollY();
if (newScrollX !== this._lastScrollX || newScrollY !== this._lastScrollY) {
this.notify(<ScrollEventData>{
object: this,
eventName: ScrollView.scrollEvent,
scrollX: newScrollX / layout.getDisplayDensity(),
scrollY: newScrollY / layout.getDisplayDensity(),
});
this._lastScrollX = newScrollX;
this._lastScrollY = newScrollY;
}
}
}
protected dettachNative() {
this.nativeViewProtected.getViewTreeObserver().removeOnScrollChangedListener(this.handler);
this.handler = null;
}
protected dettachNative() {
this.nativeViewProtected.getViewTreeObserver().removeOnScrollChangedListener(this.handler);
this.handler = null;
}
}
ScrollView.prototype.recycleNativeView = 'never';

View File

@@ -6,79 +6,79 @@ import { EventData } from '../../data/observable';
* Represents a scrollable area that can have content that is larger than its bounds.
*/
export class ScrollView extends ContentView {
/**
* String value used when hooking to scroll event.
*/
public static scrollEvent: string;
/**
* String value used when hooking to scroll event.
*/
public static scrollEvent: string;
/**
* Gets or sets a value indicating whether scroll is enabled.
*/
isScrollEnabled: boolean;
/**
* Gets or sets a value indicating whether scroll is enabled.
*/
isScrollEnabled: boolean;
/**
* Gets a value that contains the vertical offset of the scrolled content.
*/
verticalOffset: number;
/**
* Gets a value that contains the vertical offset of the scrolled content.
*/
verticalOffset: number;
/**
* Gets a value that contains the horizontal offset of the scrolled content.
*/
horizontalOffset: number;
/**
* Gets a value that contains the horizontal offset of the scrolled content.
*/
horizontalOffset: number;
/**
* Gets the maximum value for the verticalOffset.
*/
scrollableHeight: number;
/**
* Gets the maximum value for the verticalOffset.
*/
scrollableHeight: number;
/**
* Gets the maximum value for the horizontalOffset.
*/
scrollableWidth: number;
/**
* Gets the maximum value for the horizontalOffset.
*/
scrollableWidth: number;
/**
* Toggles scrollbar indicator visibility
*/
scrollBarIndicatorVisible: boolean;
/**
* Toggles scrollbar indicator visibility
*/
scrollBarIndicatorVisible: boolean;
/**
* Scrolls the content the specified vertical offset position.
* @param value The offset value
* @param animated true for animated scroll, false for immediate scroll.
*/
scrollToVerticalOffset(value: number, animated: boolean);
/**
* Scrolls the content the specified vertical offset position.
* @param value The offset value
* @param animated true for animated scroll, false for immediate scroll.
*/
scrollToVerticalOffset(value: number, animated: boolean);
/**
* Scrolls the content the specified horizontal offset position.
* @param value The offset value
* @param animated true for animated scroll, false for immediate scroll.
*/
scrollToHorizontalOffset(value: number, animated: boolean);
/**
* Scrolls the content the specified horizontal offset position.
* @param value The offset value
* @param animated true for animated scroll, false for immediate scroll.
*/
scrollToHorizontalOffset(value: number, animated: boolean);
/**
* Gets or sets direction in which the content can be scrolled.
*/
orientation: Orientation;
/**
* Gets or sets direction in which the content can be scrolled.
*/
orientation: Orientation;
/**
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
* @param callback - Callback function which will be executed when event is raised.
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
*/
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any): void;
/**
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
* @param callback - Callback function which will be executed when event is raised.
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
*/
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any): void;
/**
* Raised when a scroll event occurs.
*/
on(event: 'scroll', callback: (args: ScrollEventData) => void, thisArg?: any): void;
/**
* Raised when a scroll event occurs.
*/
on(event: 'scroll', callback: (args: ScrollEventData) => void, thisArg?: any): void;
_onOrientationChanged(): void;
_onOrientationChanged(): void;
}
export interface ScrollEventData extends EventData {
scrollX: number;
scrollY: number;
scrollX: number;
scrollY: number;
}
export type Orientation = 'horizontal' | 'vertical';

View File

@@ -8,186 +8,186 @@ export * from './scroll-view-common';
const majorVersion = iosUtils.MajorVersion;
class UIScrollViewDelegateImpl extends NSObject implements UIScrollViewDelegate {
private _owner: WeakRef<ScrollView>;
private _owner: WeakRef<ScrollView>;
public static initWithOwner(owner: WeakRef<ScrollView>): UIScrollViewDelegateImpl {
let impl = <UIScrollViewDelegateImpl>UIScrollViewDelegateImpl.new();
impl._owner = owner;
public static initWithOwner(owner: WeakRef<ScrollView>): UIScrollViewDelegateImpl {
let impl = <UIScrollViewDelegateImpl>UIScrollViewDelegateImpl.new();
impl._owner = owner;
return impl;
}
return impl;
}
public scrollViewDidScroll(sv: UIScrollView): void {
let owner = this._owner.get();
if (owner) {
owner.notify(<ScrollEventData>{
object: owner,
eventName: 'scroll',
scrollX: owner.horizontalOffset,
scrollY: owner.verticalOffset,
});
}
}
public scrollViewDidScroll(sv: UIScrollView): void {
let owner = this._owner.get();
if (owner) {
owner.notify(<ScrollEventData>{
object: owner,
eventName: 'scroll',
scrollX: owner.horizontalOffset,
scrollY: owner.verticalOffset,
});
}
}
public static ObjCProtocols = [UIScrollViewDelegate];
public static ObjCProtocols = [UIScrollViewDelegate];
}
export class ScrollView extends ScrollViewBase {
public nativeViewProtected: UIScrollView;
private _contentMeasuredWidth: number = 0;
private _contentMeasuredHeight: number = 0;
private _delegate: UIScrollViewDelegateImpl;
public nativeViewProtected: UIScrollView;
private _contentMeasuredWidth: number = 0;
private _contentMeasuredHeight: number = 0;
private _delegate: UIScrollViewDelegateImpl;
public createNativeView() {
const view = UIScrollView.new();
public createNativeView() {
const view = UIScrollView.new();
return view;
}
return view;
}
initNativeView() {
super.initNativeView();
this.updateScrollBarVisibility(this.scrollBarIndicatorVisible);
this._setNativeClipToBounds();
}
initNativeView() {
super.initNativeView();
this.updateScrollBarVisibility(this.scrollBarIndicatorVisible);
this._setNativeClipToBounds();
}
_setNativeClipToBounds() {
// Always set clipsToBounds for scroll-view
this.nativeViewProtected.clipsToBounds = true;
}
_setNativeClipToBounds() {
// Always set clipsToBounds for scroll-view
this.nativeViewProtected.clipsToBounds = true;
}
protected attachNative() {
this._delegate = UIScrollViewDelegateImpl.initWithOwner(new WeakRef(this));
this.nativeViewProtected.delegate = this._delegate;
}
protected attachNative() {
this._delegate = UIScrollViewDelegateImpl.initWithOwner(new WeakRef(this));
this.nativeViewProtected.delegate = this._delegate;
}
protected dettachNative() {
this.nativeViewProtected.delegate = null;
}
protected dettachNative() {
this.nativeViewProtected.delegate = null;
}
protected updateScrollBarVisibility(value) {
if (!this.nativeViewProtected) {
return;
}
if (this.orientation === 'horizontal') {
this.nativeViewProtected.showsHorizontalScrollIndicator = value;
} else {
this.nativeViewProtected.showsVerticalScrollIndicator = value;
}
}
protected updateScrollBarVisibility(value) {
if (!this.nativeViewProtected) {
return;
}
if (this.orientation === 'horizontal') {
this.nativeViewProtected.showsHorizontalScrollIndicator = value;
} else {
this.nativeViewProtected.showsVerticalScrollIndicator = value;
}
}
get horizontalOffset(): number {
return this.nativeViewProtected ? this.nativeViewProtected.contentOffset.x : 0;
}
get horizontalOffset(): number {
return this.nativeViewProtected ? this.nativeViewProtected.contentOffset.x : 0;
}
get verticalOffset(): number {
return this.nativeViewProtected ? this.nativeViewProtected.contentOffset.y : 0;
}
get verticalOffset(): number {
return this.nativeViewProtected ? this.nativeViewProtected.contentOffset.y : 0;
}
get scrollableWidth(): number {
if (!this.nativeViewProtected || this.orientation !== 'horizontal') {
return 0;
}
get scrollableWidth(): number {
if (!this.nativeViewProtected || this.orientation !== 'horizontal') {
return 0;
}
return Math.max(0, this.nativeViewProtected.contentSize.width - this.nativeViewProtected.bounds.size.width);
}
return Math.max(0, this.nativeViewProtected.contentSize.width - this.nativeViewProtected.bounds.size.width);
}
get scrollableHeight(): number {
if (!this.nativeViewProtected || this.orientation !== 'vertical') {
return 0;
}
get scrollableHeight(): number {
if (!this.nativeViewProtected || this.orientation !== 'vertical') {
return 0;
}
return Math.max(0, this.nativeViewProtected.contentSize.height - this.nativeViewProtected.bounds.size.height);
}
return Math.max(0, this.nativeViewProtected.contentSize.height - this.nativeViewProtected.bounds.size.height);
}
[isScrollEnabledProperty.getDefault](): boolean {
return this.nativeViewProtected.scrollEnabled;
}
[isScrollEnabledProperty.setNative](value: boolean) {
this.nativeViewProtected.scrollEnabled = value;
}
[isScrollEnabledProperty.getDefault](): boolean {
return this.nativeViewProtected.scrollEnabled;
}
[isScrollEnabledProperty.setNative](value: boolean) {
this.nativeViewProtected.scrollEnabled = value;
}
[scrollBarIndicatorVisibleProperty.getDefault](): boolean {
return true;
}
[scrollBarIndicatorVisibleProperty.setNative](value: boolean) {
this.updateScrollBarVisibility(value);
}
[scrollBarIndicatorVisibleProperty.getDefault](): boolean {
return true;
}
[scrollBarIndicatorVisibleProperty.setNative](value: boolean) {
this.updateScrollBarVisibility(value);
}
public scrollToVerticalOffset(value: number, animated: boolean) {
if (this.nativeViewProtected && this.orientation === 'vertical' && this.isScrollEnabled) {
const bounds = this.nativeViewProtected.bounds.size;
this.nativeViewProtected.scrollRectToVisibleAnimated(CGRectMake(0, value, bounds.width, bounds.height), animated);
}
}
public scrollToVerticalOffset(value: number, animated: boolean) {
if (this.nativeViewProtected && this.orientation === 'vertical' && this.isScrollEnabled) {
const bounds = this.nativeViewProtected.bounds.size;
this.nativeViewProtected.scrollRectToVisibleAnimated(CGRectMake(0, value, bounds.width, bounds.height), animated);
}
}
public scrollToHorizontalOffset(value: number, animated: boolean) {
if (this.nativeViewProtected && this.orientation === 'horizontal' && this.isScrollEnabled) {
const bounds = this.nativeViewProtected.bounds.size;
this.nativeViewProtected.scrollRectToVisibleAnimated(CGRectMake(value, 0, bounds.width, bounds.height), animated);
}
}
public scrollToHorizontalOffset(value: number, animated: boolean) {
if (this.nativeViewProtected && this.orientation === 'horizontal' && this.isScrollEnabled) {
const bounds = this.nativeViewProtected.bounds.size;
this.nativeViewProtected.scrollRectToVisibleAnimated(CGRectMake(value, 0, bounds.width, bounds.height), animated);
}
}
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
// Don't call measure because it will measure content twice.
const width = layout.getMeasureSpecSize(widthMeasureSpec);
const widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
// Don't call measure because it will measure content twice.
const width = layout.getMeasureSpecSize(widthMeasureSpec);
const widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
const height = layout.getMeasureSpecSize(heightMeasureSpec);
const heightMode = layout.getMeasureSpecMode(heightMeasureSpec);
const height = layout.getMeasureSpecSize(heightMeasureSpec);
const heightMode = layout.getMeasureSpecMode(heightMeasureSpec);
const child = this.layoutView;
this._contentMeasuredWidth = this.effectiveMinWidth;
this._contentMeasuredHeight = this.effectiveMinHeight;
const child = this.layoutView;
this._contentMeasuredWidth = this.effectiveMinWidth;
this._contentMeasuredHeight = this.effectiveMinHeight;
if (child) {
let childSize: { measuredWidth: number; measuredHeight: number };
if (this.orientation === 'vertical') {
childSize = View.measureChild(this, child, widthMeasureSpec, layout.makeMeasureSpec(0, layout.UNSPECIFIED));
} else {
childSize = View.measureChild(this, child, layout.makeMeasureSpec(0, layout.UNSPECIFIED), heightMeasureSpec);
}
if (child) {
let childSize: { measuredWidth: number; measuredHeight: number };
if (this.orientation === 'vertical') {
childSize = View.measureChild(this, child, widthMeasureSpec, layout.makeMeasureSpec(0, layout.UNSPECIFIED));
} else {
childSize = View.measureChild(this, child, layout.makeMeasureSpec(0, layout.UNSPECIFIED), heightMeasureSpec);
}
this._contentMeasuredWidth = Math.max(childSize.measuredWidth, this.effectiveMinWidth);
this._contentMeasuredHeight = Math.max(childSize.measuredHeight, this.effectiveMinHeight);
}
this._contentMeasuredWidth = Math.max(childSize.measuredWidth, this.effectiveMinWidth);
this._contentMeasuredHeight = Math.max(childSize.measuredHeight, this.effectiveMinHeight);
}
const widthAndState = View.resolveSizeAndState(this._contentMeasuredWidth, width, widthMode, 0);
const heightAndState = View.resolveSizeAndState(this._contentMeasuredHeight, height, heightMode, 0);
const widthAndState = View.resolveSizeAndState(this._contentMeasuredWidth, width, widthMode, 0);
const heightAndState = View.resolveSizeAndState(this._contentMeasuredHeight, height, heightMode, 0);
this.setMeasuredDimension(widthAndState, heightAndState);
}
this.setMeasuredDimension(widthAndState, heightAndState);
}
public onLayout(left: number, top: number, right: number, bottom: number): void {
const insets = this.getSafeAreaInsets();
let width = right - left - insets.right - insets.left;
let height = bottom - top - insets.bottom - insets.top;
public onLayout(left: number, top: number, right: number, bottom: number): void {
const insets = this.getSafeAreaInsets();
let width = right - left - insets.right - insets.left;
let height = bottom - top - insets.bottom - insets.top;
const nativeView = this.nativeViewProtected;
const nativeView = this.nativeViewProtected;
if (majorVersion > 10) {
// Disable automatic adjustment of scroll view insets
// Consider exposing this as property with all 4 modes
// https://developer.apple.com/documentation/uikit/uiscrollview/contentinsetadjustmentbehavior
nativeView.contentInsetAdjustmentBehavior = 2;
}
if (majorVersion > 10) {
// Disable automatic adjustment of scroll view insets
// Consider exposing this as property with all 4 modes
// https://developer.apple.com/documentation/uikit/uiscrollview/contentinsetadjustmentbehavior
nativeView.contentInsetAdjustmentBehavior = 2;
}
let scrollWidth = width + insets.left + insets.right;
let scrollHeight = height + insets.top + insets.bottom;
if (this.orientation === 'horizontal') {
scrollWidth = Math.max(this._contentMeasuredWidth + insets.left + insets.right, scrollWidth);
width = Math.max(this._contentMeasuredWidth, width);
} else {
scrollHeight = Math.max(this._contentMeasuredHeight + insets.top + insets.bottom, scrollHeight);
height = Math.max(this._contentMeasuredHeight, height);
}
let scrollWidth = width + insets.left + insets.right;
let scrollHeight = height + insets.top + insets.bottom;
if (this.orientation === 'horizontal') {
scrollWidth = Math.max(this._contentMeasuredWidth + insets.left + insets.right, scrollWidth);
width = Math.max(this._contentMeasuredWidth, width);
} else {
scrollHeight = Math.max(this._contentMeasuredHeight + insets.top + insets.bottom, scrollHeight);
height = Math.max(this._contentMeasuredHeight, height);
}
nativeView.contentSize = CGSizeMake(layout.toDeviceIndependentPixels(scrollWidth), layout.toDeviceIndependentPixels(scrollHeight));
View.layoutChild(this, this.layoutView, insets.left, insets.top, insets.left + width, insets.top + height);
}
nativeView.contentSize = CGSizeMake(layout.toDeviceIndependentPixels(scrollWidth), layout.toDeviceIndependentPixels(scrollHeight));
View.layoutChild(this, this.layoutView, insets.left, insets.top, insets.left + width, insets.top + height);
}
public _onOrientationChanged() {
this.updateScrollBarVisibility(this.scrollBarIndicatorVisible);
}
public _onOrientationChanged() {
this.updateScrollBarVisibility(this.scrollBarIndicatorVisible);
}
}
ScrollView.prototype.recycleNativeView = 'auto';

View File

@@ -8,111 +8,111 @@ import { EventData } from '../../data/observable';
@CSSType('ScrollView')
export abstract class ScrollViewBase extends ContentView implements ScrollViewDefinition {
private _scrollChangeCount: number = 0;
public static scrollEvent = 'scroll';
private _scrollChangeCount: number = 0;
public static scrollEvent = 'scroll';
public orientation: Orientation;
public scrollBarIndicatorVisible: boolean;
public isScrollEnabled: boolean;
public orientation: Orientation;
public scrollBarIndicatorVisible: boolean;
public isScrollEnabled: boolean;
public addEventListener(arg: string, callback: any, thisArg?: any) {
super.addEventListener(arg, callback, thisArg);
public addEventListener(arg: string, callback: any, thisArg?: any) {
super.addEventListener(arg, callback, thisArg);
if (arg === ScrollViewBase.scrollEvent) {
this._scrollChangeCount++;
this.attach();
}
}
if (arg === ScrollViewBase.scrollEvent) {
this._scrollChangeCount++;
this.attach();
}
}
public removeEventListener(arg: string, callback: any, thisArg?: any) {
super.removeEventListener(arg, callback, thisArg);
public removeEventListener(arg: string, callback: any, thisArg?: any) {
super.removeEventListener(arg, callback, thisArg);
if (arg === ScrollViewBase.scrollEvent) {
this._scrollChangeCount--;
this.dettach();
}
}
if (arg === ScrollViewBase.scrollEvent) {
this._scrollChangeCount--;
this.dettach();
}
}
@profile
public onLoaded() {
super.onLoaded();
@profile
public onLoaded() {
super.onLoaded();
this.attach();
}
this.attach();
}
public onUnloaded() {
super.onUnloaded();
public onUnloaded() {
super.onUnloaded();
this.dettach();
}
this.dettach();
}
private attach() {
if (this._scrollChangeCount > 0 && this.isLoaded) {
this.attachNative();
}
}
private attach() {
if (this._scrollChangeCount > 0 && this.isLoaded) {
this.attachNative();
}
}
private dettach() {
if (this._scrollChangeCount === 0 && this.isLoaded) {
this.dettachNative();
}
}
private dettach() {
if (this._scrollChangeCount === 0 && this.isLoaded) {
this.dettachNative();
}
}
protected attachNative() {
//
}
protected attachNative() {
//
}
protected dettachNative() {
//
}
protected dettachNative() {
//
}
get horizontalOffset(): number {
return 0;
}
get horizontalOffset(): number {
return 0;
}
get verticalOffset(): number {
return 0;
}
get verticalOffset(): number {
return 0;
}
get scrollableWidth(): number {
return 0;
}
get scrollableWidth(): number {
return 0;
}
get scrollableHeight(): number {
return 0;
}
get scrollableHeight(): number {
return 0;
}
public abstract scrollToVerticalOffset(value: number, animated: boolean);
public abstract scrollToHorizontalOffset(value: number, animated: boolean);
public abstract _onOrientationChanged();
public abstract scrollToVerticalOffset(value: number, animated: boolean);
public abstract scrollToHorizontalOffset(value: number, animated: boolean);
public abstract _onOrientationChanged();
}
export interface ScrollViewBase {
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any);
on(event: 'scroll', callback: (args: ScrollEventData) => void, thisArg?: any);
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any);
on(event: 'scroll', callback: (args: ScrollEventData) => void, thisArg?: any);
}
const converter = makeParser<Orientation>(makeValidator('horizontal', 'vertical'));
export const orientationProperty = new Property<ScrollViewBase, Orientation>({
name: 'orientation',
defaultValue: 'vertical',
affectsLayout: true,
valueChanged: (target: ScrollViewBase, oldValue: Orientation, newValue: Orientation) => {
target._onOrientationChanged();
},
valueConverter: converter,
name: 'orientation',
defaultValue: 'vertical',
affectsLayout: true,
valueChanged: (target: ScrollViewBase, oldValue: Orientation, newValue: Orientation) => {
target._onOrientationChanged();
},
valueConverter: converter,
});
orientationProperty.register(ScrollViewBase);
export const scrollBarIndicatorVisibleProperty = new Property<ScrollViewBase, boolean>({
name: 'scrollBarIndicatorVisible',
defaultValue: true,
valueConverter: booleanConverter,
name: 'scrollBarIndicatorVisible',
defaultValue: true,
valueConverter: booleanConverter,
});
scrollBarIndicatorVisibleProperty.register(ScrollViewBase);
export const isScrollEnabledProperty = new Property<ScrollViewBase, boolean>({
name: 'isScrollEnabled',
defaultValue: true,
valueConverter: booleanConverter,
name: 'isScrollEnabled',
defaultValue: true,
valueConverter: booleanConverter,
});
isScrollEnabledProperty.register(ScrollViewBase);