Better spoiler

This commit is contained in:
Thomas Ricouard 2022-12-28 11:41:56 +01:00
parent 79a75443a2
commit 7cf233c974

View file

@ -95,27 +95,31 @@ public struct StatusRowView: View {
menuButton
}
}
makeStatusContentView(status: status)
.padding(.vertical, viewModel.displaySpoiler ? 28 : 0)
.overlay {
if viewModel.displaySpoiler {
spoilerView
}
}
}
makeStatusContentView(status: status) }
}
}
private func makeStatusContentView(status: AnyStatus) -> some View {
Group {
HStack {
if !viewModel.status.spoilerText.isEmpty {
Text(status.spoilerText)
.font(.body)
}
if viewModel.displaySpoiler {
Button {
withAnimation {
viewModel.displaySpoiler = false
}
} label: {
Text("Show more")
}
.buttonStyle(.bordered)
} else {
Text(status.content.asSafeAttributedString)
.font(.body)
.environment(\.openURL, OpenURLAction { url in
routeurPath.handleStatus(status: status, url: url)
})
Spacer()
}
if !viewModel.isEmbed, let embed = viewModel.embededStatus {
StatusEmbededView(status: embed)
@ -137,6 +141,7 @@ public struct StatusRowView: View {
StatusCardView(card: card)
}
}
}
.contentShape(Rectangle())
.onTapGesture {
routeurPath.navigate(to: .statusDetail(id: viewModel.status.reblog?.id ?? viewModel.status.id))
@ -218,29 +223,4 @@ public struct StatusRowView: View {
}
}
}
private var spoilerView: some View {
HStack {
Spacer()
VStack {
Spacer()
Text(viewModel.status.reblog?.spoilerText ?? viewModel.status.spoilerText)
.font(.callout)
Button {
withAnimation {
viewModel.displaySpoiler = false
}
} label: {
Text("See more")
}
.buttonStyle(.bordered)
Spacer()
}
Spacer()
}
.background(.ultraThinMaterial)
.transition(.opacity)
.cornerRadius(4)
}
}