Skip to content

reset selectedPage bug #27

@biqinglin

Description

@biqinglin

In Demo ContentView File, I define: @State private var isResetGame: Bool = false, and in CustomButtonView @binding var isResetGame: Bool, see:
` struct ContentView: View {

@State var selectedPage: Int = 0
@State private var isResetGame: Bool = false
var body: some View {
    // Horizontal
    HPageView(selectedPage: $selectedPage) {
        CustomButtonView(pageIndex: 0, isResetGame: $isResetGame)
        CustomButtonView(pageIndex: 1, isResetGame: $isResetGame)
        CustomButtonView(pageIndex: 2, isResetGame: $isResetGame)
        CustomView(pageIndex: 3, isResetGame: $isResetGame)
        CustomListView(pageIndex: 4, isResetGame: $isResetGame)
        CustomView(pageIndex: 5, isResetGame: $isResetGame)
    }
    .onChange(of: isResetGame) { newValue in
        withAnimation(.easeOut(duration: 0.2)) {
            self.selectedPage = 0
        }
    }
    .edgesIgnoringSafeArea(.init(arrayLiteral: .leading, .trailing, .bottom))
}

struct CustomButtonView: View {
let pageIndex: Int

@Binding var isResetGame: Bool

var body: some View {
    VStack {
        Button(action: {
            print("Button 1 tapped")
        }, label: {
            Text("Button 1 at \(pageIndex)")
        })
        Button(action: {
            print("Button 2 tapped")
            
            if pageIndex == 1 {
                isResetGame.toggle()
            }
        }, label: {
            Text("Button 2 at \(pageIndex)")
        })
    }
}

}
`

when I touch button and reset selectedPage, it stucked

截屏2023-05-11 上午10 08 16

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions