From b5ab387ebd38fb997c4e3b5d19754d22aad6bea8 Mon Sep 17 00:00:00 2001 From: Panayot Cankov Date: Fri, 30 Sep 2016 17:36:17 +0300 Subject: [PATCH] Fix the LayoutParams --- tests/app/ui/helper.ts | 5 ++--- tns-core-modules/ui/core/dependency-observable.ts | 14 +++++++------- tns-core-modules/ui/core/view.android.ts | 12 +++++++++--- .../flexbox-layout/flexbox-layout.android.ts | 12 ++++++++++-- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/tests/app/ui/helper.ts b/tests/app/ui/helper.ts index 4a0f1b238..c2bdfdcf0 100644 --- a/tests/app/ui/helper.ts +++ b/tests/app/ui/helper.ts @@ -69,9 +69,8 @@ export function buildUIAndRunTest(controlToTest, testFunction, pageCss?) { clearPage(); let newPage = getCurrentPage(); newPage.content = controlToTest; - if (pageCss) { - newPage.css = pageCss; - } + + newPage.css = pageCss; testFunction([controlToTest, newPage]); newPage.content = null; diff --git a/tns-core-modules/ui/core/dependency-observable.ts b/tns-core-modules/ui/core/dependency-observable.ts index 631bd6854..47e6d3e70 100644 --- a/tns-core-modules/ui/core/dependency-observable.ts +++ b/tns-core-modules/ui/core/dependency-observable.ts @@ -252,13 +252,13 @@ export class DependencyObservable extends Observable implements definition.Depen let currentValue = entry.effectiveValue; let newValue = this.getEffectiveValueAndUpdateEntry(currentValueSource, entry, property); if (!property.equalityComparer(currentValue, newValue)) { - // // If we fallback to defalutValue - remove propertyEntry. - // if (entry.valueSource === ValueSource.Default) { - // delete this._propertyEntries[property.id]; - // } - // else { - entry.effectiveValue = newValue; - // } + // If we fallback to defalutValue - remove propertyEntry. + if (entry.valueSource === ValueSource.Default) { + delete this._propertyEntries[property.id]; + } + else { + entry.effectiveValue = newValue; + } this._onPropertyChanged(property, currentValue, newValue); } diff --git a/tns-core-modules/ui/core/view.android.ts b/tns-core-modules/ui/core/view.android.ts index b59fac4b0..7ee3cf10e 100644 --- a/tns-core-modules/ui/core/view.android.ts +++ b/tns-core-modules/ui/core/view.android.ts @@ -150,12 +150,16 @@ export class View extends viewCommon.View { } } - public _addViewCore(view: viewCommon.View, atIndex?: number) { + public _addViewCore(view: View, atIndex?: number) { if (this._context) { view._onAttached(this._context); } super._addViewCore(view, atIndex); + + if (this._context) { + view._syncNativeProperties(); + } } public _removeViewCore(view: viewCommon.View) { @@ -189,12 +193,14 @@ export class View extends viewCommon.View { if (this._childrenCount > 0) { // Notify each child for the _onAttached event var that = this; - var eachChild = function (child: View): boolean { + var eachChild = (child: View): boolean => { child._onAttached(context); if (!child._isAddedToNativeVisualTree) { // since we have lazy loading of the android widgets, we need to add the native instances at this point. child._isAddedToNativeVisualTree = that._addViewToNativeVisualTree(child); } + child._syncNativeProperties(); + return true; } this._eachChildView(eachChild); @@ -260,7 +266,7 @@ export class View extends viewCommon.View { padding = this.style.paddingTop; padding = this.style.paddingRight; padding = this.style.paddingBottom; - this._syncNativeProperties(); + trace.notifyEvent(this, "_onContextChanged"); } diff --git a/tns-core-modules/ui/layouts/flexbox-layout/flexbox-layout.android.ts b/tns-core-modules/ui/layouts/flexbox-layout/flexbox-layout.android.ts index bdf0572dd..90b98a276 100644 --- a/tns-core-modules/ui/layouts/flexbox-layout/flexbox-layout.android.ts +++ b/tns-core-modules/ui/layouts/flexbox-layout/flexbox-layout.android.ts @@ -51,6 +51,15 @@ const alignContentMap = { [AlignContent.STRETCH]: FlexboxLayoutWidget.ALIGN_CONTENT_STRETCH } +const alignSelfMap = { + [AlignSelf.AUTO]: FlexboxLayoutWidget.LayoutParams.ALIGN_SELF_AUTO, + [AlignSelf.FLEX_START]: FlexboxLayoutWidget.LayoutParams.ALIGN_SELF_FLEX_START, + [AlignSelf.FLEX_END]: FlexboxLayoutWidget.LayoutParams.ALIGN_SELF_FLEX_END, + [AlignSelf.CENTER]: FlexboxLayoutWidget.LayoutParams.ALIGN_SELF_CENTER, + [AlignSelf.BASELINE]: FlexboxLayoutWidget.LayoutParams.ALIGN_SELF_BASELINE, + [AlignSelf.STRETCH]: FlexboxLayoutWidget.LayoutParams.ALIGN_SELF_STRETCH +} + export class FlexboxLayout extends FlexboxLayoutBase { private _layout: FlexboxLayoutWidget; @@ -109,8 +118,7 @@ export class FlexboxLayout extends FlexboxLayoutBase { protected onAlignSelfPropertyChanged(view: View, oldValue: AlignSelf, newValue: AlignSelf): void { console.log("align-self changed: " + newValue + " " + view); - // TODO: Map the align self enum: - // this.setLayoutParamsProperty(view, lp => lp.alignSelf = newValue); + this.setLayoutParamsProperty(view, lp => lp.alignSelf = alignSelfMap[newValue]); } private setLayoutParamsProperty(view: View, setter: (lp: org.nativescript.widgets.FlexboxLayout.LayoutParams) => void) {