Skip to content

Commit

Permalink
Fix rerender on view resume
Browse files Browse the repository at this point in the history
  • Loading branch information
hienquangtran committed May 17, 2024
1 parent 8ff7993 commit e7053f8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions SampleApp/SampleApp/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ enum LoadingState {
struct ContentView: View {
@Environment(\.scenePhase) var scenePhase
@StateObject private var viewModel: ContentViewModel

@State private var firstLoad = true

init(viewModel: ContentViewModel) {
_viewModel = StateObject(wrappedValue: viewModel)
}
Expand All @@ -27,7 +28,6 @@ struct ContentView: View {
VStack {
Group {
switch viewModel.state {

case .error(let errorMessage):
Group {
ErrorView(errorMessage: errorMessage)
Expand Down Expand Up @@ -73,6 +73,10 @@ struct ContentView: View {
}
}
.task {
guard firstLoad else {
return
}
firstLoad = false
do {
try await viewModel.connect()
} catch {
Expand Down

0 comments on commit e7053f8

Please sign in to comment.