Add all the available version check, allows for lower firmware deployment target version user

This commit is contained in:
DreamPiggy 2019-12-04 17:12:44 +08:00
parent 1582e80e41
commit 9061beace3
9 changed files with 51 additions and 7 deletions

View File

@ -12,6 +12,7 @@ import SDWebImage
#if os(iOS) || os(tvOS) || os(macOS)
/// A coordinator object used for `AnimatedImage`native view bridge for UIKit/AppKit/WatchKit.
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public final class AnimatedImageCoordinator: NSObject {
/// Any user-provided object for actual coordinator, such as delegate method, taget-action
@ -22,6 +23,7 @@ public final class AnimatedImageCoordinator: NSObject {
}
/// Data Binding Object, only properties in this object can support changes from user with @State and refresh
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
final class AnimatedImageModel : ObservableObject {
/// URL image
@Published var url: URL?
@ -36,6 +38,7 @@ final class AnimatedImageModel : ObservableObject {
}
/// Completion Handler Binding Object, supports dynamic @State changes
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
final class AnimatedImageHandler: ObservableObject {
// Completion Handler
@Published var successBlock: ((PlatformImage, SDImageCacheType) -> Void)?
@ -47,6 +50,7 @@ final class AnimatedImageHandler: ObservableObject {
}
/// Layout Binding Object, supports dynamic @State changes
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
final class AnimatedImageLayout : ObservableObject {
var contentMode: ContentMode?
var aspectRatio: CGFloat?
@ -58,6 +62,7 @@ final class AnimatedImageLayout : ObservableObject {
}
/// Configuration Binding Object, supports dynamic @State changes
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
final class AnimatedImageConfiguration: ObservableObject {
var incrementalLoad: Bool?
var maxBufferSize: UInt?
@ -73,6 +78,7 @@ final class AnimatedImageConfiguration: ObservableObject {
}
/// A Image View type to load image from url, data or bundle. Supports animated and static image format.
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public struct AnimatedImage : PlatformViewRepresentable {
@ObservedObject var imageModel = AnimatedImageModel()
@ObservedObject var imageHandler = AnimatedImageHandler()
@ -444,6 +450,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
}
// Layout
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension AnimatedImage {
/// Configurate this view's image with the specified cap insets and options.
@ -483,6 +490,7 @@ extension AnimatedImage {
}
// Aspect Ratio
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension AnimatedImage {
/// Constrains this view's dimensions to the specified aspect ratio.
/// - Parameters:
@ -541,6 +549,7 @@ extension AnimatedImage {
}
// AnimatedImage Modifier
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension AnimatedImage {
/// Total loop count for animated image rendering. Defaults to nil.
@ -610,6 +619,7 @@ extension AnimatedImage {
}
// Completion Handler
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension AnimatedImage {
/// Provide the action when image load fails.
@ -641,6 +651,7 @@ extension AnimatedImage {
}
// View Coordinator Handler
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension AnimatedImage {
/// Provide the action when view representable create the native view.
@ -668,6 +679,7 @@ extension AnimatedImage {
}
// Web Image convenience
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension AnimatedImage {
/// Associate a placeholder when loading image with url
@ -695,6 +707,7 @@ extension AnimatedImage {
}
#if DEBUG
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
struct AnimatedImage_Previews : PreviewProvider {
static var previews: some View {
Group {

View File

@ -9,6 +9,7 @@
import SwiftUI
import SDWebImage
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
class ImageManager : ObservableObject {
@Published var image: PlatformImage? // loaded image, note when progressive loading, this will published multiple times with different partial image
@Published var isLoading: Bool = false // whether network is loading or cache is querying, should only be used for indicator binding

View File

@ -12,6 +12,7 @@ import SDWebImage
#if os(iOS) || os(tvOS) || os(macOS)
/// Use wrapper to solve tne `UIImageView`/`NSImageView` frame size become image size issue (SwiftUI's Bug)
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public class AnimatedImageViewWrapper : PlatformView {
var wrapped = SDAnimatedImageView()
var interpolationQuality = CGInterpolationQuality.default
@ -67,29 +68,33 @@ public class AnimatedImageViewWrapper : PlatformView {
}
}
private var sd_imageNameKey: Void?
private var sd_imageDataKey: Void?
/// Store the Animated Image loading state, to avoid re-query duinrg `updateView(_:)` until Source of Truth changes
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension PlatformView {
static private var sd_imageNameKey: Void?
static private var sd_imageDataKey: Void?
var sd_imageName: String? {
get {
objc_getAssociatedObject(self, &sd_imageNameKey) as? String
objc_getAssociatedObject(self, &UIView.sd_imageNameKey) as? String
}
set {
objc_setAssociatedObject(self, &sd_imageNameKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
objc_setAssociatedObject(self, &UIView.sd_imageNameKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
var sd_imageData: Data? {
get {
objc_getAssociatedObject(self, &sd_imageDataKey) as? Data
objc_getAssociatedObject(self, &UIView.sd_imageDataKey) as? Data
}
set {
objc_setAssociatedObject(self, &sd_imageDataKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
objc_setAssociatedObject(self, &UIView.sd_imageDataKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}
/// Use wrapper to solve the `UIProgressView`/`NSProgressIndicator` frame origin NaN crash (SwiftUI's bug)
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public class ProgressIndicatorWrapper : PlatformView {
#if os(macOS)
var wrapped = NSProgressIndicator()

View File

@ -10,6 +10,7 @@ import SwiftUI
#if os(macOS) || os(iOS) || os(tvOS)
/// An activity indicator (system style)
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public struct ActivityIndicator: PlatformViewRepresentable {
@Binding var isAnimating: Bool
var style: Style
@ -71,6 +72,7 @@ public struct ActivityIndicator: PlatformViewRepresentable {
#endif
}
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension ActivityIndicator {
public enum Style {
case medium

View File

@ -10,6 +10,7 @@ import Foundation
import SwiftUI
/// A type to build the indicator
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public struct Indicator<T> where T : View {
var content: (Binding<Bool>, Binding<CGFloat>) -> T
@ -26,6 +27,7 @@ public struct Indicator<T> where T : View {
/// A implementation detail View Modifier with indicator
/// SwiftUI View Modifier construced by using a internal View type which modify the `body`
/// It use type system to represent the view hierarchy, and Swift `some View` syntax to hide the type detail for users
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
struct IndicatorViewModifier<T> : ViewModifier where T : View {
@ObservedObject var imageManager: ImageManager
@ -44,6 +46,7 @@ struct IndicatorViewModifier<T> : ViewModifier where T : View {
}
#if os(macOS) || os(iOS) || os(tvOS)
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension Indicator where T == ActivityIndicator {
/// Activity Indicator
public static var activity: Indicator {
@ -61,6 +64,7 @@ extension Indicator where T == ActivityIndicator {
}
}
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension Indicator where T == ProgressIndicator {
/// Progress Indicator
public static var progress: Indicator {

View File

@ -10,6 +10,7 @@ import SwiftUI
#if os(macOS) || os(iOS) || os(tvOS)
/// A progress bar indicator (system style)
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public struct ProgressIndicator: PlatformViewRepresentable {
@Binding var isAnimating: Bool
@Binding var progress: CGFloat
@ -101,6 +102,7 @@ public struct ProgressIndicator: PlatformViewRepresentable {
#endif
}
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension ProgressIndicator {
public enum Style {
case `default`

View File

@ -10,11 +10,14 @@ import Foundation
import SwiftUI
#if os(macOS)
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public typealias PlatformImage = NSImage
#else
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public typealias PlatformImage = UIImage
#endif
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension Image {
init(platformImage: PlatformImage) {
#if os(macOS)
@ -26,21 +29,27 @@ extension Image {
}
#if os(macOS)
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public typealias PlatformView = NSView
#endif
#if os(iOS) || os(tvOS)
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public typealias PlatformView = UIView
#endif
#if os(watchOS)
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public typealias PlatformView = WKInterfaceObject
#endif
#if os(macOS)
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public typealias PlatformViewRepresentable = NSViewRepresentable
#endif
#if os(iOS) || os(tvOS)
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public typealias PlatformViewRepresentable = UIViewRepresentable
#endif
#if os(watchOS)
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public typealias PlatformViewRepresentable = WKInterfaceObjectRepresentable
#endif

View File

@ -8,6 +8,7 @@
import SwiftUI
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension AnyTransition {
/// Fade-in transition

View File

@ -9,7 +9,8 @@
import SwiftUI
import SDWebImage
/// A Image View type to load image from url. Supports static image format.
/// A Image View type to load image from url. Supports static/animated image format.
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public struct WebImage : View {
var configurations: [(Image) -> Image] = []
@ -90,6 +91,7 @@ public struct WebImage : View {
}
// Layout
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension WebImage {
func configure(_ block: @escaping (Image) -> Image) -> WebImage {
var result = self
@ -127,6 +129,7 @@ extension WebImage {
}
// Completion Handler
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension WebImage {
/// Provide the action when image load fails.
@ -158,6 +161,7 @@ extension WebImage {
}
// WebImage Modifier
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension WebImage {
/// Associate a placeholder when loading image with url
@ -198,6 +202,7 @@ extension WebImage {
}
// Indicator
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension WebImage {
/// Associate a indicator when loading image with url
@ -214,6 +219,7 @@ extension WebImage {
}
// Animated Image support (Beta)
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension WebImage {
/// Make the image to support animated images. The animation will start when view appears, and pause when disappears.
@ -259,6 +265,7 @@ extension WebImage {
}
#if DEBUG
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
struct WebImage_Previews : PreviewProvider {
static var previews: some View {
Group {