Enhancements for SwiftUI.
This commit is contained in:
parent
8c8fb6971d
commit
42bd468dcf
|
@ -8,6 +8,7 @@
|
|||
import Foundation
|
||||
import UIKit
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
@objc private class DigestKey: NSObject {
|
||||
let digest: Data
|
||||
|
@ -30,6 +31,12 @@ extension LifeHashGenerator {
|
|||
private static let serializer = DispatchQueue(label: "LifeHash serializer")
|
||||
private static var cancellables: [DigestKey: AnyCancellable] = [:]
|
||||
|
||||
public static func image(for fingerprint: Fingerprint) -> AnyPublisher<Image, Never> {
|
||||
getCachedImage(fingerprint).map { image in
|
||||
Image(uiImage: image).interpolation(.none)
|
||||
}.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
public static func getCachedImage(_ obj: Fingerprintable) -> Future<UIImage, Never> {
|
||||
getCachedImage(obj.fingerprint)
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import Foundation
|
|||
import Combine
|
||||
import UIKit
|
||||
import Dispatch
|
||||
import SwiftUI
|
||||
|
||||
public final class LifeHashState: ObservableObject {
|
||||
public var input: Fingerprintable? {
|
||||
|
@ -24,7 +25,13 @@ public final class LifeHashState: ObservableObject {
|
|||
updateImage()
|
||||
}
|
||||
|
||||
@Published var image: UIImage?
|
||||
public init(input: Fingerprintable?) {
|
||||
self.input = input
|
||||
self.fingerprint = input?.fingerprint
|
||||
updateImage()
|
||||
}
|
||||
|
||||
@Published var image: Image?
|
||||
|
||||
private var cancellable: AnyCancellable?
|
||||
|
||||
|
@ -36,7 +43,7 @@ public final class LifeHashState: ObservableObject {
|
|||
cancellable?.cancel()
|
||||
cancellable = LifeHashGenerator.getCachedImage(fingerprint).sink { image in
|
||||
DispatchQueue.main.async {
|
||||
self.image = image
|
||||
self.image = Image(uiImage: image).interpolation(.none)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,9 +20,8 @@ public struct LifeHashView<MissingView: View>: View {
|
|||
public var body: some View {
|
||||
Group {
|
||||
if state.image != nil {
|
||||
Image(uiImage: state.image!)
|
||||
state.image!
|
||||
.resizable()
|
||||
.interpolation(.none)
|
||||
} else {
|
||||
missingView
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue