通过图标进行持续 GPU 渲染

问题描述 投票:0回答:1

我的 Icon() 组件有问题,它看起来像是在不断重绘。我不明白这种行为,我几乎尝试了所有方法,它看起来像一个错误。我在其他应用程序中没有看到这种行为。 当我注释掉这个组件时,它不会重绘。我正在使用下面的代码来记录重组,它看起来很正常。

Image of GPU rendering

class Ref(var value: Int)
inline fun LogCompositions(tag: String, msg: String) {
    if (BuildConfig.DEBUG) {
        val ref = remember { Ref(0) }
        SideEffect { ref.value++ }
        Log.d(tag, "Compositions: $msg ${ref.value}")
    }
}

结果如下:

D 组合:AppEntry() 0
D 组合:NavigationBarIcon(2131755275) 0
D 组合:NavigationBarIcon(2131755276) 0
D 组合:NavigationBarIcon(2131755279) 0
D 组合:NavigationBarIcon(2131755275) 1
D 组合:NavigationBarIcon(2131755276) 1
D 组合:NavigationBarIcon(2131755279) 1

这是其余的代码:

@Composable
fun AppEntry(
    windowSizeClass: WindowSizeClass,
    appState: AppState = rememberAppState(
        windowSizeClass = windowSizeClass,
    ),
) {
    val snackBarHostState = remember { SnackbarHostState() }

    LogCompositions(tag = "TEST", msg = "AppEntry()")
    Scaffold(
        containerColor = Color.Transparent,
        contentColor = MaterialTheme.colorScheme.onBackground,
        contentWindowInsets = WindowInsets(0, 0, 0, 0),
        bottomBar = {
            if (appState.shouldShowBottomBar)
                NavigationBottom(
                    destinations = appState.topLevelDestinations,
                    currentDestination = appState.currentDestination,
                    onNavigateToDestination = appState::navigateToTopLevelDestination,
                )
        },
        snackbarHost = { SnackbarHost(snackBarHostState) },
    ) { paddingValues ->
        AppNavHost(
            appState = appState,
            modifier = Modifier
                .padding(paddingValues)
                .fillMaxSize()
        )
    }
}
@Composable
fun NavigationBottom(
    modifier: Modifier = Modifier,
    currentDestination: NavDestination?,
    onNavigateToDestination: (route: String) -> Unit,
    destinations: List<Navigation>,
) {
    NavigationBar(modifier = modifier) {
        destinations.forEach { item ->
            val selected = currentDestination.isTopLevelDestinationInHierarchy(item.route)
            val icon = item.drawableRes
            NavigationBarItem(
                icon = {
                    LogCompositions(tag = "TEST", msg = "NavigationBarIcon(${item.name})")
                    // Problem
                    Icon(imageVector = icon, contentDescription = null)
                },
                label = {
                    Text(stringResource(item.name))
                },
                selected = selected,
                onClick = { onNavigateToDestination(item.route) },
                modifier = Modifier
            )
        }
    }
}
object AppIcons {
    val Cart = Icons.Rounded.ShoppingCart
    val List = Icons.Rounded.List
    val Info = Icons.Rounded.Info
}
sealed class Navigation(
    @StringRes val name: Int,
    val route: String,
    val drawableRes: ImageVector,
) {
    data object Cart : Navigation(R.string.navigation_cart, "cart", AppIcons.Cart)
    data object History : Navigation(R.string.navigation_history, "history", AppIcons.List)
    data object Statistics : Navigation(R.string.navigation_statistics, "statistics", AppIcons.Info)
}

我尝试更改依赖项,将调试更改为发布模式,使用 Android 中的 Now 代码,似乎没有任何效果。我没主意了。

android kotlin android-jetpack-compose android-navigation
1个回答
0
投票

这是

1.5.4
库的
androidx.compose.ui:ui-graphics
中的一个错误。使用
1.6.0-alpha08
版本问题就消失了。

© www.soinside.com 2019 - 2024. All rights reserved.