mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
GridLayout now calls virtual methods when rows/columns are set through XML.
Added test. Improved code readability.
This commit is contained in:
@@ -1,21 +1,20 @@
|
||||
import layouts = require("ui/layouts/layout-base");
|
||||
import definition = require("ui/layouts/stack-layout");
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import enums = require("ui/enums");
|
||||
import proxy = require("ui/core/proxy");
|
||||
import definition = require("ui/layouts/stack-layout");
|
||||
import platform = require("platform");
|
||||
import {LayoutBase} from "ui/layouts/layout-base";
|
||||
import {View} from "ui/core/view";
|
||||
import {Orientation} from "ui/enums";
|
||||
import {PropertyMetadata} from "ui/core/proxy";
|
||||
import {Property, PropertyMetadataSettings} from "ui/core/dependency-observable";
|
||||
|
||||
// on Android we explicitly set propertySettings to None because android will invalidate its layout (skip unnecessary native call).
|
||||
var AffectsLayout = platform.device.os === platform.platformNames.android ? dependencyObservable.PropertyMetadataSettings.None : dependencyObservable.PropertyMetadataSettings.AffectsLayout;
|
||||
var AffectsLayout = platform.device.os === platform.platformNames.android ? PropertyMetadataSettings.None : PropertyMetadataSettings.AffectsLayout;
|
||||
|
||||
function validateOrientation(value: any): boolean {
|
||||
return value === enums.Orientation.vertical || value === enums.Orientation.horizontal;
|
||||
return value === Orientation.vertical || value === Orientation.horizontal;
|
||||
}
|
||||
|
||||
export class StackLayout extends layouts.LayoutBase implements definition.StackLayout {
|
||||
|
||||
public static orientationProperty = new dependencyObservable.Property("orientation","StackLayout",
|
||||
new proxy.PropertyMetadata(enums.Orientation.vertical, AffectsLayout, undefined, validateOrientation));
|
||||
export class StackLayout extends LayoutBase implements definition.StackLayout {
|
||||
public static orientationProperty = new Property("orientation", "StackLayout", new PropertyMetadata(Orientation.vertical, AffectsLayout, undefined, validateOrientation));
|
||||
|
||||
get orientation(): string {
|
||||
return this._getValue(StackLayout.orientationProperty);
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import proxy = require("ui/core/proxy");
|
||||
import common = require("./stack-layout-common");
|
||||
import enums = require("ui/enums");
|
||||
import common = require("./stack-layout-common");
|
||||
import {Orientation} from "ui/enums";
|
||||
import {PropertyMetadata} from "ui/core/proxy";
|
||||
import {PropertyChangeData} from "ui/core/dependency-observable";
|
||||
|
||||
global.moduleMerge(common, exports);
|
||||
|
||||
function setNativeOrientationProperty(data: PropertyChangeData): void {
|
||||
var stackLayout = <StackLayout>data.object;
|
||||
var nativeView = stackLayout._nativeView;
|
||||
nativeView.setOrientation(data.newValue === Orientation.vertical ? org.nativescript.widgets.Orientation.vertical : org.nativescript.widgets.Orientation.horizontal);
|
||||
}
|
||||
|
||||
(<PropertyMetadata>common.StackLayout.orientationProperty.metadata).onSetNativeValue = setNativeOrientationProperty;
|
||||
|
||||
export class StackLayout extends common.StackLayout {
|
||||
|
||||
static setNativeOrientationProperty(data: dependencyObservable.PropertyChangeData): void {
|
||||
var stackLayout = <StackLayout>data.object;
|
||||
var nativeView = stackLayout._nativeView;
|
||||
nativeView.setOrientation(data.newValue === enums.Orientation.vertical ? org.nativescript.widgets.Orientation.vertical : org.nativescript.widgets.Orientation.horizontal);
|
||||
}
|
||||
|
||||
private _layout: org.nativescript.widgets.StackLayout;
|
||||
|
||||
get android(): org.nativescript.widgets.StackLayout {
|
||||
@@ -26,6 +27,4 @@ export class StackLayout extends common.StackLayout {
|
||||
public _createUI() {
|
||||
this._layout = new org.nativescript.widgets.StackLayout(this._context);
|
||||
}
|
||||
}
|
||||
|
||||
(<proxy.PropertyMetadata>common.StackLayout.orientationProperty.metadata).onSetNativeValue = StackLayout.setNativeOrientationProperty;
|
||||
}
|
||||
9
ui/layouts/stack-layout/stack-layout.d.ts
vendored
9
ui/layouts/stack-layout/stack-layout.d.ts
vendored
@@ -1,16 +1,15 @@
|
||||
declare module "ui/layouts/stack-layout" {
|
||||
import layout = require("ui/layouts/layout-base");
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import {LayoutBase} from "ui/layouts/layout-base";
|
||||
import {Property} from "ui/core/dependency-observable";
|
||||
|
||||
/**
|
||||
* A Layout that arranges its children horizontally or vertically. The direction can be set by orientation property.
|
||||
*/
|
||||
class StackLayout extends layout.LayoutBase {
|
||||
|
||||
class StackLayout extends LayoutBase {
|
||||
/**
|
||||
* Represents the observable property backing the orientation property of each StackLayout instance.
|
||||
*/
|
||||
public static orientationProperty: dependencyObservable.Property;
|
||||
public static orientationProperty: Property;
|
||||
|
||||
/**
|
||||
* Gets or sets if layout should be horizontal or vertical.
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import utils = require("utils/utils");
|
||||
import {Orientation, VerticalAlignment, HorizontalAlignment} from "ui/enums";
|
||||
import common = require("./stack-layout-common");
|
||||
import utils = require("utils/utils");
|
||||
import {View} from "ui/core/view";
|
||||
import common = require("./stack-layout-common");
|
||||
import {Orientation, VerticalAlignment, HorizontalAlignment} from "ui/enums";
|
||||
import {CommonLayoutParams, nativeLayoutParamsProperty} from "ui/styling/style";
|
||||
|
||||
global.moduleMerge(common, exports);
|
||||
|
||||
export class StackLayout extends common.StackLayout {
|
||||
|
||||
private _totalLength = 0;
|
||||
|
||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
@@ -104,7 +103,6 @@ export class StackLayout extends common.StackLayout {
|
||||
}
|
||||
|
||||
private layoutVertical(left: number, top: number, right: number, bottom: number): void {
|
||||
|
||||
var density = utils.layout.getDisplayDensity();
|
||||
var paddingLeft = this.paddingLeft * density;
|
||||
var paddingRight = this.paddingRight * density;
|
||||
@@ -146,7 +144,6 @@ export class StackLayout extends common.StackLayout {
|
||||
}
|
||||
|
||||
private layoutHorizontal(left: number, top: number, right: number, bottom: number): void {
|
||||
|
||||
var density = utils.layout.getDisplayDensity();
|
||||
var paddingLeft = this.paddingLeft * density;
|
||||
var paddingRight = this.paddingRight * density;
|
||||
|
||||
Reference in New Issue
Block a user