Untitled
unknown
swift
3 years ago
5.0 kB
3
Indexable
// // SettingsScreenView.swift // SenseCap // // Created by Doğancan Mavideniz on 13.02.2022. // import SwiftUI struct SettingsSceneView: View { @State var isClicked : Bool = false var timeDurations = ["1", "5", "10", "15", "20"] @State var selectedTimeDuration: String = "" @Environment(\.presentationMode) var mode: Binding<PresentationMode> var body: some View { ZStack{ Color.lightBlue .ignoresSafeArea() ZStack { RoundedRectangle(cornerRadius: 20) .fill(Color.white) .padding(.horizontal , 20) .padding(.vertical, -20) VStack(spacing: 30) { HStack{ Spacer() Button(action: { self.mode.wrappedValue.dismiss() }) { Image("closeButton") } } Text(TextConstants.settingsInfoText).normalText(size: 16) .multilineTextAlignment(.center) VStack(spacing: 42) { VStack(spacing:8){ ForEach(timeDurations, id: \.self) { timeDuration in VStack{ HStack{ Button(action: { self.isClicked.toggle() selectedTimeDuration = timeDuration }) { Image(timeDuration == selectedTimeDuration ? "fill" : "fill2") .resizable() .frame(width: 22, height: 22) .padding(.horizontal,10) Text("Per \(timeDuration) minutes") .modifier(TextModifier(font: Font.custom("Poppins-Regular", size: 14).weight(.regular), foregroundColor: .black)) } } .frame(width: 313, height: 43, alignment: .leading) .overlay(RoundedRectangle(cornerRadius: 10).stroke(Color.black, lineWidth: 1)) } } } Button { let content = UNMutableNotificationContent() content.title = TextConstants.notificationTitle content.subtitle = TextConstants.notificationSubtitle // Notification içeriği henüz belli olmadığından bunu yazdırdım. content.sound = UNNotificationSound.default let trigger = UNTimeIntervalNotificationTrigger(timeInterval: Double(selectedTimeDuration)!*60, repeats: true) let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger) UNUserNotificationCenter.current().add(request) self.mode.wrappedValue.dismiss() } label: { buttonContent(buttonTitle: TextConstants.confirmButtonTitle) .modifier(TextModifier(font: Font.custom("Poppins-Regular", size: 16).weight(.regular), foregroundColor: .black)) } } } .padding(.horizontal, 50) } .fixedSize(horizontal: false, vertical: true) .navigationBarHidden(true) }.onAppear { UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { success, error in if success { print("All set for Notification Perm!") } else if let error = error { print(error.localizedDescription) } } } } } struct SettingsScreenView_Previews: PreviewProvider { static var previews: some View { SettingsSceneView() } } extension SettingsSceneView { private func buttonContent(buttonTitle: String) -> some View { ZStack { RoundedRectangle(cornerRadius: 12) .frame(width: 270, height: 52, alignment: .center) .foregroundColor(Color("senseBlue")) Text(buttonTitle) .modifier(TextModifier(font: Font.system(size: 16).weight(.bold), foregroundColor: .white)) .foregroundColor(.white) } } }
Editor is loading...