2023-01-09 14:48:41 +01:00
|
|
|
//
|
|
|
|
// https://mczachurski.dev
|
|
|
|
// Copyright © 2023 Marcin Czachurski and the repository contributors.
|
2023-03-28 10:35:38 +02:00
|
|
|
// Licensed under the Apache License 2.0.
|
2023-01-09 14:48:41 +01:00
|
|
|
//
|
2023-04-01 12:10:59 +02:00
|
|
|
|
2023-01-09 14:48:41 +01:00
|
|
|
import SwiftUI
|
|
|
|
|
2023-03-29 09:35:01 +02:00
|
|
|
struct ContentWarning<Content: View, Blurred: View>: View {
|
2023-01-09 14:48:41 +01:00
|
|
|
private let spoilerText: String?
|
2023-03-29 09:35:01 +02:00
|
|
|
private let content: () -> Content
|
|
|
|
private let blurred: () -> Blurred
|
2023-04-01 12:10:59 +02:00
|
|
|
|
2023-01-09 14:48:41 +01:00
|
|
|
@State private var showSensitive = false
|
2023-04-01 12:10:59 +02:00
|
|
|
|
2023-03-29 09:35:01 +02:00
|
|
|
init(spoilerText: String?,
|
|
|
|
@ViewBuilder content: @escaping () -> Content,
|
|
|
|
@ViewBuilder blurred: @escaping () -> Blurred) {
|
|
|
|
|
2023-01-09 14:48:41 +01:00
|
|
|
self.spoilerText = spoilerText
|
2023-03-29 09:35:01 +02:00
|
|
|
self.content = content
|
|
|
|
self.blurred = blurred
|
2023-01-09 14:48:41 +01:00
|
|
|
}
|
2023-04-01 12:10:59 +02:00
|
|
|
|
2023-01-09 14:48:41 +01:00
|
|
|
var body: some View {
|
|
|
|
if self.showSensitive {
|
|
|
|
ZStack {
|
2023-03-29 09:35:01 +02:00
|
|
|
content()
|
2023-01-09 14:48:41 +01:00
|
|
|
.transition(.opacity)
|
2023-03-29 09:35:01 +02:00
|
|
|
|
2023-01-09 14:48:41 +01:00
|
|
|
VStack(alignment: .trailing) {
|
|
|
|
HStack(alignment: .top) {
|
|
|
|
Spacer()
|
|
|
|
Button {
|
|
|
|
withAnimation {
|
|
|
|
self.showSensitive = false
|
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
Image(systemName: "eye.slash")
|
|
|
|
.font(.title2)
|
|
|
|
.shadow(color: Color.systemBackground, radius: 0.3)
|
2023-03-29 09:35:01 +02:00
|
|
|
.padding()
|
|
|
|
}
|
2023-01-09 14:48:41 +01:00
|
|
|
}
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
.foregroundColor(.mainTextColor)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ZStack {
|
2023-03-29 09:35:01 +02:00
|
|
|
self.blurred()
|
2023-04-01 12:10:59 +02:00
|
|
|
|
2023-01-09 14:48:41 +01:00
|
|
|
VStack(alignment: .center) {
|
|
|
|
Spacer()
|
|
|
|
Image(systemName: "eye.slash.fill")
|
|
|
|
.font(.title2)
|
|
|
|
.shadow(color: Color.systemBackground, radius: 0.3)
|
2023-03-13 13:53:36 +01:00
|
|
|
Text("global.title.contentWarning", comment: "Sensitive content")
|
2023-01-09 14:48:41 +01:00
|
|
|
.font(.title2)
|
|
|
|
.shadow(color: Color.systemBackground, radius: 0.3)
|
|
|
|
if let spoilerText {
|
|
|
|
Text(spoilerText)
|
|
|
|
.font(.body)
|
|
|
|
.multilineTextAlignment(.center)
|
|
|
|
.shadow(color: Color.systemBackground, radius: 0.3)
|
|
|
|
}
|
|
|
|
Button {
|
|
|
|
withAnimation {
|
|
|
|
self.showSensitive = true
|
|
|
|
}
|
|
|
|
} label: {
|
2023-03-13 13:53:36 +01:00
|
|
|
Text("global.title.seePost", comment: "See post")
|
2023-01-09 14:48:41 +01:00
|
|
|
.shadow(color: Color.systemBackground, radius: 0.3)
|
|
|
|
}
|
|
|
|
.buttonStyle(.bordered)
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
.foregroundColor(.mainTextColor)
|
|
|
|
}
|
|
|
|
.transition(.opacity)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|