mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00

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
40 lines
1.6 KiB
TypeScript
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)));
|
|
|