Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. //
  2. // MeditationView.swift
  3. // ZazenTimer
  4. //
  5. // Created by Joshua Brunhuber on 15.08.19.
  6. // Copyright © 2019 Joshua Brunhuber. All rights reserved.
  7. //
  8.  
  9. import SwiftUI
  10. import Combine
  11.  
  12. struct MeditationView: View {
  13.  
  14. @EnvironmentObject var controller: TimerController
  15.  
  16. @State private var remainingMeditationTime: String = "-"
  17.  
  18. var body: some View {
  19.  
  20. VStack {
  21. if self.controller.navigation == .meditating {
  22. VStack(spacing: 100) {
  23. Spacer()
  24. Text(remainingMeditationTime).font(Font.monospacedDigit(.title)())
  25.  
  26. Button(action: {
  27. self.controller.stop()
  28. self.controller.navigation = .timer
  29. self.controller.inSession = false
  30. }) {
  31. Text("Abort").foregroundColor(.primary).bold().padding()
  32. }
  33. .background(Color.primary.opacity(0.1))
  34. .cornerRadius(10)
  35. .opacity(0.3)
  36. Spacer()
  37. }
  38. } else if self.controller.navigation == .finished {
  39. FinishedView().animation(.easeIn)
  40. }
  41. }.onAppear {
  42. self.controller.start()
  43.  
  44. self.controller.currentTimePublisher.map { _ in
  45.  
  46. self.controller.decreaseRemaining()
  47. return self.controller.makeRemainingTimeText()
  48. }
  49. .sink { value in
  50. self.remainingMeditationTime = value
  51. }.store(in: &self.controller.connections)
  52. }.navigationBarBackButtonHidden(true)
  53. }
  54. }
  55.  
  56. #if DEBUG
  57. struct MeditationView_Previews: PreviewProvider {
  58. static var previews: some View {
  59.  
  60. let testController = TimerController()
  61. testController.durationPickerValue = 5
  62. testController.navigation = .meditating
  63. let view = MeditationView().environmentObject(testController)
  64. return view
  65. }
  66. }
  67. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement