Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The child view onAppear is not fired consistently with .bottomSheet but it is consistent when using .sheet. #160

Open
gjmoyer opened this issue Apr 15, 2024 · 0 comments

Comments

@gjmoyer
Copy link

gjmoyer commented Apr 15, 2024

Describe the bug
The child view onAppear is not fired consistently with .bottomSheet but it is consistent when using .sheet.

Minimal reproduce-able code

struct TabbedViewWithBottomSheet: View {
    @State var bottomSheetPosition: BottomSheetPosition = .hidden
    @State var sheetContent: any View = EmptyView()
    @State var showSheet: Bool = false
    
    var body: some View {
        TabView {
            VStack {
                Button("show1") {
                    sheetContent = ChildView1(name: "Show1 sheet1")
                    bottomSheetPosition = .relativeTop(1)
                }
                Button("show2") {
                    sheetContent = ChildView1(name: "Show2 sheet2")
                    bottomSheetPosition = .relativeTop(1)
                }
                Button("show3") {
                    sheetContent = ChildView1(name: "Show3 sheet3")
                    showSheet.toggle()
                }
                Button("show4") {
                    sheetContent = ChildView1(name: "Show4 sheet4")
                    showSheet.toggle()
                }
            }
            .bottomSheet(
                bottomSheetPosition: self.$bottomSheetPosition,
                switchablePositions: [.relativeTop(1), .hidden]
            ) {
                AnyView(sheetContent)
            }
            .enableSwipeToDismiss()
            .showCloseButton()
            .sheetWidth(BottomSheetWidth.relative(1))
            .tabItem {
                Image(systemName: "magnifyingglass")
                Text("Search")
            }
            .tag(0)
            
            Text("Lists content")
                .tabItem {
                    Image(systemName: "list.dash")
                    Text("Lists")
                }
                .tag(1)
        }
        .sheet(isPresented: $showSheet) {
            AnyView(sheetContent)
        }

    }
}

struct ChildView1: View {
    var name: String
  
    var body: some View {
        VStack {
            Text("Hello, \(self.name)!")
        }
        .onAppear {
            print("ChildView1.onAppear \(self.name)")
        }
    }
}

Expected behavior
I expect the onAppear to fire in the ChildView every time the bottom view is not hidden. If I have logic that fires in the onAppear to populate the view from an API this doesn't fire and the previous view content is shown instead.

Target version

  • Environment: iOS 17.4 simulator
  • Version: Xcode 15.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant