mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
Fixed grid block calculation of intrinsicContentHeight for cases with height constraints
commit_hash:9e1b5c37a7ed41dc657627e20dbc3d9f1d4382b4
This commit is contained in:
@@ -176,7 +176,7 @@ public final class GridBlock: BlockWithTraits, BlockWithLayout {
|
||||
|
||||
var result = makeLayout(constrainedTo: CGSize(width: width, height: .infinity)).size.height
|
||||
|
||||
if case let .intrinsic(_, minSize, maxSize) = widthTrait {
|
||||
if case let .intrinsic(_, minSize, maxSize) = heightTrait {
|
||||
result = clamp(result, min: minSize, max: maxSize)
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,89 @@ final class GridBlockTests: XCTestCase {
|
||||
XCTAssertEqual(block.intrinsicContentHeight(forWidth: 100), 0)
|
||||
}
|
||||
|
||||
func test_IntrinsicTraitsWithDefaultConstraints() {
|
||||
let contentSize = CGSize(width: 50, height: 75)
|
||||
|
||||
let grid = makeGrid(
|
||||
contentSize: contentSize,
|
||||
widthTrait: .intrinsic(constrained: false, minSize: 0, maxSize: .infinity),
|
||||
heightTrait: .intrinsic(constrained: false, minSize: 0, maxSize: .infinity)
|
||||
)
|
||||
|
||||
assertIntrinsicContentSize(ofBlock: grid, equals: contentSize)
|
||||
}
|
||||
|
||||
func test_IntrinsicTraitsWithMaxConstraints() {
|
||||
let contentSize = CGSize(width: 50, height: 75)
|
||||
let maxSize = CGSize(width: contentSize.width / 2, height: contentSize.height / 2)
|
||||
|
||||
let grid = makeGrid(
|
||||
contentSize: contentSize,
|
||||
widthTrait: .intrinsic(constrained: false, minSize: 0, maxSize: maxSize.width),
|
||||
heightTrait: .intrinsic(constrained: false, minSize: 0, maxSize: maxSize.height)
|
||||
)
|
||||
|
||||
assertIntrinsicContentSize(ofBlock: grid, equals: maxSize)
|
||||
}
|
||||
|
||||
func test_IntrinsicTraitsWithMinConstraints() {
|
||||
let contentSize = CGSize(width: 50, height: 75)
|
||||
let minSize = CGSize(width: contentSize.width * 2, height: contentSize.height * 2)
|
||||
|
||||
let grid = makeGrid(
|
||||
contentSize: contentSize,
|
||||
widthTrait: .intrinsic(
|
||||
constrained: false,
|
||||
minSize: minSize.width,
|
||||
maxSize: .infinity
|
||||
),
|
||||
heightTrait: .intrinsic(
|
||||
constrained: false,
|
||||
minSize: minSize.height,
|
||||
maxSize: .infinity
|
||||
)
|
||||
)
|
||||
|
||||
assertIntrinsicContentSize(ofBlock: grid, equals: minSize)
|
||||
}
|
||||
|
||||
private func makeGrid(
|
||||
contentSize: CGSize,
|
||||
widthTrait: LayoutTrait,
|
||||
heightTrait: LayoutTrait
|
||||
) -> GridBlock {
|
||||
let itemBlock = EmptyBlock(
|
||||
widthTrait: .fixed(contentSize.width),
|
||||
heightTrait: .fixed(contentSize.height)
|
||||
)
|
||||
|
||||
return try! GridBlock(
|
||||
widthTrait: widthTrait,
|
||||
heightTrait: heightTrait,
|
||||
contentAlignment: .default,
|
||||
items: [
|
||||
.init(
|
||||
weight: GridBlock.Item.Weight(),
|
||||
contents: itemBlock
|
||||
),
|
||||
],
|
||||
columnCount: 1
|
||||
)
|
||||
}
|
||||
|
||||
private func assertIntrinsicContentSize(
|
||||
ofBlock block: GridBlock,
|
||||
equals: CGSize
|
||||
) {
|
||||
let width = block.intrinsicContentWidth
|
||||
let height = block.intrinsicContentHeight(forWidth: width)
|
||||
|
||||
XCTAssertEqual(
|
||||
CGSize(width: width, height: height),
|
||||
equals
|
||||
)
|
||||
}
|
||||
|
||||
func test_KeepWeightWhenUpdateState() {
|
||||
struct TestState: ElementState {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user