Better spoiler

This commit is contained in:
Thomas Ricouard 2022-12-28 11:41:56 +01:00
parent 79a75443a2
commit 7cf233c974
1 changed files with 34 additions and 54 deletions

View File

@ -95,27 +95,31 @@ public struct StatusRowView: View {
menuButton menuButton
} }
} }
makeStatusContentView(status: status) makeStatusContentView(status: status) }
.padding(.vertical, viewModel.displaySpoiler ? 28 : 0)
.overlay {
if viewModel.displaySpoiler {
spoilerView
}
}
}
} }
} }
private func makeStatusContentView(status: AnyStatus) -> some View { private func makeStatusContentView(status: AnyStatus) -> some View {
Group { 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) Text(status.content.asSafeAttributedString)
.font(.body) .font(.body)
.environment(\.openURL, OpenURLAction { url in .environment(\.openURL, OpenURLAction { url in
routeurPath.handleStatus(status: status, url: url) routeurPath.handleStatus(status: status, url: url)
}) })
Spacer()
}
if !viewModel.isEmbed, let embed = viewModel.embededStatus { if !viewModel.isEmbed, let embed = viewModel.embededStatus {
StatusEmbededView(status: embed) StatusEmbededView(status: embed)
@ -137,6 +141,7 @@ public struct StatusRowView: View {
StatusCardView(card: card) StatusCardView(card: card)
} }
} }
}
.contentShape(Rectangle()) .contentShape(Rectangle())
.onTapGesture { .onTapGesture {
routeurPath.navigate(to: .statusDetail(id: viewModel.status.reblog?.id ?? viewModel.status.id)) 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)
}
} }