This repository was archived by the owner on Sep 8, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +16
-8
lines changed
androidMain/kotlin/dev/icerock/moko/widgets/core
commonMain/kotlin/dev/icerock/moko/widgets/core
iosMain/kotlin/dev/icerock/moko/widgets/core Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -19,8 +19,8 @@ actual abstract class Image {
1919 return ResourceImage (imageResource)
2020 }
2121
22- actual fun network (url : String ): Image {
23- return NetworkImage (url)
22+ actual fun network (url : String , placeholder : ImageResource ? ): Image {
23+ return NetworkImage (url, placeholder )
2424 }
2525
2626 actual fun bitmap (bitmap : Bitmap ): Image {
@@ -35,11 +35,18 @@ private class ResourceImage(val imageResource: ImageResource) : Image() {
3535 }
3636}
3737
38- private class NetworkImage (val url : String ) : Image() {
38+ private class NetworkImage (val url : String , val placeholder : ImageResource ? ) : Image() {
3939 override fun loadIn (imageView : ImageView ) {
40+
4041 Glide .with (imageView)
4142 .load(Uri .parse(url))
43+ .apply {
44+ if (placeholder != null ) {
45+ placeholder(placeholder.drawableResId)
46+ }
47+ }
4248 .into(imageView)
49+
4350 }
4451}
4552
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ expect abstract class Image {
1111
1212 companion object {
1313 fun resource (imageResource : ImageResource ): Image
14- fun network (url : String ): Image
14+ fun network (url : String , placeholder : ImageResource ? = null ): Image
1515 fun bitmap (bitmap : Bitmap ): Image
1616 }
1717}
Original file line number Diff line number Diff line change @@ -22,8 +22,8 @@ actual abstract class Image {
2222 return ResourceImage (imageResource)
2323 }
2424
25- actual fun network (url : String ): Image {
26- return NetworkImage (url)
25+ actual fun network (url : String , placeholder : ImageResource ? ): Image {
26+ return NetworkImage (url, placeholder )
2727 }
2828
2929 actual fun bitmap (bitmap : Bitmap ): Image {
@@ -51,10 +51,11 @@ class BitmapImage(
5151
5252// TODO add https://github.com/SDWebImage/SDWebImage to cache images
5353class NetworkImage (
54- private val url : String
54+ private val url : String ,
55+ private val placeholder : ImageResource ?
5556) : Image() {
5657 override fun apply (view : UIView , block : (UIImage ? ) -> Unit ) {
57- block(null )
58+ block(placeholder?.toUIImage() )
5859
5960 try {
6061 val tag = url.hashCode().toLong()
You can’t perform that action at this time.
0 commit comments