-
Notifications
You must be signed in to change notification settings - Fork 38
Open
Description
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

Metadata
Metadata
Assignees
Labels
No labels