Hi there we are unable to load swift imageview as ...
# multiplatform
s
Hi there we are unable to load swift imageview as a part of composable view, do we have any restriction for this??. we wrote actual/expect for to load image separately for iOS and Android using their native image loading libs, but unfortunately, in iOS swift image view not becoming visible until we wrap swift imageview inside UIKitView. Can someone help on this.
Copy code
UIKitView {....}
p
If you want to show swiftui/uiKit in compose you have to use Uikitview or UiKitViewController. Is the way the API is designed I believe.
💯 1
a
There are lots of frameworks that allow to draw images directly into compose. Maybe, using interop to UIImageView is not what you're looking for.
s
Maybe, using interop to UIImageView is not what you're looking for.
yes I am not looking into this
@Andrei Salavei as attached in Screen shot this is what I wanted to achieve is this possible?. i.e entire scene is composable and contains lazy column only one row in column contains swift UI.
the swift image is not becoming visible, until we wrap returned UIView inside
UIKitView
in iosMain
actually I wanted to load only swift image inside lazy column as one row, other rows still remains purely as composable items..
a
Still can't understand reasons why it's needed, as Kamel already works in multiplatform - and it will be the correct way to use images in the app.
the swift image is not becoming visible, until we wrap returned UIView inside
UIKitView
in iosMain
Yes, that's the way to embed interop views. What code you're using to add image in the first case?
s
> Andrei Salavei [JetBrains] [3:28 PM] > Still can't understand reasons why it's needed, as Kamel already works in multiplatform - and it will be the correct way to use images in the app. we tried Kamel and Coil libraries to load image, in case of iOS, we are seeing sudden spike in memory consumption when image loads, and its not releasing as soon as we scroll the lazy column. as I mentioned here, https://kotlinlang.slack.com/archives/C3PQML5NU/p1717523423831819
just to mitigate that problem, we wanted load images natively. And we see there is no memory spike when we use nuke library in case of iOS, But as we returning the UIView to iosMain and again wrapping inside UIKitview, which is resulting in slow performance...
👍 1
> What code you're using to add image in the first case?
Copy code
//ImageLoaderiOS.swift


@MainActor
struct ImageView: View {
  // Property to hold the input text
  private var text: String = ""
  public init?(string: String){
    text = string
  }
 private let pipeline = ImagePipeline {
  $0.dataLoader = {
   let config = URLSessionConfiguration.default
   config.urlCache = nil
   return DataLoader(configuration: config)
  }()
 }
 var body: some View {
  VStack{
   makeImage(url: URL(string: text))
    
  }
 }
 func makeImage(url: URL?) -> some View {
  LazyImage(url: url) { state in
   if let image = state.image {
    image
     .resizable()
     .aspectRatio(contentMode: .fill)
   } else {
    Color.gray.opacity(0.2)
   }
  }
  .pipeline(pipeline)
  .frame(height: 400)
  .frame(width: 400)
 }
}
a
Ah, okay, I see. So it's much better to solve problem with memory consumption rather the embedding SwiftUI views (Btw, UIKit views will work a bit faster). If you cannot resize your images on server, the most obvious solution here: download image from swift, resize it to required size, and then pass to Compose image view. As far as I know, on iOS images are extracting directly into GPU memory, which isn't present in memory consumption stat. We will take a look on this use-case scenario to find better solution.
🙏 1
s
If you cannot resize your images on server, the most obvious solution here: download image from swift, resize it to required size, and then pass to Compose image view.
instead passing swift UIView to compose image view, why can't we make ios view visible at called place itself i,e in swift itself and make it visible without adding it to UIKit
what is exactly blocking renderring GUI from swift,
a
You can, use UIKitView {} or UIKitViewController {} (second one works for embedding SwiftUI code), but they won't work 100% in the way you want.
👍 1
🥴 1
s
lol crazy meme... 😅