You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
883 B
27 lines
883 B
4 years ago
|
package org.jetbrains.compose.demo.widgets.platform
|
||
|
|
||
|
import androidx.compose.runtime.Composable
|
||
|
import androidx.compose.ui.graphics.ImageBitmap
|
||
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||
|
import org.jetbrains.compose.demo.widgets.R
|
||
|
|
||
|
@Composable
|
||
|
actual fun imageResource(res: String): ImageBitmap {
|
||
|
val id = drawableId(res)
|
||
|
return androidx.compose.ui.res.imageResource(id)
|
||
|
}
|
||
|
|
||
|
@Composable
|
||
|
actual fun vectorResource(res: String): ImageVector {
|
||
|
val id = drawableId(res)
|
||
|
return androidx.compose.ui.res.vectorResource(id)
|
||
|
}
|
||
|
|
||
|
// TODO: improve resource loading
|
||
|
private fun drawableId(res: String): Int {
|
||
|
val imageName = res.substringAfterLast("/").substringBeforeLast(".")
|
||
|
val drawableClass = R.drawable::class.java
|
||
|
val field = drawableClass.getDeclaredField(imageName)
|
||
|
val idValue = field.get(drawableClass) as Integer
|
||
|
return idValue.toInt()
|
||
|
}
|