From ae02bbdff38e812ff60b20c7e78f86b9fa1e54d7 Mon Sep 17 00:00:00 2001 From: Panayot Cankov Date: Fri, 21 Oct 2016 16:11:38 +0300 Subject: [PATCH] Fix order set at runtime, polish unit test app example. Add alignSelf nad flexWrapBefore in the flexbox examples Some test fail with quite close calculations. Use eps. Fix flex grow making last items with flexGrow 0 to shrink due to rounding, happy tslint --- apps/app/ui-tests-app/flexbox/flexbox.css | 22 +-- apps/app/ui-tests-app/flexbox/flexbox.ts | 52 ++--- apps/app/ui-tests-app/flexbox/flexbox.xml | 186 +++++++++--------- tests/app/ui/layouts/flexbox-layout-tests.ts | 48 ++--- .../flexbox-layout/flexbox-layout-common.ts | 50 +++-- .../flexbox-layout/flexbox-layout.android.ts | 70 ++++--- .../flexbox-layout/flexbox-layout.ios.ts | 88 +++------ 7 files changed, 229 insertions(+), 287 deletions(-) diff --git a/apps/app/ui-tests-app/flexbox/flexbox.css b/apps/app/ui-tests-app/flexbox/flexbox.css index 0be39be0f..3ebf5a1b1 100644 --- a/apps/app/ui-tests-app/flexbox/flexbox.css +++ b/apps/app/ui-tests-app/flexbox/flexbox.css @@ -1,11 +1,3 @@ -@keyframes select { - 0%, 100% { - transform: scale(1, 1); - } - 50% { - transform: scale(1.4, 1.4); - } -} #container>Label { border-width: 1; border-color: black; @@ -13,16 +5,18 @@ } #container>Label[selected="yes"] { border-color: yellow; - /* animation-name: select; - animation-duration: 0.2s; - animation-fill-mode: forwards; - animation-iteration-count: 1;*/ } .control { font-size: 11; } +.control FlexboxLayout { + border-width: 0 0 1 1; + border-color: gray; +} .control Button { - padding: 2; - margin: 2; + border-width: 1 1 0 0; + border-color: gray; + padding: 0; + height: 0; } \ No newline at end of file diff --git a/apps/app/ui-tests-app/flexbox/flexbox.ts b/apps/app/ui-tests-app/flexbox/flexbox.ts index 592b855dd..4bbe06a94 100644 --- a/apps/app/ui-tests-app/flexbox/flexbox.ts +++ b/apps/app/ui-tests-app/flexbox/flexbox.ts @@ -1,5 +1,4 @@ -import {isAndroid} from "platform"; -import * as flexbox from "ui/layouts/flexbox-layout"; +import {FlexboxLayout} from "ui/layouts/flexbox-layout"; function set(what: string) { return function(args) { @@ -15,41 +14,26 @@ export const alignContent = set("alignContent"); let lastSelection = null; export function select(args) { - console.log("Select: " + args.object); + if (lastSelection) { + lastSelection.selected = "no"; + lastSelection.notify({ eventName: "selectedChange", object: lastSelection }); + } lastSelection = args.object; - - if (isAndroid) { - let layoutParams = lastSelection.android.getLayoutParams(); - console.log("Selection: " + lastSelection + ": " + layoutParams); - console.log(" - margin: " + layoutParams.topMargin + " " + layoutParams.rightMargin + " " + layoutParams.bottomMargin + " " + layoutParams.leftMargin); + if (lastSelection) { + lastSelection.selected = "yes"; + lastSelection.notify({ eventName: "selectedChange", object: lastSelection }); } } -export function order({object}) { - if (!lastSelection) { - return; - } - let value = object.text; - console.log("Set order " + value + " " + lastSelection); - flexbox.FlexboxLayout.setOrder(lastSelection, object.text); -} +let whenSelected = handler => args => lastSelection && handler(args); +let setProperty = setter => value => setter(lastSelection, value); +let intHandler = handler => ({object}) => handler(parseInt(object.text)); +let stringHandler = handler => ({object}) => handler(object.text); +let booleanHandler = handler => ({object}) => handler(object.text === "true"); -export function flexGrow({object}) { - if (!lastSelection) { - return; - } - let value = object.text; - console.log("Set flexGrow " + value + " " + lastSelection); - flexbox.FlexboxLayout.setFlexGrow(lastSelection, object.text); -} +export const order = whenSelected(intHandler(setProperty(FlexboxLayout.setOrder))); +export const flexGrow = whenSelected(intHandler(setProperty(FlexboxLayout.setFlexGrow))); +export const flexShrink = whenSelected(intHandler(setProperty(FlexboxLayout.setFlexShrink))); +export const alignSelf = whenSelected(stringHandler(setProperty(FlexboxLayout.setAlignSelf))); +export const flexWrapBefore = whenSelected(booleanHandler(setProperty(FlexboxLayout.setFlexWrapBefore))); -export function flexShrink({object}) { - if (!lastSelection) { - return; - } - let value = object.text; - console.log("Set flexShrink " + value + " " + lastSelection); - flexbox.FlexboxLayout.setFlexShrink(lastSelection, object.text); -} - -// TODO: Align self \ No newline at end of file diff --git a/apps/app/ui-tests-app/flexbox/flexbox.xml b/apps/app/ui-tests-app/flexbox/flexbox.xml index 407a04343..c795532f1 100644 --- a/apps/app/ui-tests-app/flexbox/flexbox.xml +++ b/apps/app/ui-tests-app/flexbox/flexbox.xml @@ -1,119 +1,109 @@ - - + +