Skip to content

Commit

Permalink
fix: to fix fitcontent error as developer set fixed with and none hei…
Browse files Browse the repository at this point in the history
…ght (#247)
  • Loading branch information
biezhihua authored Oct 26, 2022
1 parent be05e97 commit 86bd780
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#template_text_fitcontent_lines_null_width_fixed_height_null_padding_top_padding_bottom {
width: 100%;
height: 50px;
background-color: primaryBackground;
justify-content: center;
align-items: center;
}
#text {
width: 100px;
fit-content:true;
padding-top:10px;
padding-bottom:10px;
font-size:13px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"data": {
"text": {
"value":"'HelloWorld'"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "template_text_fitcontent_lines_null_width_fixed_height_null_padding_top_padding_bottom",
"type": "gaia-template",
"layers": [
{
"id": "text",
"type": "text"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,28 @@ class GXComponentTextTest : GXBaseTest() {
Assert.assertEquals(24F.dpToPx(), rootView.child(0).height())
}

@Test
fun template_text_fitcontent_lines_null_width_fixed_height_null_padding_top_padding_bottom() {
val templateItem = GXTemplateEngine.GXTemplateItem(
GXMockUtils.context,
"text",
"template_text_fitcontent_lines_null_width_fixed_height_null_padding_top_padding_bottom"
)
val templateData = GXTemplateEngine.GXTemplateData(JSONObject())
val rootView = GXTemplateEngine.instance.createView(templateItem, size)
GXTemplateEngine.instance.bindData(rootView, templateData)

val textView = GXText(GXMockUtils.context)
textView.text = "HelloWorld"
val padding = 10F.dpToPx().roundToInt()
textView.setPadding(0, padding, 0, padding)
textView.setFontSize(13F.dpToPx())
textView.measure(0, 0)

Assert.assertEquals(textView.measuredWidth.toFloat(), rootView.child(0).width())
Assert.assertEquals(textView.measuredHeight.toFloat(), rootView.child(0).height())
}

@Test
fun template_text_fitcontent_lines_1_width_100_percent_height_100px() {
val templateItem = GXTemplateEngine.GXTemplateItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,23 @@ object GXFitContentUtils {
}
}


var textHeight = nodeHeight

// FIXED: template_text_fitcontent_lines_null_width_fixed_height_null_padding_top_padding_bottom
val textTopAndBottomPadding =
(finalFlexBox.padding?.top?.value ?: 0F) + (finalFlexBox.padding?.bottom?.value
?: 0F)
// 高度等于上下padding之和,也认为是0高度
if (textHeight == textTopAndBottomPadding) {
textHeight = 0F
}

if (textHeight == 0F) {
// 兼容处理, 如果未设置高度,那么使用文本默认的高度
textHeight = measuredHeight
}

// 修复template_text_fitcontent_lines_null_width_null_height_fixed_padding_left_padding_right
// FIXED: template_text_fitcontent_lines_null_width_null_height_fixed_padding_left_padding_right
val textLeftAndRightPadding =
(finalFlexBox.padding?.start?.value ?: 0F) + (finalFlexBox.padding?.end?.value
?: 0F)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class MainActivity : AppCompatActivity() {
// 9292
intent.putExtra(
"GAIA_STUDIO_URL",
"gaiax://gaiax/preview?url=ws://30.78.148.113:9001&id=test-template&type=auto"
"gaiax://gaiax/preview?url=ws://30.78.148.15:9001&id=test-template&type=auto"
)
launcher.launch(intent)
}
Expand Down

0 comments on commit 86bd780

Please sign in to comment.