Skip to content

Commit

Permalink
Remove animation setting based on options
Browse files Browse the repository at this point in the history
  • Loading branch information
onevcat committed Oct 3, 2019
1 parent ea84ff2 commit 8b0d254
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 47 deletions.
77 changes: 48 additions & 29 deletions Demo/Demo/Kingfisher-SwiftUI-Demo/Views/SwiftUIList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import Kingfisher
import KingfisherSwiftUI
import SwiftUI

Expand All @@ -33,41 +34,59 @@ struct SwiftUIList : View {

var body: some View {
List(index) { i in
ListCell(index: i)
}.navigationBarTitle(Text("SwiftUI List"), displayMode: .inline)
}

struct ListCell: View {

@State var done = false

var alreadyCached: Bool {
ImageCache.default.isCached(forKey: url.absoluteString)
}

let index: Int
var url: URL {
URL(string: "https://github.com/onevcat/Flower-Data-Set/raw/master/rose/rose-\(index).jpg")!
}

var body: some View {
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))]
)
.resizable()
.onSuccess { r in
print("Success: \(i) - \(r.cacheType)")
}
.onFailure { e in
print("Error \(i): \(e)")
}
.onProgress { downloaded, total in
print("\(downloaded) / \(total))")
}
.placeholder {
HStack {
Image(systemName: "arrow.2.circlepath.circle")
.resizable()
.frame(width: 50, height: 50)
.padding(10)
Text("Loading...").font(.title)
KFImage(url)
.resizable()
.onSuccess { r in
self.done = true
print("Success: \(self.index) - \(r.cacheType)")
}
.onFailure { e in
print("Error \(self.index): \(e)")
}
.onProgress { downloaded, total in
print("\(downloaded) / \(total))")
}
.foregroundColor(.gray)
.opacity(0.3)
}
.cancelOnDisappear(true)
.aspectRatio(contentMode: .fit)
.cornerRadius(20)
.frame(width: 300, height: 300)
.placeholder {
HStack {
Image(systemName: "arrow.2.circlepath.circle")
.resizable()
.frame(width: 50, height: 50)
.padding(10)
Text("Loading...").font(.title)
}
.foregroundColor(.gray)
}
.cancelOnDisappear(true)
.aspectRatio(contentMode: .fit)
.cornerRadius(20)
.frame(width: 300, height: 300)
.opacity(done || alreadyCached ? 1.0 : 0.3)
.animation(.linear(duration: 0.4))

Spacer()
}.padding(.vertical, 12)
}.navigationBarTitle(Text("SwiftUI List"), displayMode: .inline)
}

}
}

Expand Down
17 changes: 0 additions & 17 deletions Sources/SwiftUI/ImageBinder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,6 @@ extension KFImage {

@Published var image: KFCrossPlatformImage?

// Only `.fade` is now supported.
var fadeTransitionAnimation: Animation? {
#if os(iOS) || os(tvOS)
guard let options = (options.map { KingfisherParsedOptionsInfo($0) }) else {
return nil
}
switch options.transition {
case .fade(let duration):
return .linear(duration: duration)
default:
return nil
}
#else
return nil
#endif
}

init(source: Source?, options: KingfisherOptionsInfo?) {
self.source = source
self.options = options
Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftUI/KFImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public struct KFImage: View {
.reduce(Image(crossPlatformImage: binder.image!)) {
current, config in config(current)
}
.animation(binder.fadeTransitionAnimation)
} else {
Group {
if placeholder != nil {
Expand Down

0 comments on commit 8b0d254

Please sign in to comment.