The introduction of iOS 18 brought a new bug that made `KFAnimatedImage` not recognize tap gestures and become unclickable. (https://github.com/onevcat/Kingfisher/issues/2295) This commit addresses the issue with a workaround found here: https://github.com/onevcat/Kingfisher/issues/2046#issuecomment-1554068070 The workaround was suggested by the author of the library to fix a slightly different issue, but that property seems to work for our purposes. The issue is addressed by adding a `contentShape` property to usages of `KFAnimatedImage`, in order to make them clickable. A custom modifier was created to make the solution less obscure and more obvious. Furthermore, one empty tap gesture handler was removed as it was preventing other tap gesture handlers on the image carousel from being triggered on iOS 18 Testing ------- PASS Configurations: - iPhone 13 mini on iOS 18.0 - iPhone SE simulator on iOS 17.5 Damus: This commit Coverage: - Check that the following views are clickable: - Images in the carousel - Profile picture on notes - Profile picture on thread comments - Profile picture on profile page Changelog-Fixed: Fix items that became unclickable on iOS 18 Closes: https://github.com/damus-io/damus/issues/2342 Closes: https://github.com/damus-io/damus/issues/2370 Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
70 lines
2.2 KiB
Swift
70 lines
2.2 KiB
Swift
//
|
|
// CarouselImageContainerView.swift
|
|
// damus
|
|
//
|
|
// Created by William Casarin on 2023-03-23.
|
|
//
|
|
|
|
import SwiftUI
|
|
import Kingfisher
|
|
|
|
|
|
struct ImageContainerView: View {
|
|
let video_controller: VideoController
|
|
let url: MediaUrl
|
|
let settings: UserSettingsStore
|
|
|
|
@State private var image: UIImage?
|
|
@State private var showShareSheet = false
|
|
|
|
private struct ImageHandler: ImageModifier {
|
|
@Binding var handler: UIImage?
|
|
|
|
func modify(_ image: UIImage) -> UIImage {
|
|
handler = image
|
|
return image
|
|
}
|
|
}
|
|
|
|
func Img(url: URL) -> some View {
|
|
KFAnimatedImage(url)
|
|
.imageContext(.note, disable_animation: settings.disable_animation)
|
|
.configure { view in
|
|
view.framePreloadCount = 3
|
|
}
|
|
.imageModifier(ImageHandler(handler: $image))
|
|
.kfClickable()
|
|
.clipped()
|
|
.modifier(ImageContextMenuModifier(url: url, image: image, settings: settings, showShareSheet: $showShareSheet))
|
|
.sheet(isPresented: $showShareSheet) {
|
|
ShareSheet(activityItems: [url])
|
|
}
|
|
}
|
|
|
|
var body: some View {
|
|
Group {
|
|
switch url {
|
|
case .image(let url):
|
|
Img(url: url)
|
|
case .video(let url):
|
|
DamusVideoPlayer(url: url, video_size: .constant(nil), controller: video_controller, style: .full, visibility_tracking_method: .generic)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
let test_image_url = URL(string: "https://jb55.com/red-me.jpg")!
|
|
fileprivate let test_video_url = URL(string: "http://cdn.jb55.com/s/zaps-build.mp4")!
|
|
|
|
struct ImageContainerView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
Group {
|
|
ImageContainerView(video_controller: test_damus_state.video, url: .image(test_image_url), settings: test_damus_state.settings)
|
|
.previewDisplayName("Image")
|
|
ImageContainerView(video_controller: test_damus_state.video, url: .video(test_video_url), settings: test_damus_state.settings)
|
|
.previewDisplayName("Video")
|
|
}
|
|
.environmentObject(OrientationTracker())
|
|
}
|
|
}
|