ReportReasonView.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // ReportReasonView.swift
  3. // Mastodon
  4. //
  5. // Created by MainasuK on 2022-5-10.
  6. //
  7. import UIKit
  8. import SwiftUI
  9. import MastodonLocalization
  10. import MastodonSDK
  11. import MastodonAsset
  12. import MastodonCore
  13. struct ReportReasonView: View {
  14. @ObservedObject var viewModel: ReportReasonViewModel
  15. var body: some View {
  16. ScrollView(.vertical) {
  17. HStack {
  18. VStack(alignment: .leading, spacing: 8) {
  19. Text(L10n.Scene.Report.StepOne.step1Of4)
  20. .foregroundColor(Color(Asset.Colors.Label.secondary.color))
  21. .font(Font(UIFontMetrics(forTextStyle: .largeTitle).scaledFont(for: .systemFont(ofSize: 17, weight: .regular)) as CTFont))
  22. Text(viewModel.headline)
  23. .foregroundColor(Color(Asset.Colors.Label.primary.color))
  24. .font(Font(UIFontMetrics(forTextStyle: .largeTitle).scaledFont(for: .systemFont(ofSize: 28, weight: .bold)) as CTFont))
  25. Text(L10n.Scene.Report.StepOne.selectTheBestMatch)
  26. .foregroundColor(Color(Asset.Colors.Label.secondary.color))
  27. .font(Font(UIFontMetrics(forTextStyle: .largeTitle).scaledFont(for: .systemFont(ofSize: 17, weight: .regular)) as CTFont))
  28. }
  29. Spacer()
  30. }
  31. .padding()
  32. VStack(spacing: 16) {
  33. if let serverRules = viewModel.serverRules {
  34. ForEach(ReportReasonViewModel.Reason.allCases, id: \.self) { reason in
  35. switch reason {
  36. case .violateRule where serverRules.isEmpty:
  37. EmptyView()
  38. default:
  39. ReportReasonRowView(reason: reason, isSelect: reason == viewModel.selectReason)
  40. .contentShape(Rectangle())
  41. .onTapGesture {
  42. viewModel.selectReason = reason
  43. }
  44. }
  45. }
  46. } else {
  47. ProgressView()
  48. }
  49. }
  50. .padding()
  51. .transition(.opacity)
  52. .animation(.easeInOut)
  53. Spacer()
  54. .frame(minHeight: viewModel.bottomPaddingHeight)
  55. }
  56. .background(
  57. Color(viewModel.backgroundColor)
  58. )
  59. }
  60. }
  61. struct ReportReasonRowView: View {
  62. var reason: ReportReasonViewModel.Reason
  63. var isSelect: Bool
  64. var body: some View {
  65. HStack(spacing: 14) {
  66. Image(systemName: isSelect ? "checkmark.circle.fill" : "circle")
  67. .resizable()
  68. .frame(width: 28, height: 28, alignment: .center)
  69. VStack(alignment: .leading, spacing: 4) {
  70. Text(reason.title)
  71. .foregroundColor(Color(Asset.Colors.Label.primary.color))
  72. .font(.headline)
  73. Text(reason.subtitle)
  74. .font(.subheadline)
  75. .foregroundColor(Color(Asset.Colors.Label.secondary.color))
  76. }
  77. Spacer()
  78. }
  79. }
  80. }
  81. #if DEBUG
  82. struct ReportReasonView_Previews: PreviewProvider {
  83. static var previews: some View {
  84. Group {
  85. NavigationView {
  86. ReportReasonView(viewModel: ReportReasonViewModel(context: .shared))
  87. .navigationBarTitle(Text(""))
  88. .navigationBarTitleDisplayMode(.inline)
  89. }
  90. NavigationView {
  91. ReportReasonView(viewModel: ReportReasonViewModel(context: .shared))
  92. .navigationBarTitle(Text(""))
  93. .navigationBarTitleDisplayMode(.inline)
  94. }
  95. .preferredColorScheme(.dark)
  96. }
  97. }
  98. }
  99. #endif