Я тестировал Jetpack Compose с новым пустым JC-действием под названием HomeActivity. Я пытаюсь загрузить ресурс в моем коде. Это моя функция:
@Composable
fun home() {
MaterialTheme(
colors = colors,
typography = typography
) {
val menuIcon = +imageResource(R.drawable.ic_baseline_menu_24)
val bottomActions = listOf<Image>()
var (drawerState, onDrawerStateChangeListener) = +state { DrawerState.Closed }
BottomDrawerLayout(drawerState = drawerState, onStateChange = onDrawerStateChangeListener, drawerContent = {
Text(text = "Drawer")
}) {
Column(
crossAxisSize = LayoutSize.Expand
) {
BottomAppBar(
navigationIcon = {
drawerState = DrawerState.Opened
AppBarIcon(icon = menuIcon, onClick = {})
},
actionData = bottomActions,
action = {
AppBarIcon(icon = it, onClick = {})
}
)
}
}
}
}
Согласно веб-сайту JC, +imageResource(R.drawable.xyz)
должен загружать ресурс, так как функция andX.ui Image
object imageResource
возвращает Effect<Image>
, это не приводит к сбоюприложение, но я не знаю, как преобразовать его в объект Image, необходимый для AppBarIcon
Некоторые из выводов Logcat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.craftmyspace/com.craftmyspace.activities.HomeActivity}: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter bitmap
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
...os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter bitmap
at androidx.ui.graphics.AndroidImage.<init>(Unknown Source:2)
at androidx.ui.graphics.AndroidImageKt.imageFromResource(AndroidImage.kt:29)
at androidx.ui.res.ImageResourcesKt$imageResource$1$1.invoke(ImageResources.kt:45)
at androidx.ui.res.ImageResourcesKt$imageResource$1$1.invoke(Unknown Source:0)
at androidx.compose.ComposerKt.remember(Composer.kt:1867)
at androidx.compose.EffectsKt$memo$2.invoke(Effects.kt:287)
at androidx.compose.EffectsKt$memo$2.invoke(Unknown Source:2)
at androidx.compose.Effect.resolve(Effects.kt:106)
at androidx.compose.Effect.resolve$default(Effects.kt:843)
at androidx.compose.Effect.unaryPlus(Effects.kt:115)
at androidx.ui.res.ImageResourcesKt$imageResource$1.invoke(ImageResources.kt:45)
at androidx.ui.res.ImageResourcesKt$imageResource$1.invoke(Unknown Source:2)
at androidx.compose.Effect.resolve(Effects.kt:106)
at androidx.compose.Effect.resolve$default(Effects.kt:843)
at androidx.compose.EffectsKt.unaryPlus(Effects.kt:841)
at com.craftmyspace.activities.HomeActivityKt$home$1$1$1.invoke(HomeActivity.kt:66)
HomeActivity.kt: 66 это val menuIcon = +imageResource(R.drawable.ic_baseline_menu_24)