Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 51 additions & 7 deletions Sources/SkipUI/SkipUI/UIKit/UIImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import android.graphics.ImageDecoder
import android.net.Uri
import java.nio.ByteBuffer
import android.graphics.Bitmap
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
#endif

// SKIP @bridge
Expand Down Expand Up @@ -80,15 +82,41 @@ public class UIImage {
public func prepareForDisplay(completionHandler: @escaping (UIImage?) -> Void) {
fatalError()
}
@available(*, unavailable)

public func preparingThumbnail(of size: CGSize) -> UIImage? {
fatalError()
#if SKIP
if let bitmap {
let newBitmap = Bitmap.createScaledBitmap(bitmap, Int(size.width), Int(size.height), true)
return UIImage(bitmap: newBitmap, scale: 1.0)
}
#endif
return nil
}

// SKIP @bridge
public func preparingThumbnail(width: CGFloat, height: CGFloat) -> UIImage? {
return preparingThumbnail(of: .init(width: width, height: height))
}

@available(*, unavailable)
public func prepareThumbnail(of size: CGSize, completionHandler: @escaping (UIImage?) -> Void) {
fatalError()
}

public func byPreparingThumbnail(ofSize size: CGSize) async -> UIImage? {
#if SKIP
return await withContext(Dispatchers.Default) {
preparingThumbnail(of: size)
}
#endif
return nil
}

// SKIP @bridge
public func byPreparingThumbnail(width: CGFloat, height: CGFloat) async -> UIImage? {
return await byPreparingThumbnail(ofSize: .init(width: width, height: height))
}

public init?(contentsOfFile path: String) {
#if SKIP
do {
Expand All @@ -101,6 +129,7 @@ public class UIImage {
}

self.bitmap = bitmap
self.size = .init(width: Double(bitmap.getWidth()), height: Double(bitmap.getHeight()))
} catch {
android.util.Log.w("SkipUI", "Error initializing UIImage from contentsOfFile", error as? Throwable)
return nil
Expand All @@ -125,7 +154,7 @@ public class UIImage {
}

self.bitmap = bitmap

self.size = .init(width: Double(bitmap.getWidth()), height: Double(bitmap.getHeight()))
} catch {
android.util.Log.w("SkipUI", "Error initializing UIImage from data", error as? Throwable)
return nil
Expand All @@ -138,6 +167,14 @@ public class UIImage {
public static func bridgedInit(data: Data, scale: CGFloat) -> UIImage? {
return UIImage(data: data, scale: scale)
}

#if SKIP
private init(bitmap: Bitmap, scale: CGFloat) {
self.bitmap = bitmap
self.size = .init(width: Double(bitmap.getWidth()), height: Double(bitmap.getHeight()))
self.scale = scale
}
#endif

@available(*, unavailable)
public struct UIImageReader {
Expand Down Expand Up @@ -213,11 +250,18 @@ public class UIImage {

// SKIP @bridge
public let scale: CGFloat

@available(*, unavailable)
public var size: CGSize {
fatalError()

public private(set) var size: CGSize = .zero

// SKIP @bridge
public var bridgedWidth: CGFloat {
return size.width
}
// SKIP @bridge
public var bridgedHeight: CGFloat {
return size.height
}

@available(*, unavailable)
public var imageOrientation: Any {
fatalError()
Expand Down