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

reset selectedPage bug #27

Open
biqinglin opened this issue May 11, 2023 · 1 comment
Open

reset selectedPage bug #27

biqinglin opened this issue May 11, 2023 · 1 comment

Comments

@biqinglin
Copy link

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
@lengyue524
Copy link

I have the same problem.

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

2 participants