mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Layouts are now implemented natively for Android.
This commit is contained in:
25
ui/layouts/stack-layout/stack-layout-common.ts
Normal file
25
ui/layouts/stack-layout/stack-layout-common.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
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");
|
||||
|
||||
// on Android we explicitly set propertySettings to None because android will invalidate its layout (skip unnecessary native call).
|
||||
var AffectsLayout = global.android ? dependencyObservable.PropertyMetadataSettings.None : dependencyObservable.PropertyMetadataSettings.AffectsLayout;
|
||||
|
||||
function validateOrientation(value: any): boolean {
|
||||
return value === enums.Orientation.vertical || value === enums.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));
|
||||
|
||||
get orientation(): string {
|
||||
return this._getValue(StackLayout.orientationProperty);
|
||||
}
|
||||
set orientation(value: string) {
|
||||
this._setValue(StackLayout.orientationProperty, value);
|
||||
}
|
||||
}
|
||||
38
ui/layouts/stack-layout/stack-layout.android.ts
Normal file
38
ui/layouts/stack-layout/stack-layout.android.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import proxy = require("ui/core/proxy");
|
||||
import common = require("ui/layouts/stack-layout/stack-layout-common");
|
||||
import enums = require("ui/enums");
|
||||
|
||||
// merge the exports of the common file with the exports of this file
|
||||
declare var exports;
|
||||
require("utils/module-merge").merge(common, exports);
|
||||
|
||||
export class StackLayout extends common.StackLayout {
|
||||
|
||||
static setNativeOrientationProperty(data: dependencyObservable.PropertyChangeData): void {
|
||||
var stackLayout = <StackLayout>data.object;
|
||||
var nativeView = stackLayout._nativeView;
|
||||
if (data.newValue === enums.Orientation.vertical) {
|
||||
nativeView.setOrientation(org.nativescript.widgets.Orientation.vertical);
|
||||
}
|
||||
else {
|
||||
nativeView.setOrientation(org.nativescript.widgets.Orientation.horzontal);
|
||||
}
|
||||
}
|
||||
|
||||
private _layout: org.nativescript.widgets.StackLayout;
|
||||
|
||||
get android(): org.nativescript.widgets.StackLayout {
|
||||
return this._layout;
|
||||
}
|
||||
|
||||
get _nativeView(): org.nativescript.widgets.StackLayout {
|
||||
return this._layout;
|
||||
}
|
||||
|
||||
public _createUI() {
|
||||
this._layout = new org.nativescript.widgets.StackLayout(this._context);
|
||||
}
|
||||
}
|
||||
|
||||
(<proxy.PropertyMetadata>common.StackLayout.orientationProperty.metadata).onSetNativeValue = StackLayout.setNativeOrientationProperty;
|
||||
4
ui/layouts/stack-layout/stack-layout.d.ts
vendored
4
ui/layouts/stack-layout/stack-layout.d.ts
vendored
@@ -1,11 +1,11 @@
|
||||
declare module "ui/layouts/stack-layout" {
|
||||
import layout = require("ui/layouts/layout");
|
||||
import layout = require("ui/layouts/layout-base");
|
||||
import dependencyObservable = require("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.Layout {
|
||||
class StackLayout extends layout.LayoutBase {
|
||||
|
||||
/**
|
||||
* Represents the observable property backing the orientation property of each StackLayout instance.
|
||||
|
||||
@@ -1,35 +1,16 @@
|
||||
import layouts = require("ui/layouts/layout");
|
||||
import definition = require("ui/layouts/stack-layout");
|
||||
import utils = require("utils/utils");
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import utils = require("utils/utils");
|
||||
import enums = require("ui/enums");
|
||||
import proxy = require("ui/core/proxy");
|
||||
import view = require("ui/core/view");
|
||||
import common = require("ui/layouts/stack-layout/stack-layout-common");
|
||||
|
||||
function validateOrientation(value: any): boolean {
|
||||
return value === enums.Orientation.vertical || value === enums.Orientation.horizontal;
|
||||
}
|
||||
// merge the exports of the common file with the exports of this file
|
||||
declare var exports;
|
||||
require("utils/module-merge").merge(common, exports);
|
||||
|
||||
export var orientationProperty = new dependencyObservable.Property(
|
||||
"orientation",
|
||||
"StackLayout",
|
||||
new proxy.PropertyMetadata(enums.Orientation.vertical,
|
||||
dependencyObservable.PropertyMetadataSettings.AffectsLayout,
|
||||
undefined,
|
||||
validateOrientation)
|
||||
);
|
||||
|
||||
export class StackLayout extends layouts.Layout implements definition.StackLayout {
|
||||
export class StackLayout extends common.StackLayout {
|
||||
|
||||
private _totalLength = 0;
|
||||
|
||||
get orientation(): string {
|
||||
return this._getValue(orientationProperty);
|
||||
}
|
||||
set orientation(value: string) {
|
||||
this._setValue(orientationProperty, value);
|
||||
}
|
||||
|
||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
var density = utils.layout.getDisplayDensity();
|
||||
Reference in New Issue
Block a user