Skip to content

Commit

Permalink
Merge pull request #2296 from onevcat/fix/kfimage-tapping
Browse files Browse the repository at this point in the history
Align animated image interaction behavior to normal image and iOS 17
  • Loading branch information
onevcat authored Sep 21, 2024
2 parents 78c172b + 50fc41e commit cce8558
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions Demo/Demo/Kingfisher-Demo/SwiftUIViews/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct MainView: View {
Section(header: Text("Regression Cases")) {
NavigationLink(destination: Issue1998View()) { Text("#1998") }
NavigationLink(destination: Issue2035View()) { Text("#2035") }
NavigationLink(destination: Issue2295View()) { Text("#2295") }
}
}.navigationBarTitle(Text("SwiftUI Sample"))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// Issue2295View.swift
// Kingfisher
//
// Created by onevcat on 2024/09/21.
//
// Copyright (c) 2024 Wei Wang <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import SwiftUI
import Kingfisher

@available(iOS 14.0, *)
struct Issue2295View: View {

@State private var count = 0

var body: some View {
Text("This is a test case for #2295")
Text("Count: \(count)")
ScrollView {
VStack {
Text("Tapping these to add count.")
HStack {
KFImage(ImageLoader.sampleImageURLs.first)
.resizable()
.frame(width: 150, height: 150)
.onTapGesture {
count += 1
}
KFAnimatedImage(ImageLoader.sampleImageURLs.first)
.frame(width: 150, height: 150)
.onTapGesture {
count += 1
}
}
}
Divider()
VStack {
Text("These are not tappable.")
HStack {
KFImage(ImageLoader.sampleImageURLs.first)
.resizable()
.frame(width: 150, height: 150)
.allowsHitTesting(false)
.onTapGesture {
count += 1
}
KFAnimatedImage(ImageLoader.sampleImageURLs.first)
.frame(width: 150, height: 150)
.allowsHitTesting(false)
.onTapGesture {
count += 1
}
}
}
}
}
}

@available(iOS 14.0, *)
struct Issue2295View_Previews: PreviewProvider {
static var previews: some View {
Issue1998View()
}
}
4 changes: 4 additions & 0 deletions Demo/Kingfisher-Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
D1CE1BD321A1B45A00419000 /* ImageLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1CE1BD221A1B45A00419000 /* ImageLoader.swift */; };
D1CE1BD421A1B45A00419000 /* ImageLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1CE1BD221A1B45A00419000 /* ImageLoader.swift */; };
D1E4CF5421BACBA6004D029D /* ImageDataProviderCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1E4CF5321BACBA6004D029D /* ImageDataProviderCollectionViewController.swift */; };
D1EDF7422C9F01270017FFA5 /* Issue2295View.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1EDF7412C9F01200017FFA5 /* Issue2295View.swift */; };
D1F06F3321AA4292000B1C38 /* DetailImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1F06F3221AA4292000B1C38 /* DetailImageViewController.swift */; };
D1F06F3521AA5938000B1C38 /* ImageCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D12E0C911C47F91800AC98AD /* ImageCollectionViewCell.swift */; };
D1F06F3721AAEACF000B1C38 /* GIFViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1F06F3621AAEACF000B1C38 /* GIFViewController.swift */; };
Expand Down Expand Up @@ -217,6 +218,7 @@
D1CE1BD221A1B45A00419000 /* ImageLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageLoader.swift; sourceTree = "<group>"; };
D1E4CF5321BACBA6004D029D /* ImageDataProviderCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageDataProviderCollectionViewController.swift; sourceTree = "<group>"; };
D1ED2D0B1AD2CFA600CFC3EB /* Kingfisher-Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Kingfisher-Demo.app"; sourceTree = BUILT_PRODUCTS_DIR; };
D1EDF7412C9F01200017FFA5 /* Issue2295View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Issue2295View.swift; sourceTree = "<group>"; };
D1F06F3221AA4292000B1C38 /* DetailImageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailImageViewController.swift; sourceTree = "<group>"; };
D1F06F3621AAEACF000B1C38 /* GIFViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GIFViewController.swift; sourceTree = "<group>"; };
D1F06F3821AAF1EE000B1C38 /* IndicatorCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IndicatorCollectionViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -309,6 +311,7 @@
4BC0ED4829A6EE4F003E9CD1 /* Regression */ = {
isa = PBXGroup;
children = (
D1EDF7412C9F01200017FFA5 /* Issue2295View.swift */,
4B6E1B6C28DB4E8C0023B54B /* Issue1998View.swift */,
4BC0ED4929A6EE78003E9CD1 /* Issue2035View.swift */,
);
Expand Down Expand Up @@ -726,6 +729,7 @@
D198F42225EDC4B900C53E0D /* GridDemo.swift in Sources */,
4B1C7A3D21A256E300CE9D31 /* InfinityCollectionViewController.swift in Sources */,
078DCB512BCFEFB40008114E /* PHPickerResultViewController.swift in Sources */,
D1EDF7422C9F01270017FFA5 /* Issue2295View.swift in Sources */,
D1A1CCA321A1879600263AD8 /* MainViewController.swift in Sources */,
4BC0ED4A29A6EE78003E9CD1 /* Issue2035View.swift in Sources */,
D1F06F3721AAEACF000B1C38 /* GIFViewController.swift in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftUI/KFAnimatedImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public struct KFAnimatedImageViewRepresenter: KFCrossPlatformViewRepresentable,
private func makeImageView() -> AnimatedImageView {
let view = AnimatedImageView()

#if !os(macOS)
view.isUserInteractionEnabled = true
#endif

self.context.renderConfigurations.forEach { $0(view) }

view.image = image
Expand Down

0 comments on commit cce8558

Please sign in to comment.