From f2b7a3d0d836af9422bd5aa668e0f9306dc15589 Mon Sep 17 00:00:00 2001 From: liseul Date: Fri, 26 May 2023 01:47:32 +0900 Subject: [PATCH 1/2] Add SettingLayout --- Nav.xcodeproj/project.pbxproj | 12 +++---- Nav/ContentView.swift | 4 +-- Nav/View/SettingView.swift | 68 +++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 Nav/View/SettingView.swift diff --git a/Nav.xcodeproj/project.pbxproj b/Nav.xcodeproj/project.pbxproj index dcecd29..bfbffcd 100644 --- a/Nav.xcodeproj/project.pbxproj +++ b/Nav.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 11756B8F2A1FC5D000FC8C43 /* SettingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11756B8E2A1FC5D000FC8C43 /* SettingView.swift */; }; 262C17BE290CDF6900450E54 /* PinCreationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 262C17BD290CDF6900450E54 /* PinCreationView.swift */; }; 262C17C0290D06F700450E54 /* Color+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 262C17BF290D06F700450E54 /* Color+.swift */; }; 262C17C2290D090C00450E54 /* Font+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 262C17C1290D090C00450E54 /* Font+.swift */; }; @@ -27,6 +28,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 11756B8E2A1FC5D000FC8C43 /* SettingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingView.swift; sourceTree = ""; }; 262C17BD290CDF6900450E54 /* PinCreationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PinCreationView.swift; sourceTree = ""; }; 262C17BF290D06F700450E54 /* Color+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Color+.swift"; sourceTree = ""; }; 262C17C1290D090C00450E54 /* Font+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Font+.swift"; sourceTree = ""; }; @@ -126,6 +128,7 @@ 262C17BD290CDF6900450E54 /* PinCreationView.swift */, FD3389192917B81E00C4AB98 /* ListView.swift */, DCE7EBD02A172C9000644745 /* SearchBar.swift */, + 11756B8E2A1FC5D000FC8C43 /* SettingView.swift */, ); path = View; sourceTree = ""; @@ -146,14 +149,6 @@ path = Extension; sourceTree = ""; }; - 26FE54E62949B90100B4E0E9 /* Data */ = { - isa = PBXGroup; - children = ( - FDFD7A642928993A001BE945 /* MockData.json */, - ); - path = Data; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -229,6 +224,7 @@ 262C17C2290D090C00450E54 /* Font+.swift in Sources */, 262C17C6290E385E00450E54 /* Text+.swift in Sources */, 262C17C0290D06F700450E54 /* Color+.swift in Sources */, + 11756B8F2A1FC5D000FC8C43 /* SettingView.swift in Sources */, FDFD7A6129289926001BE945 /* Bundle+Ext.swift in Sources */, 262C17CE290E9D4500450E54 /* Image+.swift in Sources */, 26A1501929083B7B00BC7355 /* MapView.swift in Sources */, diff --git a/Nav/ContentView.swift b/Nav/ContentView.swift index e85df69..93aa74c 100644 --- a/Nav/ContentView.swift +++ b/Nav/ContentView.swift @@ -20,9 +20,9 @@ struct ContentView: View { Image(systemName: "list.bullet") } - PinCreationView() + SettingView() .tabItem { - Image(systemName: "plus") + Image(systemName: "gearshape") } } } diff --git a/Nav/View/SettingView.swift b/Nav/View/SettingView.swift new file mode 100644 index 0000000..badfd51 --- /dev/null +++ b/Nav/View/SettingView.swift @@ -0,0 +1,68 @@ +// +// Setting.swift +// Nav +// +// Created by Seulki Lee on 2023/04/21. +// + +import SwiftUI + +struct SettingView: View { + @State private var isApiModalPresented = false + @State private var isVersionAlert = false + @State private var isLogoutAlert = false + @State private var isResetAlert = false + + var body: some View { + NavigationView { + Form{ + Section { + Button(action: { + self.isApiModalPresented = true + }) { + Text("오픈 API") + } + .font(.subheadline) + .foregroundColor(.black) + .sheet(isPresented: $isApiModalPresented) { + // 오픈 API 모달 뷰 구현 + Text("오픈 API 모달 팝업") + } + + Button(action: { + self.isVersionAlert = true + }) { + Text("버전 정보") + } + .font(.subheadline) + .foregroundColor(.black) + .alert(isPresented: $isVersionAlert) { + Alert(title: Text("버전 정보"), message: Text("현재 버전: 1.0"), dismissButton: .default(Text("확인"))) + } + + Button(action: { + self.isResetAlert = true + }) { + Text("초기화") + } + .font(.subheadline) + .foregroundColor(.black) + .alert(isPresented: $isResetAlert) { + Alert(title: Text("초기화"), message: Text("초기화 하시겠습니까?"), primaryButton: .destructive(Text("초기화"), action: { + // 초기화 로직 구현 + }), secondaryButton: .cancel(Text("취소"))) + } + } + + } + } + + } +} + +struct SettingView_Previews: PreviewProvider { + static var previews: some View { + SettingView() + } +} + From d62de0ebddd46eac5591f137b5d42cc7f91bdb81 Mon Sep 17 00:00:00 2001 From: liseul Date: Thu, 8 Jun 2023 18:19:53 +0900 Subject: [PATCH 2/2] =?UTF-8?q?SettingView=20=EC=BD=94=EB=93=9C=EB=B6=84?= =?UTF-8?q?=EB=A6=AC=20=EB=B0=8Fclss=20AlertManager=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Nav.xcodeproj/project.pbxproj | 12 +++++++++++ Nav/Common/Common.swift | 22 +++++++++++++++++++ Nav/View/SettingView.swift | 40 +++++++++++++++++------------------ 3 files changed, 53 insertions(+), 21 deletions(-) create mode 100644 Nav/Common/Common.swift diff --git a/Nav.xcodeproj/project.pbxproj b/Nav.xcodeproj/project.pbxproj index bfbffcd..bffab1b 100644 --- a/Nav.xcodeproj/project.pbxproj +++ b/Nav.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 11756B8F2A1FC5D000FC8C43 /* SettingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11756B8E2A1FC5D000FC8C43 /* SettingView.swift */; }; + 11A6F3992A31BFD600E36EBD /* Common.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11A6F3982A31BFD600E36EBD /* Common.swift */; }; 262C17BE290CDF6900450E54 /* PinCreationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 262C17BD290CDF6900450E54 /* PinCreationView.swift */; }; 262C17C0290D06F700450E54 /* Color+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 262C17BF290D06F700450E54 /* Color+.swift */; }; 262C17C2290D090C00450E54 /* Font+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 262C17C1290D090C00450E54 /* Font+.swift */; }; @@ -29,6 +30,7 @@ /* Begin PBXFileReference section */ 11756B8E2A1FC5D000FC8C43 /* SettingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingView.swift; sourceTree = ""; }; + 11A6F3982A31BFD600E36EBD /* Common.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Common.swift; sourceTree = ""; }; 262C17BD290CDF6900450E54 /* PinCreationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PinCreationView.swift; sourceTree = ""; }; 262C17BF290D06F700450E54 /* Color+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Color+.swift"; sourceTree = ""; }; 262C17C1290D090C00450E54 /* Font+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Font+.swift"; sourceTree = ""; }; @@ -60,6 +62,14 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 11A6F3972A31BFC300E36EBD /* Common */ = { + isa = PBXGroup; + children = ( + 11A6F3982A31BFD600E36EBD /* Common.swift */, + ); + path = Common; + sourceTree = ""; + }; 26A14FFE29083A1300BC7355 = { isa = PBXGroup; children = ( @@ -81,6 +91,7 @@ children = ( 26A1500A29083A1300BC7355 /* NavApp.swift */, 26A1500C29083A1300BC7355 /* ContentView.swift */, + 11A6F3972A31BFC300E36EBD /* Common */, 26FE54E62949B90100B4E0E9 /* Data */, FD3389112917993300C4AB98 /* Extension */, FD3389102917992800C4AB98 /* Model */, @@ -219,6 +230,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 11A6F3992A31BFD600E36EBD /* Common.swift in Sources */, CE2D8D3829C59D5F00E5C104 /* ImagePicker.swift in Sources */, 26A1500D29083A1300BC7355 /* ContentView.swift in Sources */, 262C17C2290D090C00450E54 /* Font+.swift in Sources */, diff --git a/Nav/Common/Common.swift b/Nav/Common/Common.swift new file mode 100644 index 0000000..143c4f8 --- /dev/null +++ b/Nav/Common/Common.swift @@ -0,0 +1,22 @@ +// +// Common.swift +// Nav +// +// Created by Seulki Lee on 2023/06/08. +// + +import Foundation +import SwiftUI + +class AlertManager: ObservableObject { + + func showAlert(title: String, message: String) -> Alert { + let alert = Alert(title: Text(title), message: Text(message), dismissButton: .default(Text("확인"))) + return alert + } + + func showResetAlert(title: String, message: String, resetAction: @escaping () -> Void) -> Alert { + let alert = Alert(title: Text(title), message: Text(message), primaryButton: .destructive(Text("확인"), action: resetAction), secondaryButton: .cancel(Text("취소"))) + return alert + } +} diff --git a/Nav/View/SettingView.swift b/Nav/View/SettingView.swift index badfd51..65f687c 100644 --- a/Nav/View/SettingView.swift +++ b/Nav/View/SettingView.swift @@ -8,55 +8,41 @@ import SwiftUI struct SettingView: View { + @StateObject private var alertManager = AlertManager() @State private var isApiModalPresented = false @State private var isVersionAlert = false - @State private var isLogoutAlert = false @State private var isResetAlert = false var body: some View { NavigationView { Form{ Section { - Button(action: { + SettingButton(title: "오픈 API") { self.isApiModalPresented = true - }) { - Text("오픈 API") } - .font(.subheadline) - .foregroundColor(.black) .sheet(isPresented: $isApiModalPresented) { // 오픈 API 모달 뷰 구현 Text("오픈 API 모달 팝업") } - Button(action: { + SettingButton(title: "버전 정보") { self.isVersionAlert = true - }) { - Text("버전 정보") } - .font(.subheadline) - .foregroundColor(.black) .alert(isPresented: $isVersionAlert) { - Alert(title: Text("버전 정보"), message: Text("현재 버전: 1.0"), dismissButton: .default(Text("확인"))) + alertManager.showAlert(title: "버전정보", message: "현재 버전: v1.0") } - Button(action: { + SettingButton(title: "초기화") { self.isResetAlert = true - }) { - Text("초기화") } - .font(.subheadline) - .foregroundColor(.black) .alert(isPresented: $isResetAlert) { - Alert(title: Text("초기화"), message: Text("초기화 하시겠습니까?"), primaryButton: .destructive(Text("초기화"), action: { + alertManager.showResetAlert(title: "초기화", message: "초기화 하시겠습니까?") { // 초기화 로직 구현 - }), secondaryButton: .cancel(Text("취소"))) + } } } - } } - } } @@ -66,3 +52,15 @@ struct SettingView_Previews: PreviewProvider { } } +struct SettingButton: View { + let title: String + let action: () -> Void + + var body: some View { + Button(action: action) { + Text(title) + } + .font(.subheadline) + .foregroundColor(.black) + } +}