2024-07-03 22:42:13 +01:00
|
|
|
//
|
|
|
|
// ViewModifiers.swift
|
|
|
|
// SimpleX (iOS)
|
|
|
|
//
|
|
|
|
// Created by Avently on 12.06.2024.
|
|
|
|
// Copyright © 2024 SimpleX Chat. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
extension View {
|
ios: fix XCode 16 regressions (tap not working on files, quotes, images, voice messages, etc.), open link previews on tap (#5880)
* ios: fix XCode 16 regressions (tap not working on files, quotes, images, voice messages, etc.), open link previews on tap
* fix voice recording
* fix video, accepting calls from chat, preference toggles in chat
* WIP message and meta
* handle links in attributed strings
* custom attribute for links to prevent race conditions with default tap handler
2025-05-10 14:37:45 +01:00
|
|
|
@inline(__always)
|
2024-08-04 22:24:08 +01:00
|
|
|
@ViewBuilder func `if`<Content: View>(_ condition: Bool, transform: (Self) -> Content) -> some View {
|
|
|
|
if condition {
|
2024-07-03 22:42:13 +01:00
|
|
|
transform(self)
|
|
|
|
} else {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-07-26 14:38:22 +07:00
|
|
|
|
|
|
|
extension Notification.Name {
|
|
|
|
static let chatViewWillBeginScrolling = Notification.Name("chatWillBeginScrolling")
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PrivacyBlur: ViewModifier {
|
|
|
|
var enabled: Bool = true
|
|
|
|
@Binding var blurred: Bool
|
|
|
|
@AppStorage(DEFAULT_PRIVACY_MEDIA_BLUR_RADIUS) private var blurRadius: Int = 0
|
|
|
|
|
|
|
|
func body(content: Content) -> some View {
|
|
|
|
if blurRadius > 0 {
|
|
|
|
// parallel ifs are necessary here because otherwise some views flicker,
|
|
|
|
// e.g. when playing video
|
|
|
|
content
|
|
|
|
.blur(radius: blurred && enabled ? CGFloat(blurRadius) * 0.5 : 0)
|
|
|
|
.overlay {
|
|
|
|
if (blurred && enabled) {
|
|
|
|
Color.clear.contentShape(Rectangle())
|
2025-05-11 15:42:09 +01:00
|
|
|
.simultaneousGesture(TapGesture().onEnded {
|
2024-07-26 14:38:22 +07:00
|
|
|
blurred = false
|
2025-05-11 15:42:09 +01:00
|
|
|
})
|
2024-07-26 14:38:22 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.onReceive(NotificationCenter.default.publisher(for: .chatViewWillBeginScrolling)) { _ in
|
|
|
|
if !blurred {
|
|
|
|
blurred = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
content
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|