NCAssistantCreateNewTask.swift 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // NCAssistantCreateNewTask.swift
  3. // Nextcloud
  4. //
  5. // Created by Milen on 09.04.24.
  6. // Copyright © 2024 Marino Faggiana. All rights reserved.
  7. //
  8. import SwiftUI
  9. struct NCAssistantCreateNewTask: View {
  10. @EnvironmentObject var model: NCAssistantTask
  11. @State var text = ""
  12. @FocusState private var inFocus: Bool
  13. @Environment(\.presentationMode) var presentationMode
  14. var body: some View {
  15. VStack {
  16. Text(model.selectedType?.description ?? "")
  17. .frame(maxWidth: .infinity, alignment: .topLeading)
  18. ZStack(alignment: .topLeading) {
  19. if text.isEmpty {
  20. Text(NSLocalizedString("_input_", comment: ""))
  21. .padding(24)
  22. .foregroundStyle(.secondary)
  23. }
  24. TextEditor(text: $text)
  25. .frame(maxWidth: .infinity, alignment: .topLeading)
  26. .padding()
  27. .transparentScrolling()
  28. .background(Color(NCBrandColor.shared.textColor2).opacity(0.1))
  29. .focused($inFocus)
  30. }
  31. .background(Color(NCBrandColor.shared.textColor2).opacity(0.1))
  32. .clipShape(.rect(cornerRadius: 8))
  33. }
  34. .toolbar {
  35. Button(action: {
  36. model.scheduleTask(input: text)
  37. presentationMode.wrappedValue.dismiss()
  38. }, label: {
  39. Text(NSLocalizedString("_create_", comment: ""))
  40. })
  41. .disabled(text.isEmpty)
  42. }
  43. .navigationTitle(String(format: NSLocalizedString("_new_task_", comment: ""), model.selectedType?.name ?? ""))
  44. .navigationBarTitleDisplayMode(.inline)
  45. .padding()
  46. .onAppear {
  47. inFocus = true
  48. }
  49. }
  50. }
  51. #Preview {
  52. let model = NCAssistantTask(controller: nil)
  53. return NCAssistantCreateNewTask()
  54. .environmentObject(model)
  55. .onAppear {
  56. model.loadDummyData()
  57. }}
  58. private extension View {
  59. func transparentScrolling() -> some View {
  60. if #available(iOS 16.0, *) {
  61. return scrollContentBackground(.hidden)
  62. } else {
  63. return onAppear {
  64. UITextView.appearance().backgroundColor = .clear
  65. }
  66. }
  67. }
  68. }