mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
fix-next(flexbox): flex end for justify content (#6337)
* fix-next(flexbox): flex end for justify content * refactor: add lessOrCloseEnough assert method
This commit is contained in:
@ -33,6 +33,12 @@ export function closeEnough(a: number, b: number, message?: string) {
|
|||||||
message ? TKUnit.assertTrue(Math.abs(a - b) <= EPS, message) : TKUnit.assertTrue(Math.abs(a - b) <= EPS);
|
message ? TKUnit.assertTrue(Math.abs(a - b) <= EPS, message) : TKUnit.assertTrue(Math.abs(a - b) <= EPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function lessOrCloseEnough(a: number, b: number, message?: string) {
|
||||||
|
const less = a < b;
|
||||||
|
const close = Math.abs(a - b) <= EPS;
|
||||||
|
message ? TKUnit.assertTrue(less || close, message) : TKUnit.assertTrue(less || close);
|
||||||
|
}
|
||||||
|
|
||||||
export function notEqual<T>(a: T, b: T, message?: string) {
|
export function notEqual<T>(a: T, b: T, message?: string) {
|
||||||
message ? TKUnit.assertNotEqual(a, b, message) : TKUnit.assertNotEqual(a, b);
|
message ? TKUnit.assertNotEqual(a, b, message) : TKUnit.assertNotEqual(a, b);
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,15 @@
|
|||||||
import { Page } from "tns-core-modules/ui/page";
|
import { GridLayout } from "tns-core-modules/ui/layouts/grid-layout";
|
||||||
import { GridLayout, ItemSpec } from "tns-core-modules/ui/layouts/grid-layout";
|
|
||||||
import { Button } from "tns-core-modules/ui/button";
|
|
||||||
import * as TKUnit from "../../TKUnit";
|
import * as TKUnit from "../../TKUnit";
|
||||||
import * as view from "tns-core-modules/ui/core/view";
|
import * as view from "tns-core-modules/ui/core/view";
|
||||||
import { unsetValue } from "tns-core-modules/ui/core/view";
|
|
||||||
import * as builder from "tns-core-modules/ui/builder";
|
|
||||||
import * as testModule from "../../ui-test";
|
import * as testModule from "../../ui-test";
|
||||||
import * as layoutHelper from "./layout-helper";
|
|
||||||
import * as platform from "tns-core-modules/platform";
|
import * as platform from "tns-core-modules/platform";
|
||||||
import { ios as iosUtils } from "tns-core-modules/utils/utils";
|
import { ios as iosUtils } from "tns-core-modules/utils/utils";
|
||||||
import * as commonTests from "./common-layout-tests";
|
|
||||||
import * as helper from "../helper";
|
import * as helper from "../helper";
|
||||||
import { parse } from "tns-core-modules/ui/builder";
|
import { parse } from "tns-core-modules/ui/builder";
|
||||||
import {
|
import {
|
||||||
dipToDp, left, top, right, bottom, height, width,
|
dipToDp, left, top, right, bottom, height, width,
|
||||||
paddingLeft, paddingTop, paddingRight, paddingBottom,
|
equal, closeEnough, lessOrCloseEnough, check,
|
||||||
equal, closeEnough, notEqual, check,
|
|
||||||
heightEqual, widthEqual,
|
|
||||||
isLeftAlignedWith, isRightAlignedWith, isTopAlignedWith, isBottomAlignedWith,
|
isLeftAlignedWith, isRightAlignedWith, isTopAlignedWith, isBottomAlignedWith,
|
||||||
isLeftOf, isRightOf, isBelow, isAbove,
|
|
||||||
isLeftWith, isAboveWith, isRightWith, isBelowWith
|
isLeftWith, isAboveWith, isRightWith, isBelowWith
|
||||||
} from "./layout-tests-helper";
|
} from "./layout-tests-helper";
|
||||||
|
|
||||||
@ -960,12 +951,12 @@ export class SafeAreaTests extends testModule.UITest<any> {
|
|||||||
isAboveWith(cells[2][2], grid, insets.bottom);
|
isAboveWith(cells[2][2], grid, insets.bottom);
|
||||||
|
|
||||||
closeEnough(height(cells[0][1]), height(cells[1][1]), `cell height should be equal - cell01<${height(cells[0][1])}> - cell11<${height(cells[1][1])}>`);
|
closeEnough(height(cells[0][1]), height(cells[1][1]), `cell height should be equal - cell01<${height(cells[0][1])}> - cell11<${height(cells[1][1])}>`);
|
||||||
equal(height(cells[1][1]), height(cells[2][1]), `cell height should be equal - cell11<${height(cells[1][1])}> - cell21<${height(cells[2][1])}>`);
|
closeEnough(height(cells[1][1]), height(cells[2][1]), `cell height should be equal - cell11<${height(cells[1][1])}> - cell21<${height(cells[2][1])}>`);
|
||||||
const sumOfLabelHeightAndInsets = insets.top + height(cells[0][1]) + height(cells[1][1]) + height(cells[2][1]) + insets.bottom;
|
const sumOfLabelHeightAndInsets = insets.top + height(cells[0][1]) + height(cells[1][1]) + height(cells[2][1]) + insets.bottom;
|
||||||
closeEnough(height(grid), sumOfLabelHeightAndInsets, `grid height<${height(grid)}> sum of labels height and insets<${sumOfLabelHeightAndInsets}>`);
|
closeEnough(height(grid), sumOfLabelHeightAndInsets, `grid height<${height(grid)}> sum of labels height and insets<${sumOfLabelHeightAndInsets}>`);
|
||||||
|
|
||||||
equal(width(cells[1][0]), width(cells[1][1]), `cell width should be equal - cell10<${width(cells[1][0])}> - cell11<${width(cells[1][1])}>`);
|
closeEnough(width(cells[1][0]), width(cells[1][1]), `cell width should be equal - cell10<${width(cells[1][0])}> - cell11<${width(cells[1][1])}>`);
|
||||||
equal(width(cells[1][1]), width(cells[1][2]), `cell width should be equal - cell11<${width(cells[1][1])}> - cell12<${width(cells[1][2])}>`);
|
closeEnough(width(cells[1][1]), width(cells[1][2]), `cell width should be equal - cell11<${width(cells[1][1])}> - cell12<${width(cells[1][2])}>`);
|
||||||
const sumOfLabelWidthsAndInsets = insets.left + width(cells[1][0]) + width(cells[1][1]) + width(cells[1][2]) + insets.right;
|
const sumOfLabelWidthsAndInsets = insets.left + width(cells[1][0]) + width(cells[1][1]) + width(cells[1][2]) + insets.right;
|
||||||
equal(width(grid), sumOfLabelWidthsAndInsets, `grid width<${width(grid)}> sum of nested grids width and insets<${sumOfLabelWidthsAndInsets}>`);
|
equal(width(grid), sumOfLabelWidthsAndInsets, `grid width<${width(grid)}> sum of nested grids width and insets<${sumOfLabelWidthsAndInsets}>`);
|
||||||
},
|
},
|
||||||
@ -1021,7 +1012,7 @@ export class SafeAreaTests extends testModule.UITest<any> {
|
|||||||
isBottomAlignedWith(grid, cells[2][2]);
|
isBottomAlignedWith(grid, cells[2][2]);
|
||||||
|
|
||||||
check(height(cells[0][1]) >= height(cells[1][1]), `cell01 height<${height(cells[0][1])}> not greater or equal cell11 height<${height(cells[1][1])}>`);
|
check(height(cells[0][1]) >= height(cells[1][1]), `cell01 height<${height(cells[0][1])}> not greater or equal cell11 height<${height(cells[1][1])}>`);
|
||||||
check(height(cells[1][1]) <= height(cells[2][1]), `cell11 height<${height(cells[1][1])}> not less or equal cell21 height<${height(cells[2][1])}>`);
|
lessOrCloseEnough(height(cells[1][1]), height(cells[2][1]), `cell11 height<${height(cells[1][1])}> not less or equal cell21 height<${height(cells[2][1])}>`);
|
||||||
const sumOfNestedGridHeights = height(cells[0][1]) + height(cells[1][1]) + height(cells[2][1]);
|
const sumOfNestedGridHeights = height(cells[0][1]) + height(cells[1][1]) + height(cells[2][1]);
|
||||||
equal(height(grid), sumOfNestedGridHeights, `grid height<${height(grid)}> sum of nested grids height <${sumOfNestedGridHeights}>`);
|
equal(height(grid), sumOfNestedGridHeights, `grid height<${height(grid)}> sum of nested grids height <${sumOfNestedGridHeights}>`);
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import { ViewModel } from "./list-view-view-model";
|
|||||||
import { UITest } from "../../ui-test";
|
import { UITest } from "../../ui-test";
|
||||||
import {
|
import {
|
||||||
dipToDp, left, top, right, bottom, height, width,
|
dipToDp, left, top, right, bottom, height, width,
|
||||||
equal, check,
|
equal, check, lessOrCloseEnough,
|
||||||
isLeftAlignedWith, isRightAlignedWith, isTopAlignedWith
|
isLeftAlignedWith, isRightAlignedWith, isTopAlignedWith
|
||||||
} from "../layouts/layout-tests-helper";
|
} from "../layouts/layout-tests-helper";
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ export class ListViewSafeAreaTest extends UITest<ListView> {
|
|||||||
isRightAlignedWith(root, cells[2][2]);
|
isRightAlignedWith(root, cells[2][2]);
|
||||||
|
|
||||||
check(height(cells[0][1]) >= height(cells[1][1]), `cell01 height<${height(cells[0][1])}> not greater or equal cell11 height<${height(cells[1][1])}>`);
|
check(height(cells[0][1]) >= height(cells[1][1]), `cell01 height<${height(cells[0][1])}> not greater or equal cell11 height<${height(cells[1][1])}>`);
|
||||||
check(height(cells[1][1]) <= height(cells[2][1]), `cell11 height<${height(cells[1][1])}> not less or equal cell21 height<${height(cells[2][1])}>`);
|
lessOrCloseEnough(height(cells[1][1]), height(cells[2][1]), `cell11 height<${height(cells[1][1])}> not less or equal cell21 height<${height(cells[2][1])}>`);
|
||||||
const sumOfNestedListViewHeights = height(cells[0][1]) + height(cells[1][1]) + height(cells[2][1]);
|
const sumOfNestedListViewHeights = height(cells[0][1]) + height(cells[1][1]) + height(cells[2][1]);
|
||||||
equal(height(root), sumOfNestedListViewHeights, `grid height<${height(root)}> sum of nested list views height <${sumOfNestedListViewHeights}>`);
|
equal(height(root), sumOfNestedListViewHeights, `grid height<${height(root)}> sum of nested list views height <${sumOfNestedListViewHeights}>`);
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import * as helper from "../helper";
|
|||||||
import { parse } from "tns-core-modules/ui/builder";
|
import { parse } from "tns-core-modules/ui/builder";
|
||||||
import {
|
import {
|
||||||
dipToDp, left, top, right, bottom, height, width,
|
dipToDp, left, top, right, bottom, height, width,
|
||||||
equal, check,
|
equal, check, lessOrCloseEnough,
|
||||||
isLeftAlignedWith, isRightAlignedWith, isTopAlignedWith, isBottomAlignedWith,
|
isLeftAlignedWith, isRightAlignedWith, isTopAlignedWith, isBottomAlignedWith,
|
||||||
isLeftWith, isRightWith, isBelowWith
|
isLeftWith, isRightWith, isBelowWith
|
||||||
} from "../layouts/layout-tests-helper";
|
} from "../layouts/layout-tests-helper";
|
||||||
@ -426,7 +426,7 @@ class ScrollLayoutSafeAreaTest extends UITest<ScrollView> {
|
|||||||
isBottomAlignedWith(grid, cells[2][2]);
|
isBottomAlignedWith(grid, cells[2][2]);
|
||||||
|
|
||||||
check(height(cells[0][1]) >= height(cells[1][1]), `cell01 height<${height(cells[0][1])}> not greater or equal cell11 height<${height(cells[1][1])}>`);
|
check(height(cells[0][1]) >= height(cells[1][1]), `cell01 height<${height(cells[0][1])}> not greater or equal cell11 height<${height(cells[1][1])}>`);
|
||||||
check(height(cells[1][1]) <= height(cells[2][1]), `cell11 height<${height(cells[1][1])}> not less or equal cell21 height<${height(cells[2][1])}>`);
|
lessOrCloseEnough(height(cells[1][1]), height(cells[2][1]), `cell11 height<${height(cells[1][1])}> not less or equal cell21 height<${height(cells[2][1])}>`);
|
||||||
const sumOfNestedScrollViewHeights = height(cells[0][1]) + height(cells[1][1]) + height(cells[2][1]);
|
const sumOfNestedScrollViewHeights = height(cells[0][1]) + height(cells[1][1]) + height(cells[2][1]);
|
||||||
equal(height(grid), sumOfNestedScrollViewHeights, `grid height<${height(grid)}> sum of nested scroll views height <${sumOfNestedScrollViewHeights}>`);
|
equal(height(grid), sumOfNestedScrollViewHeights, `grid height<${height(grid)}> sum of nested scroll views height <${sumOfNestedScrollViewHeights}>`);
|
||||||
|
|
||||||
|
@ -1003,8 +1003,8 @@ export class FlexboxLayout extends FlexboxLayoutBase {
|
|||||||
childRight = width - paddingRight;
|
childRight = width - paddingRight;
|
||||||
break;
|
break;
|
||||||
case JustifyContent.FLEX_END:
|
case JustifyContent.FLEX_END:
|
||||||
childLeft = width - flexLine._mainSize - paddingRight;
|
childLeft = width - flexLine._mainSize + paddingRight;
|
||||||
childRight = flexLine._mainSize + paddingLeft;
|
childRight = flexLine._mainSize - paddingLeft;
|
||||||
break;
|
break;
|
||||||
case JustifyContent.CENTER:
|
case JustifyContent.CENTER:
|
||||||
childLeft = paddingLeft + (width - insets.left - insets.right - flexLine._mainSize) / 2.0;
|
childLeft = paddingLeft + (width - insets.left - insets.right - flexLine._mainSize) / 2.0;
|
||||||
@ -1164,8 +1164,8 @@ export class FlexboxLayout extends FlexboxLayoutBase {
|
|||||||
childBottom = height - paddingBottom;
|
childBottom = height - paddingBottom;
|
||||||
break;
|
break;
|
||||||
case JustifyContent.FLEX_END:
|
case JustifyContent.FLEX_END:
|
||||||
childTop = height - flexLine._mainSize - paddingBottom;
|
childTop = height - flexLine._mainSize + paddingBottom;
|
||||||
childBottom = flexLine._mainSize + paddingTop;
|
childBottom = flexLine._mainSize - paddingTop;
|
||||||
break;
|
break;
|
||||||
case JustifyContent.CENTER:
|
case JustifyContent.CENTER:
|
||||||
childTop = paddingTop + (height - insets.top - insets.bottom - flexLine._mainSize) / 2.0;
|
childTop = paddingTop + (height - insets.top - insets.bottom - flexLine._mainSize) / 2.0;
|
||||||
|
Reference in New Issue
Block a user