PageView icon indicating copy to clipboard operation
PageView copied to clipboard

reset selectedPage bug

Open biqinglin opened this issue 1 year ago • 1 comments

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

biqinglin avatar May 11 '23 02:05 biqinglin

I have the same problem.

lengyue524 avatar Oct 08 '23 12:10 lengyue524