Skip to content

Commit

Permalink
Merge pull request onevcat#1840 from onevcat/fix/wrap-kfimage
Browse files Browse the repository at this point in the history
Wrap KFImage to a ZStack
  • Loading branch information
onevcat authored Oct 11, 2021
2 parents 5d8f18e + 33e824a commit cd31c6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 10 additions & 1 deletion Demo/Demo/Kingfisher-Demo/SwiftUIViews/LazyVStackDemo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,23 @@
// THE SOFTWARE.

import SwiftUI
import Kingfisher

@available(iOS 14.0, *)
struct LazyVStackDemo: View {
@State private var singleImage = false

var body: some View {
ScrollView {
// Checking for #1839
Toggle("Single Image", isOn: $singleImage).padding()
LazyVStack {
ForEach(1..<700) { i in
ImageCell(index: i).frame(width: 300, height: 300)
if singleImage {
KFImage.url(ImageLoader.roseImage(index: 1))
} else {
ImageCell(index: i).frame(width: 300, height: 300)
}
}
}
}.navigationBarTitle(Text("Lazy Stack"), displayMode: .inline)
Expand Down
7 changes: 5 additions & 2 deletions Sources/SwiftUI/KFImageProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ public protocol KFImageProtocol: View, KFOptionSetter {
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
extension KFImageProtocol {
public var body: some View {
KFImageRenderer<HoldingView>(context: context)
.id(context)
ZStack {
KFImageRenderer<HoldingView>(
context: context
).id(context)
}
}

/// Creates a Kingfisher compatible image view to load image from the given `Source`.
Expand Down

0 comments on commit cd31c6e

Please sign in to comment.