@@ -349,55 +349,25 @@ private fun TabBaselineLayout(
349349 firstBaseline = firstBaseline!! ,
350350 lastBaseline = lastBaseline!!
351351 )
352- textPlaceable != null -> placeText(
353- density = this @Layout,
354- textPlaceable = textPlaceable,
355- tabHeight = tabHeight,
356- firstBaseline = firstBaseline!! ,
357- lastBaseline = lastBaseline!!
358- )
359- iconPlaceable != null -> placeIcon(iconPlaceable, tabHeight)
360- else -> {}
352+ textPlaceable != null -> placeTextOrIcon(textPlaceable, tabHeight)
353+ iconPlaceable != null -> placeTextOrIcon(iconPlaceable, tabHeight)
354+ else -> {
355+ }
361356 }
362357 }
363358 }
364359}
365360
366361/* *
367- * Places the provided [iconPlaceable] in the vertical center of the provided [tabHeight].
362+ * Places the provided [textOrIconPlaceable] in the vertical center of the provided
363+ * [tabHeight].
368364 */
369- private fun Placeable.PlacementScope.placeIcon (
370- iconPlaceable : Placeable ,
365+ private fun Placeable.PlacementScope.placeTextOrIcon (
366+ textOrIconPlaceable : Placeable ,
371367 tabHeight : Int
372368) {
373- val iconY = (tabHeight - iconPlaceable.height) / 2
374- iconPlaceable.placeRelative(0 , iconY)
375- }
376-
377- /* *
378- * Places the provided [textPlaceable] offset from the bottom of the tab using the correct
379- * baseline offset.
380- */
381- private fun Placeable.PlacementScope.placeText (
382- density : Density ,
383- textPlaceable : Placeable ,
384- tabHeight : Int ,
385- firstBaseline : Int ,
386- lastBaseline : Int
387- ) {
388- val baselineOffset = if (firstBaseline == lastBaseline) {
389- SingleLineTextBaseline
390- } else {
391- DoubleLineTextBaseline
392- }
393-
394- // Total offset between the last text baseline and the bottom of the Tab layout
395- val totalOffset = with (density) {
396- baselineOffset.roundToPx() + TabRowDefaults .IndicatorHeight .roundToPx()
397- }
398-
399- val textPlaceableY = tabHeight - lastBaseline - totalOffset
400- textPlaceable.placeRelative(0 , textPlaceableY)
369+ val contentY = (tabHeight - textOrIconPlaceable.height) / 2
370+ textOrIconPlaceable.placeRelative(0 , contentY)
401371}
402372
403373/* *
@@ -452,14 +422,10 @@ private const val TabFadeOutAnimationDuration = 100
452422// The horizontal padding on the left and right of text
453423private val HorizontalTextPadding = 16 .dp
454424
455- // Distance from the top of the indicator to the text baseline when there is one line of text
456- private val SingleLineTextBaseline = 18 .dp
457425// Distance from the top of the indicator to the text baseline when there is one line of text and an
458426// icon
459427private val SingleLineTextBaselineWithIcon = 14 .dp
460428// Distance from the top of the indicator to the last text baseline when there are two lines of text
461- private val DoubleLineTextBaseline = 10 .dp
462- // Distance from the top of the indicator to the last text baseline when there are two lines of text
463429// and an icon
464430private val DoubleLineTextBaselineWithIcon = 6 .dp
465431// Distance from the first text baseline to the bottom of the icon in a combined tab
0 commit comments