From b4837a97d9f7a95d8eb8a00c304361b3c2782d93 Mon Sep 17 00:00:00 2001 From: onevcat Date: Sat, 21 Sep 2024 22:20:40 +0900 Subject: [PATCH 1/3] Allow user interaction for animated image --- Sources/SwiftUI/KFAnimatedImage.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/SwiftUI/KFAnimatedImage.swift b/Sources/SwiftUI/KFAnimatedImage.swift index ac5685244..4f199d625 100644 --- a/Sources/SwiftUI/KFAnimatedImage.swift +++ b/Sources/SwiftUI/KFAnimatedImage.swift @@ -87,6 +87,7 @@ public struct KFAnimatedImageViewRepresenter: KFCrossPlatformViewRepresentable, @MainActor private func makeImageView() -> AnimatedImageView { let view = AnimatedImageView() + view.isUserInteractionEnabled = true self.context.renderConfigurations.forEach { $0(view) } From 411268706676e005615123b277ce2a2552c6c67b Mon Sep 17 00:00:00 2001 From: onevcat Date: Sat, 21 Sep 2024 22:37:18 +0900 Subject: [PATCH 2/3] Add regression sample scene --- .../SwiftUIViews/MainView.swift | 1 + .../Regression/Issue2295View.swift | 83 +++++++++++++++++++ .../Kingfisher-Demo.xcodeproj/project.pbxproj | 4 + 3 files changed, 88 insertions(+) create mode 100644 Demo/Demo/Kingfisher-Demo/SwiftUIViews/Regression/Issue2295View.swift diff --git a/Demo/Demo/Kingfisher-Demo/SwiftUIViews/MainView.swift b/Demo/Demo/Kingfisher-Demo/SwiftUIViews/MainView.swift index 86639c528..ba9528196 100644 --- a/Demo/Demo/Kingfisher-Demo/SwiftUIViews/MainView.swift +++ b/Demo/Demo/Kingfisher-Demo/SwiftUIViews/MainView.swift @@ -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")) } diff --git a/Demo/Demo/Kingfisher-Demo/SwiftUIViews/Regression/Issue2295View.swift b/Demo/Demo/Kingfisher-Demo/SwiftUIViews/Regression/Issue2295View.swift new file mode 100644 index 000000000..07c248c68 --- /dev/null +++ b/Demo/Demo/Kingfisher-Demo/SwiftUIViews/Regression/Issue2295View.swift @@ -0,0 +1,83 @@ +// +// Issue2295View.swift +// Kingfisher +// +// Created by onevcat on 2024/09/21. +// +// Copyright (c) 2024 Wei Wang +// +// 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() + } +} diff --git a/Demo/Kingfisher-Demo.xcodeproj/project.pbxproj b/Demo/Kingfisher-Demo.xcodeproj/project.pbxproj index 70596c9b5..8cedd1200 100644 --- a/Demo/Kingfisher-Demo.xcodeproj/project.pbxproj +++ b/Demo/Kingfisher-Demo.xcodeproj/project.pbxproj @@ -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 */; }; @@ -217,6 +218,7 @@ D1CE1BD221A1B45A00419000 /* ImageLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageLoader.swift; sourceTree = ""; }; D1E4CF5321BACBA6004D029D /* ImageDataProviderCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageDataProviderCollectionViewController.swift; sourceTree = ""; }; 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 = ""; }; D1F06F3221AA4292000B1C38 /* DetailImageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailImageViewController.swift; sourceTree = ""; }; D1F06F3621AAEACF000B1C38 /* GIFViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GIFViewController.swift; sourceTree = ""; }; D1F06F3821AAF1EE000B1C38 /* IndicatorCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IndicatorCollectionViewController.swift; sourceTree = ""; }; @@ -309,6 +311,7 @@ 4BC0ED4829A6EE4F003E9CD1 /* Regression */ = { isa = PBXGroup; children = ( + D1EDF7412C9F01200017FFA5 /* Issue2295View.swift */, 4B6E1B6C28DB4E8C0023B54B /* Issue1998View.swift */, 4BC0ED4929A6EE78003E9CD1 /* Issue2035View.swift */, ); @@ -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 */, From 50fc41e3c29bdcc56d80655facea9ceeda63e1ac Mon Sep 17 00:00:00 2001 From: onevcat Date: Sat, 21 Sep 2024 22:45:25 +0900 Subject: [PATCH 3/3] Only need to apply on UIKit --- Sources/SwiftUI/KFAnimatedImage.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/SwiftUI/KFAnimatedImage.swift b/Sources/SwiftUI/KFAnimatedImage.swift index 4f199d625..7e1ed0b74 100644 --- a/Sources/SwiftUI/KFAnimatedImage.swift +++ b/Sources/SwiftUI/KFAnimatedImage.swift @@ -87,7 +87,10 @@ public struct KFAnimatedImageViewRepresenter: KFCrossPlatformViewRepresentable, @MainActor private func makeImageView() -> AnimatedImageView { let view = AnimatedImageView() + + #if !os(macOS) view.isUserInteractionEnabled = true + #endif self.context.renderConfigurations.forEach { $0(view) }