mirror of
https://github.com/divkit/divkit.git
synced 2026-05-07 20:02:32 +00:00
Support min/max sizes for match_parent
commit_hash:221865c0718c81e82093c88f644b4a42cde459e0
This commit is contained in:
@@ -20080,6 +20080,7 @@
|
||||
"schema/div-shape-drawable.json":"divkit/public/schema/div-shape-drawable.json",
|
||||
"schema/div-shape.json":"divkit/public/schema/div-shape.json",
|
||||
"schema/div-sight-action.json":"divkit/public/schema/div-sight-action.json",
|
||||
"schema/div-size-unit-value.json":"divkit/public/schema/div-size-unit-value.json",
|
||||
"schema/div-size-unit.json":"divkit/public/schema/div-size-unit.json",
|
||||
"schema/div-size.json":"divkit/public/schema/div-size.json",
|
||||
"schema/div-slide-transition.json":"divkit/public/schema/div-slide-transition.json",
|
||||
|
||||
+6
-6
@@ -86,11 +86,11 @@ import com.yandex.div2.DivShapeDrawable
|
||||
import com.yandex.div2.DivSightAction
|
||||
import com.yandex.div2.DivSize
|
||||
import com.yandex.div2.DivSizeUnit
|
||||
import com.yandex.div2.DivSizeUnitValue
|
||||
import com.yandex.div2.DivStroke
|
||||
import com.yandex.div2.DivTextAlignmentVertical
|
||||
import com.yandex.div2.DivTransform
|
||||
import com.yandex.div2.DivVisibilityAction
|
||||
import com.yandex.div2.DivWrapContentSize
|
||||
import kotlin.math.max
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@@ -193,7 +193,7 @@ internal fun DivFixedSize.toPx(metrics: DisplayMetrics, resolver: ExpressionReso
|
||||
}
|
||||
}
|
||||
|
||||
internal fun DivWrapContentSize.ConstraintSize.toPx(metrics: DisplayMetrics, resolver: ExpressionResolver): Int {
|
||||
internal fun DivSizeUnitValue.toPx(metrics: DisplayMetrics, resolver: ExpressionResolver): Int {
|
||||
return when (unit.evaluate(resolver)) {
|
||||
DivSizeUnit.DP -> value.evaluate(resolver).dpToPx(metrics)
|
||||
DivSizeUnit.SP -> value.evaluate(resolver).spToPx(metrics)
|
||||
@@ -238,7 +238,7 @@ internal fun View.applyHeight(div: DivBase, resolver: ExpressionResolver) {
|
||||
applyTransform(div.transform, resolver)
|
||||
}
|
||||
|
||||
internal fun View.applyMinHeight(minHeight: DivWrapContentSize.ConstraintSize?, resolver: ExpressionResolver) {
|
||||
internal fun View.applyMinHeight(minHeight: DivSizeUnitValue?, resolver: ExpressionResolver) {
|
||||
val heightValue = minHeight?.toPx(resources.displayMetrics, resolver) ?: 0
|
||||
if (minimumHeight != heightValue) {
|
||||
minimumHeight = heightValue
|
||||
@@ -254,7 +254,7 @@ internal fun View.applyVerticalWeightValue(value: Float) {
|
||||
}
|
||||
}
|
||||
|
||||
internal fun View.applyMaxHeight(maxHeight: DivWrapContentSize.ConstraintSize?, resolver: ExpressionResolver) {
|
||||
internal fun View.applyMaxHeight(maxHeight: DivSizeUnitValue?, resolver: ExpressionResolver) {
|
||||
val params = layoutParams as? DivLayoutParams ?: return
|
||||
val heightValue = maxHeight?.toPx(resources.displayMetrics, resolver) ?: Int.MAX_VALUE
|
||||
if (params.maxHeight != heightValue) {
|
||||
@@ -272,7 +272,7 @@ internal fun View.applyWidth(div: DivBase, resolver: ExpressionResolver) {
|
||||
applyTransform(div.transform, resolver)
|
||||
}
|
||||
|
||||
internal fun View.applyMinWidth(minWidth: DivWrapContentSize.ConstraintSize?, resolver: ExpressionResolver) {
|
||||
internal fun View.applyMinWidth(minWidth: DivSizeUnitValue?, resolver: ExpressionResolver) {
|
||||
val widthValue = minWidth?.toPx(resources.displayMetrics, resolver) ?: 0
|
||||
if (minimumWidth != widthValue) {
|
||||
minimumWidth = widthValue
|
||||
@@ -293,7 +293,7 @@ internal fun DivSize.getWeight(resolver: ExpressionResolver) = when (this) {
|
||||
else -> DivLayoutParams.DEFAULT_WEIGHT
|
||||
}
|
||||
|
||||
internal fun View.applyMaxWidth(maxWidth: DivWrapContentSize.ConstraintSize?, resolver: ExpressionResolver) {
|
||||
internal fun View.applyMaxWidth(maxWidth: DivSizeUnitValue?, resolver: ExpressionResolver) {
|
||||
val params = layoutParams as? DivLayoutParams ?: return
|
||||
val widthValue = maxWidth?.toPx(resources.displayMetrics, resolver) ?: Int.MAX_VALUE
|
||||
if (params.maxWidth != widthValue) {
|
||||
|
||||
@@ -11,6 +11,16 @@
|
||||
"enum": [
|
||||
"match_parent"
|
||||
]
|
||||
},
|
||||
"min_size": {
|
||||
"$ref": "div-size-unit-value.json",
|
||||
"$description": "translations.json#/div_size_min",
|
||||
"platforms": []
|
||||
},
|
||||
"max_size": {
|
||||
"$ref": "div-size-unit-value.json",
|
||||
"$description": "translations.json#/div_size_max",
|
||||
"platforms": []
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"value": {
|
||||
"$ref": "common.json#/non_negative_integer",
|
||||
"$description": "translations.json#/div_fixed_size_value"
|
||||
},
|
||||
"unit": {
|
||||
"$ref": "div-size-unit.json",
|
||||
"$description": "translations.json#/div_size_unit",
|
||||
"default_value": "dp"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"value"
|
||||
]
|
||||
}
|
||||
@@ -1,24 +1,6 @@
|
||||
{
|
||||
"type": "object",
|
||||
"$description": "translations.json#/div_wrap_content_size",
|
||||
"definitions": {
|
||||
"constraint_size": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"value": {
|
||||
"$ref": "common.json#/non_negative_integer"
|
||||
},
|
||||
"unit": {
|
||||
"$ref": "div-size-unit.json",
|
||||
"$description": "translations.json#/div_size_unit",
|
||||
"default_value": "dp"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"value"
|
||||
]
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
@@ -31,11 +13,11 @@
|
||||
"$description": "translations.json#/div_wrap_content_size_constrained"
|
||||
},
|
||||
"min_size": {
|
||||
"$ref": "#/definitions/constraint_size",
|
||||
"$ref": "div-size-unit-value.json",
|
||||
"$description": "translations.json#/div_size_min"
|
||||
},
|
||||
"max_size": {
|
||||
"$ref": "#/definitions/constraint_size",
|
||||
"$ref": "div-size-unit-value.json",
|
||||
"$description": "translations.json#/div_size_max"
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user