rememberDrawablePainter
Remembers Drawable wrapped up as a Painter. This function attempts to un-wrap the drawable contents and use Compose primitives where possible.
If the provided drawable is null
, an empty no-op painter is returned.
This function tries to dispatch lifecycle events to drawable as much as possible from within Compose.
Samples
import androidx.appcompat.content.res.AppCompatResources
import androidx.compose.foundation.Image
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import com.google.accompanist.drawablepainter.rememberDrawablePainter
import com.google.accompanist.sample.R
fun main() {
//sampleStart
val drawable = AppCompatResources.getDrawable(LocalContext.current, R.drawable.rectangle)
Image(
painter = rememberDrawablePainter(drawable = drawable),
contentDescription = "content description",
)
//sampleEnd
}