Khanzada Kashif
09/06/2023, 8:36 AMMichael Paus
09/06/2023, 9:03 AMKhanzada Kashif
09/06/2023, 12:23 PMJeff Lockhart
09/06/2023, 4:07 PMKhanzada Kashif
09/06/2023, 4:10 PMJeff Lockhart
09/06/2023, 4:17 PMKhanzada Kashif
09/06/2023, 4:42 PMShivam Kanodia
10/27/2023, 9:05 AMShivam Kanodia
10/27/2023, 9:05 AMKhanzada Kashif
10/27/2023, 9:32 AMShivam Kanodia
10/27/2023, 9:36 AMKhanzada Kashif
10/27/2023, 10:45 AMKhanzada Kashif
10/27/2023, 10:46 AM@Composable
expect fun MYAsyncImage(
url: String,
contentScale: ContentScale = ContentScale.FillBounds,
contentDescription: String? = null,
modifier: Modifier,
onClick: () -> Unit
)
Khanzada Kashif
10/27/2023, 10:47 AM@Composable
actual fun MYAsyncImage(
url: String,
contentScale: ContentScale,
contentDescription: String?,
modifier: Modifier,
onClick: () -> Unit
) {
AsyncImage(
modifier = modifier.clickable {
onClick()
},
model = ImageRequest.Builder(LocalContext.current).data(url).crossfade(true).build(),
contentDescription = contentDescription,
contentScale = contentScale,
onError = {
Log.e("image error", it.result.throwable.localizedMessage ?: "image error")
}
)
}
Khanzada Kashif
10/27/2023, 10:47 AM@Composable
actual fun MYAsyncImage(
url: String,
contentScale: ContentScale,
contentDescription: String?,
modifier: Modifier,
onClick: () -> Unit
) {
val imageView = rememberSaveable(url) {
UIImageView().apply {
layer.zPosition = 1.0
loadImageFromUrl(url = url)
}
}
Box(
modifier = modifier
) {
UIKitView(
factory = {
imageView
},
modifier = Modifier,
interactive = true
)
Box(modifier = Modifier.zIndex(100f).fillMaxSize().clickable {
onClick()
})
}
}
fun UIImageView.loadImageFromUrl(url: String) {
if (url.contains("\\s".toRegex()).not())
NSURLSession.sharedSession.dataTaskWithURL(
url = NSURL(string = url),
completionHandler = { data, response, error ->
if (error == null && response != null && data != null) {
if ((response as NSHTTPURLResponse).statusCode == 200L) {
CoroutineScope(Dispatchers.Main).launch {
image = UIImage(data = data)
}
}
}
}
).resume()
}
Khanzada Kashif
10/27/2023, 10:48 AMKhanzada Kashif
10/27/2023, 10:49 AM