Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // MeditationView.swift
- // ZazenTimer
- //
- // Created by Joshua Brunhuber on 15.08.19.
- // Copyright © 2019 Joshua Brunhuber. All rights reserved.
- //
- import SwiftUI
- import Combine
- struct MeditationView: View {
- @EnvironmentObject var controller: TimerController
- @State private var remainingMeditationTime: String = "-"
- var body: some View {
- VStack {
- if self.controller.navigation == .meditating {
- VStack(spacing: 100) {
- Spacer()
- Text(remainingMeditationTime).font(Font.monospacedDigit(.title)())
- Button(action: {
- self.controller.stop()
- self.controller.navigation = .timer
- self.controller.inSession = false
- }) {
- Text("Abort").foregroundColor(.primary).bold().padding()
- }
- .background(Color.primary.opacity(0.1))
- .cornerRadius(10)
- .opacity(0.3)
- Spacer()
- }
- } else if self.controller.navigation == .finished {
- FinishedView().animation(.easeIn)
- }
- }.onAppear {
- self.controller.start()
- self.controller.currentTimePublisher.map { _ in
- self.controller.decreaseRemaining()
- return self.controller.makeRemainingTimeText()
- }
- .sink { value in
- self.remainingMeditationTime = value
- }.store(in: &self.controller.connections)
- }.navigationBarBackButtonHidden(true)
- }
- }
- #if DEBUG
- struct MeditationView_Previews: PreviewProvider {
- static var previews: some View {
- let testController = TimerController()
- testController.durationPickerValue = 5
- testController.navigation = .meditating
- let view = MeditationView().environmentObject(testController)
- return view
- }
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement