Files
Panayot Cankov ae02bbdff3 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
2016-10-24 14:34:26 +03:00

40 lines
1.6 KiB
TypeScript

import {FlexboxLayout} from "ui/layouts/flexbox-layout";
function set(what: string) {
return function(args) {
args.object.page.getViewById("container")[what] = args.object.text;
}
}
export const flexDirection = set("flexDirection");
export const flexWrap = set("flexWrap");
export const justifyContent = set("justifyContent");
export const alignItems = set("alignItems");
export const alignContent = set("alignContent");
let lastSelection = null;
export function select(args) {
if (lastSelection) {
lastSelection.selected = "no";
lastSelection.notify({ eventName: "selectedChange", object: lastSelection });
}
lastSelection = args.object;
if (lastSelection) {
lastSelection.selected = "yes";
lastSelection.notify({ eventName: "selectedChange", object: lastSelection });
}
}
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 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)));