mirror of
https://github.com/jlengrand/compose-multiplatform.git
synced 2026-03-10 15:48:51 +00:00
WidgetsGallery. Refactor painterResource
This commit is contained in:
@@ -4,21 +4,12 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.ImageBitmap
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.imageResource
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.vectorResource
|
||||
import org.jetbrains.compose.demo.widgets.platform.R
|
||||
|
||||
@Composable
|
||||
actual fun imageResource(res: String): Painter {
|
||||
actual fun painterResource(res: String): Painter {
|
||||
val id = drawableId(res)
|
||||
return painterResource(id)
|
||||
}
|
||||
|
||||
@Composable
|
||||
actual fun vectorResource(res: String): Painter {
|
||||
val id = drawableId(res)
|
||||
return painterResource(id)
|
||||
return androidx.compose.ui.res.painterResource(id)
|
||||
}
|
||||
|
||||
// TODO: improve resource loading
|
||||
|
||||
@@ -4,8 +4,4 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
|
||||
@Composable
|
||||
expect fun imageResource(res: String): Painter
|
||||
|
||||
@Composable
|
||||
expect fun vectorResource(res: String): Painter
|
||||
|
||||
expect fun painterResource(res: String): Painter
|
||||
|
||||
@@ -16,8 +16,7 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.unit.dp
|
||||
import org.jetbrains.compose.demo.widgets.platform.Res
|
||||
import org.jetbrains.compose.demo.widgets.platform.imageResource
|
||||
import org.jetbrains.compose.demo.widgets.platform.vectorResource
|
||||
import org.jetbrains.compose.demo.widgets.platform.painterResource
|
||||
import org.jetbrains.compose.demo.widgets.theme.twitterColor
|
||||
import org.jetbrains.compose.demo.widgets.ui.utils.SubtitleText
|
||||
import org.jetbrains.compose.demo.widgets.ui.utils.TitleText
|
||||
@@ -52,12 +51,12 @@ private fun TopAppBarsDemo() {
|
||||
elevation = 8.dp,
|
||||
navigationIcon = {
|
||||
IconButton(onClick = {}) {
|
||||
Icon(vectorResource(Res.drawable.ic_instagram), contentDescription = "Instagram")
|
||||
Icon(painterResource(Res.drawable.ic_instagram), contentDescription = "Instagram")
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
IconButton(onClick = {}) {
|
||||
Icon(vectorResource(Res.drawable.ic_send), contentDescription = "Send")
|
||||
Icon(painterResource(Res.drawable.ic_send), contentDescription = "Send")
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -67,7 +66,7 @@ private fun TopAppBarsDemo() {
|
||||
TopAppBar(
|
||||
title = {
|
||||
Icon(
|
||||
vectorResource(Res.drawable.ic_twitter),
|
||||
painterResource(Res.drawable.ic_twitter),
|
||||
contentDescription = "Twitter",
|
||||
tint = twitterColor,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
@@ -78,7 +77,7 @@ private fun TopAppBarsDemo() {
|
||||
elevation = 8.dp,
|
||||
navigationIcon = {
|
||||
Image(
|
||||
imageResource(Res.drawable.p6),
|
||||
painterResource(Res.drawable.p6),
|
||||
contentDescription = "",
|
||||
modifier = Modifier.padding(vertical = 4.dp, horizontal = 8.dp)
|
||||
.requiredSize(32.dp).clip(CircleShape)
|
||||
|
||||
@@ -16,7 +16,7 @@ import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import org.jetbrains.compose.demo.widgets.platform.Res
|
||||
import org.jetbrains.compose.demo.widgets.platform.imageResource
|
||||
import org.jetbrains.compose.demo.widgets.platform.painterResource
|
||||
import org.jetbrains.compose.demo.widgets.ui.utils.SubtitleText
|
||||
|
||||
@Composable
|
||||
@@ -85,7 +85,7 @@ private fun CustomImageChip(
|
||||
) {
|
||||
Row(modifier = Modifier) {
|
||||
Image(
|
||||
imageResource(imageId),
|
||||
painterResource(imageId),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.padding(8.dp).requiredSize(20.dp).clip(CircleShape)
|
||||
)
|
||||
|
||||
@@ -12,7 +12,7 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import org.jetbrains.compose.demo.widgets.data.DemoDataProvider
|
||||
import org.jetbrains.compose.demo.widgets.platform.Res
|
||||
import org.jetbrains.compose.demo.widgets.platform.imageResource
|
||||
import org.jetbrains.compose.demo.widgets.platform.painterResource
|
||||
import org.jetbrains.compose.demo.widgets.theme.typography
|
||||
|
||||
@OptIn(ExperimentalMaterialApi::class)
|
||||
@@ -53,7 +53,7 @@ fun UICards() {
|
||||
) {
|
||||
Row {
|
||||
Image(
|
||||
imageResource(Res.drawable.p3),
|
||||
painterResource(Res.drawable.p3),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.requiredSize(60.dp)
|
||||
)
|
||||
@@ -77,7 +77,7 @@ fun UICards() {
|
||||
Divider(modifier = Modifier.padding(4.dp))
|
||||
ListItem(text = { Text(item.title) }, secondaryText = { Text(item.subtitle) }, icon = {
|
||||
Image(
|
||||
imageResource(Res.drawable.p3),
|
||||
painterResource(Res.drawable.p3),
|
||||
contentDescription = null
|
||||
)
|
||||
})
|
||||
@@ -86,7 +86,7 @@ fun UICards() {
|
||||
ListItem(
|
||||
text = { Text(item.title) },
|
||||
secondaryText = { Text(item.subtitle) },
|
||||
icon = { Image(imageResource(Res.drawable.p1), contentDescription = null) },
|
||||
icon = { Image(painterResource(Res.drawable.p1), contentDescription = null) },
|
||||
overlineText = { Text("Overline text") },
|
||||
singleLineSecondaryText = false
|
||||
)
|
||||
@@ -94,7 +94,7 @@ fun UICards() {
|
||||
ListItem(
|
||||
text = { Text(item.title) },
|
||||
secondaryText = { Text(item.subtitle) },
|
||||
icon = { Image(imageResource(Res.drawable.p2), contentDescription = null) },
|
||||
icon = { Image(painterResource(Res.drawable.p2), contentDescription = null) },
|
||||
trailing = { Icon(Icons.Default.ShoppingCart, contentDescription = null) },
|
||||
singleLineSecondaryText = false
|
||||
)
|
||||
|
||||
@@ -2,12 +2,6 @@ package org.jetbrains.compose.demo.widgets.platform
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.loadXmlImageVector
|
||||
import androidx.compose.ui.res.painterResource
|
||||
|
||||
@Composable
|
||||
actual fun imageResource(res: String): Painter = painterResource(res)
|
||||
|
||||
@Composable
|
||||
actual fun vectorResource(res: String): Painter = painterResource(res)
|
||||
actual fun painterResource(res: String): Painter = androidx.compose.ui.res.painterResource(res)
|
||||
|
||||
Reference in New Issue
Block a user