Open saket opened 3 weeks ago
ZoomableImage() does not correctly measure images when Modifier.wrapContentSize() is used.
ZoomableImage()
Modifier.wrapContentSize()
Image()
Image( modifier = Modifier.wrapContentSize(), painter = assetPainter("cat_1920.jpg"), contentDescription = null, contentScale = ContentScale.Crop, alignment = Alignment.BottomCenter, )
ZoomableImage( modifier = Modifier.wrapContentSize(), image = ZoomableImageSource.asset("cat_1920.jpg"), contentDescription = null, contentScale = ContentScale.Crop, alignment = Alignment.BottomCenter, )
@Composable internal fun ZoomableImageSource.Companion.asset(assetName: String): ZoomableImageSource { val painter = assetPainter(assetName) return remember(painter) { object : ZoomableImageSource { @Composable override fun resolve(canvasSize: Flow<Size>): ResolveResult { return ResolveResult( delegate = ZoomableImageSource.PainterDelegate(painter) ) } } } } @Composable private fun assetPainter(assetName: String): Painter { val context = LocalContext.current return remember(assetName) { context.assets.open(assetName).use { stream -> BitmapPainter(BitmapFactory.decodeStream(stream).asImageBitmap()) } } }
ZoomableImage()
does not correctly measure images whenModifier.wrapContentSize()
is used.Image()
ZoomableImage()