Code A 是 fun 的源代碼TabRow。
indicator呼叫時需要傳遞一個named引數 ,Android給出了一個默認實作 @Composable { tabPositions -> TabRowDefaults.Indicator( Modifier.tabIndicatorOffset(tabPositions[selectedTabIndex])) }
但是我不知道引數在哪里tabPositions實體化,你能告訴我嗎?
代碼 A
@Composable
fun TabRow(
selectedTabIndex: Int,
modifier: Modifier = Modifier,
backgroundColor: Color = MaterialTheme.colors.primarySurface,
contentColor: Color = contentColorFor(backgroundColor),
indicator: @Composable (tabPositions: List<TabPosition>) -> Unit = @Composable { tabPositions ->
TabRowDefaults.Indicator(
Modifier.tabIndicatorOffset(tabPositions[selectedTabIndex])
)
},
divider: @Composable () -> Unit = @Composable {
TabRowDefaults.Divider()
},
tabs: @Composable () -> Unit
) {
Surface(
modifier = modifier.selectableGroup(),
color = backgroundColor,
contentColor = contentColor
) {
...
}
}
uj5u.com熱心網友回復:
該indicator引數是一個lambda您提供背后TabRow代碼將呼叫它并傳遞tabPositions。只需搜索源代碼indicator(:
標簽行
你會發現它在這里被呼叫:
subcompose(TabSlots.Indicator) {
indicator(tabPositions)
}.fastForEach {
it.measure(Constraints.fixed(tabRowWidth, tabRowHeight)).placeRelative(0, 0)
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/376205.html
標籤:科特林 android-jetpack-compose
