Skip to content

Commit 88a877d

Browse files
committed
Add showLocationInfo state for improved layout adjustment and dynamic forecast text
• Introduced showLocationInfo state in ContentViewState to track whether location information is displayed, enabling more flexible UI behavior. • Adjusted the locationButton() and locationTextField() to modify showLocationInfo based on user actions, allowing the layout to dynamically adjust when showing weather or location information. • Updated padding logic in weatherInfoView to account for showLocationInfo, providing better spacing when displaying the current location’s weather forecast. • Modified forecast display to show dynamic forecast text based on the number of forecast days (e.g., “5-Day Forecast” or “3-Day Forecast”).
1 parent 56be153 commit 88a877d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Moti/Moti/Views/ContentView.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import SwiftUI
1212
class ContentViewState: ObservableObject {
1313
@Published var locationInput: String = ""
1414
@Published var showWeatherInfo: Bool = false
15+
@Published var showLocationInfo: Bool = false
1516
}
1617

1718
struct ContentView: View {
@@ -58,6 +59,7 @@ struct ContentView: View {
5859
private func locationButton() -> some View {
5960
Button(action: {
6061
withAnimation(.easeInOut(duration: 0.5)) {
62+
state.showLocationInfo = true
6163
weatherManager.clearSelectedLocation()
6264
weatherManager.fetchCurrentLocation()
6365
state.showWeatherInfo = true
@@ -71,6 +73,7 @@ struct ContentView: View {
7173

7274
private func locationTextField() -> some View {
7375
TextField("Search Location", text: $state.locationInput, onCommit: {
76+
state.showLocationInfo = false
7477
performLocationSearch()
7578
})
7679
.textFieldStyle(RoundedBorderTextFieldStyle())
@@ -137,7 +140,7 @@ struct ContentView: View {
137140
.font(.title3)
138141
.fontWeight(.medium)
139142
.foregroundColor(.primary)
140-
.padding(.top, weatherManager.forecast.count == 5 ? 30 : 130)
143+
.padding(.top, weatherManager.forecast.count == 5 ? 30 : state.showLocationInfo ? 125 : 45)
141144

142145
HStack(alignment: .top, spacing: 8) {
143146
if let iconURL = URL(string: weatherManager.currentWeatherIcon) {

Moti/Moti/Views/ForecastView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct ForecastView: View {
1212

1313
var body: some View {
1414
VStack(spacing: 8) {
15-
Text("5-Day Forecast")
15+
Text("\(forecast.count)-Day Forecast")
1616
.font(.headline)
1717
.padding(.bottom, 5)
1818

0 commit comments

Comments
 (0)