Skip to content

Commit

Permalink
Demo project for SwiftUI
Browse files Browse the repository at this point in the history
  • Loading branch information
onevcat committed Aug 18, 2019
1 parent 524c5ff commit 93aa6d4
Show file tree
Hide file tree
Showing 14 changed files with 509 additions and 97 deletions.
2 changes: 1 addition & 1 deletion Demo/Demo/Kingfisher-SwiftUI-Demo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// AppDelegate.swift
// Kingfisher
//
// Created by jp20028 on 2019/08/07.
// Created by onevcat on 2019/08/18.
//
// Copyright (c) 2019 Wei Wang <[email protected]>
//
Expand Down
2 changes: 1 addition & 1 deletion Demo/Demo/Kingfisher-SwiftUI-Demo/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SceneDelegate.swift
// Kingfisher
//
// Created by jp20028 on 2019/08/07.
// Created by onevcat on 2019/08/18.
//
// Copyright (c) 2019 Wei Wang <[email protected]>
//
Expand Down
3 changes: 1 addition & 2 deletions Demo/Demo/Kingfisher-SwiftUI-Demo/Views/SwiftUIList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import KingfisherSwiftUI
import Kingfisher
import SwiftUI

struct SwiftUIList : View {
Expand All @@ -35,7 +35,6 @@ struct SwiftUIList : View {
List(index) { i in
HStack(alignment: .center) {
Spacer()

KFImage(
URL(string: "https://github.com/onevcat/Flower-Data-Set/raw/master/rose/rose-\(i).jpg")!,
options: [.transition(.fade(0.4))]
Expand Down
2 changes: 1 addition & 1 deletion Demo/Demo/Kingfisher-SwiftUI-Demo/Views/SwiftUIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import KingfisherSwiftUI
import Kingfisher
import SwiftUI

struct SwiftUIView : View {
Expand Down
199 changes: 198 additions & 1 deletion Demo/Kingfisher-Demo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

280 changes: 274 additions & 6 deletions Kingfisher.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1100"
version = "1.7">
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
Expand All @@ -14,9 +14,9 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D134D49722DCC375002F5C35"
BuildableName = "KingfisherSwiftUI.framework"
BlueprintName = "Kingfisher-SwiftUI"
BlueprintIdentifier = "D1F7603B230974DE000C5269"
BuildableName = "Kingfisher.framework"
BlueprintName = "KingfisherSwiftUI"
ReferencedContainer = "container:Kingfisher.xcodeproj">
</BuildableReference>
</BuildActionEntry>
Expand All @@ -27,8 +27,8 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<TestPlans>
</TestPlans>
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -50,9 +50,9 @@
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D134D49722DCC375002F5C35"
BuildableName = "KingfisherSwiftUI.framework"
BlueprintName = "Kingfisher-SwiftUI"
BlueprintIdentifier = "D1F7603B230974DE000C5269"
BuildableName = "Kingfisher.framework"
BlueprintName = "KingfisherSwiftUI"
ReferencedContainer = "container:Kingfisher.xcodeproj">
</BuildableReference>
</MacroExpansion>
Expand Down
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ let package = Package(
targets: [
.target(
name: "Kingfisher",
path: "Sources"
path: "Sources",
exclude: ["SwiftUI"]
)
]
)
13 changes: 9 additions & 4 deletions Sources/Cache/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ public enum StorageExpiration {
func estimatedExpirationSince(_ date: Date) -> Date {
switch self {
case .never: return .distantFuture
case .seconds(let seconds): return date.addingTimeInterval(seconds)
case .days(let days): return date.addingTimeInterval(TimeInterval(TimeConstants.secondsInOneDay * days))
case .date(let ref): return ref
case .expired: return .distantPast
case .seconds(let seconds):
return date.addingTimeInterval(seconds)
case .days(let days):
let duration = TimeInterval(TimeConstants.secondsInOneDay * days)
return date.addingTimeInterval(duration)
case .date(let ref):
return ref
case .expired:
return .distantPast
}
}

Expand Down
4 changes: 1 addition & 3 deletions Sources/SwiftUI/ImageBinder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@

import Combine
import SwiftUI
import Kingfisher

@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension KFImage {

/// Represents a binder for `KFImage`. It takes responsibility as an `ObjectBinding` and performs
Expand All @@ -46,7 +44,7 @@ extension KFImage {
let onSuccessDelegate = Delegate<RetrieveImageResult, Void>()
let onProgressDelegate = Delegate<(Int64, Int64), Void>()

@Published var image: Kingfisher.KFCrossPlatformImage?
@Published var image: KFCrossPlatformImage?

// Only `.fade` is now supported.
var fadeTransitionAnimation: Animation? {
Expand Down
22 changes: 0 additions & 22 deletions Sources/SwiftUI/Info.plist

This file was deleted.

6 changes: 0 additions & 6 deletions Sources/SwiftUI/KFImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@

import SwiftUI
import Combine
import Kingfisher

@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension Image {
// Creates an SwiftUI.Image with either UIImage or NSImage.
init(crossPlatformImage: KFCrossPlatformImage) {
Expand All @@ -42,7 +40,6 @@ extension Image {

/// A Kingfisher compatible SwiftUI `View` to load an image from a `Source`.
/// Declaring a `KFImage` in a `View`'s body to trigger loading from the given `Source`.
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public struct KFImage: View {

/// An image binder that manages loading and cancelling image related task.
Expand Down Expand Up @@ -99,7 +96,6 @@ public struct KFImage: View {
}
}

@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension KFImage {

/// Configures current image with a `block`. This block will be lazily applied when creating the final `Image`.
Expand Down Expand Up @@ -150,7 +146,6 @@ extension KFImage {
}
}

@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension KFImage {

/// Sets the action to perform when the image setting fails.
Expand Down Expand Up @@ -182,7 +177,6 @@ extension KFImage {
}

#if DEBUG
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
struct KFImage_Previews : PreviewProvider {
static var previews: some View {
Group {
Expand Down
37 changes: 0 additions & 37 deletions Sources/SwiftUI/KingfisherSwiftUI.h

This file was deleted.

15 changes: 12 additions & 3 deletions Sources/Views/Indicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,21 @@ final class ActivityIndicator: Indicator {
activityIndicatorView.controlSize = .small
activityIndicatorView.style = .spinning
#else
let indicatorStyle: UIActivityIndicatorView.Style
#if os(tvOS)
let indicatorStyle = UIActivityIndicatorView.Style.white
if #available(tvOS 13.0, *) {
indicatorStyle = UIActivityIndicatorView.Style.medium
} else {
indicatorStyle = UIActivityIndicatorView.Style.white
}
#elseif targetEnvironment(macCatalyst)
let indicatorStyle = UIActivityIndicatorView.Style.medium
indicatorStyle = UIActivityIndicatorView.Style.medium
#else
let indicatorStyle = UIActivityIndicatorView.Style.gray
if #available(iOS 13.0, *) {
indicatorStyle = UIActivityIndicatorView.Style.medium
} else {
indicatorStyle = UIActivityIndicatorView.Style.gray
}
#endif
#if swift(>=4.2)
activityIndicatorView = UIActivityIndicatorView(style: indicatorStyle)
Expand Down

0 comments on commit 93aa6d4

Please sign in to comment.