From 35758f0b3cdeeee0adf11da8016cdc4d56572394 Mon Sep 17 00:00:00 2001 From: Kanta Oikawa Date: Fri, 16 Feb 2024 15:06:35 +0900 Subject: [PATCH 1/4] Use ForecastViewModel in ForecastView --- YumemiTraining/ForecastView.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/YumemiTraining/ForecastView.swift b/YumemiTraining/ForecastView.swift index 3d0ec37..1119b83 100644 --- a/YumemiTraining/ForecastView.swift +++ b/YumemiTraining/ForecastView.swift @@ -78,7 +78,6 @@ struct ForecastView: View { Text(message) } } - } } From eecb679cf4976f934d53683f4b44822d1447d03c Mon Sep 17 00:00:00 2001 From: Kanta Oikawa Date: Fri, 16 Feb 2024 21:20:20 +0900 Subject: [PATCH 2/4] Add NewView and configure fullScreenCover --- YumemiTraining.xcodeproj/project.pbxproj | 4 ++++ YumemiTraining/ForecastView.swift | 4 +++- YumemiTraining/NewView.swift | 30 ++++++++++++++++++++++++ YumemiTraining/YumemiTrainingApp.swift | 2 +- 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 YumemiTraining/NewView.swift diff --git a/YumemiTraining.xcodeproj/project.pbxproj b/YumemiTraining.xcodeproj/project.pbxproj index 64436b3..e53b1b3 100644 --- a/YumemiTraining.xcodeproj/project.pbxproj +++ b/YumemiTraining.xcodeproj/project.pbxproj @@ -18,6 +18,7 @@ F072BB632B7F49F300A8E86F /* SizePreferenceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = F072BB622B7F49F300A8E86F /* SizePreferenceKey.swift */; }; F072BB652B7F569200A8E86F /* Weather.swift in Sources */ = {isa = PBXBuildFile; fileRef = F072BB642B7F569200A8E86F /* Weather.swift */; }; F0AEFC312B85E2270090F669 /* TemperatureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0AEFC302B85E2270090F669 /* TemperatureView.swift */; }; + F072BB6B2B7F848600A8E86F /* NewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F072BB6A2B7F848600A8E86F /* NewView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -32,6 +33,7 @@ F072BB622B7F49F300A8E86F /* SizePreferenceKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SizePreferenceKey.swift; sourceTree = ""; }; F072BB642B7F569200A8E86F /* Weather.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Weather.swift; sourceTree = ""; }; F0AEFC302B85E2270090F669 /* TemperatureView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemperatureView.swift; sourceTree = ""; }; + F072BB6A2B7F848600A8E86F /* NewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -66,6 +68,7 @@ isa = PBXGroup; children = ( F072BB492B7F09D400A8E86F /* YumemiTrainingApp.swift */, + F072BB6A2B7F848600A8E86F /* NewView.swift */, F072BB4B2B7F09D400A8E86F /* ForecastView.swift */, F0AEFC302B85E2270090F669 /* TemperatureView.swift */, F072BB602B7F496500A8E86F /* View+.swift */, @@ -167,6 +170,7 @@ F072BB5D2B7F2C9300A8E86F /* WeatherCondition.swift in Sources */, F072BB5B2B7F2B9600A8E86F /* ForecastViewModel.swift in Sources */, F072BB4C2B7F09D400A8E86F /* ForecastView.swift in Sources */, + F072BB6B2B7F848600A8E86F /* NewView.swift in Sources */, F072BB4A2B7F09D400A8E86F /* YumemiTrainingApp.swift in Sources */, F0AEFC312B85E2270090F669 /* TemperatureView.swift in Sources */, F072BB632B7F49F300A8E86F /* SizePreferenceKey.swift in Sources */, diff --git a/YumemiTraining/ForecastView.swift b/YumemiTraining/ForecastView.swift index 1119b83..685699f 100644 --- a/YumemiTraining/ForecastView.swift +++ b/YumemiTraining/ForecastView.swift @@ -8,6 +8,7 @@ import SwiftUI struct ForecastView: View { + @Environment(\.dismiss) var dismiss @StateObject var viewModel: ViewModel @State private var buttonsSize: CGSize = .zero @@ -37,7 +38,8 @@ struct ForecastView: View { HStack(spacing: 0) { Button { - // TODO: Close Action + // Close Action + self.dismiss() } label: { Text("Close") } diff --git a/YumemiTraining/NewView.swift b/YumemiTraining/NewView.swift new file mode 100644 index 0000000..72252f8 --- /dev/null +++ b/YumemiTraining/NewView.swift @@ -0,0 +1,30 @@ +// +// NewView.swift +// YumemiTraining +// +// Created by 及川 寛太 on 2024/02/16. +// + +import SwiftUI + +struct NewView: View { + @State var isPresented: Bool = false + + var body: some View { + EmptyView() + .onAppear { + self.isPresented = true + } + .fullScreenCover(isPresented: $isPresented) { + self.isPresented = true + } content: { + ForecastView( + viewModel: ForecastViewModelImpl() + ) + } + } +} + +#Preview { + NewView() +} diff --git a/YumemiTraining/YumemiTrainingApp.swift b/YumemiTraining/YumemiTrainingApp.swift index 9fb7a7a..93ca2c2 100644 --- a/YumemiTraining/YumemiTrainingApp.swift +++ b/YumemiTraining/YumemiTrainingApp.swift @@ -11,7 +11,7 @@ import SwiftUI struct YumemiTrainingApp: App { var body: some Scene { WindowGroup { - ForecastView(viewModel: ForecastViewModelImpl()) + NewView() } } } From 7fe5509e95cb3dfc618ac4fdf090ed5713e2858a Mon Sep 17 00:00:00 2001 From: Kanta Oikawa Date: Fri, 16 Feb 2024 21:39:51 +0900 Subject: [PATCH 3/4] Update to use onDismiss action to onDisappear action --- YumemiTraining/NewView.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/YumemiTraining/NewView.swift b/YumemiTraining/NewView.swift index 72252f8..b0306da 100644 --- a/YumemiTraining/NewView.swift +++ b/YumemiTraining/NewView.swift @@ -16,11 +16,12 @@ struct NewView: View { self.isPresented = true } .fullScreenCover(isPresented: $isPresented) { - self.isPresented = true - } content: { ForecastView( viewModel: ForecastViewModelImpl() ) + .onDisappear { + self.isPresented = true + } } } } From 22bdde3702c2880c2da99b18856d73d3b4eabd65 Mon Sep 17 00:00:00 2001 From: Kanta Oikawa Date: Wed, 21 Feb 2024 17:06:53 +0900 Subject: [PATCH 4/4] Remove unused property from protocol --- YumemiTraining/ForecastViewModel.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/YumemiTraining/ForecastViewModel.swift b/YumemiTraining/ForecastViewModel.swift index fcd9e4c..aea1648 100644 --- a/YumemiTraining/ForecastViewModel.swift +++ b/YumemiTraining/ForecastViewModel.swift @@ -11,7 +11,6 @@ import YumemiWeather @MainActor protocol ForecastViewModel: ObservableObject { var weather: Weather? { get } - var weatherCondition: WeatherCondition? { get } var alertMessage: String? { get } var isAlertPresented: Bool { get set }