Fix view switcher not updating selection

This commit is contained in:
david-swift 2024-10-19 21:54:38 +02:00
parent 4913c0a382
commit 8c50494c74
2 changed files with 7 additions and 9 deletions

View File

@ -65,7 +65,9 @@ public struct ViewSwitcher<Element>: AdwaitaWidget where Element: ViewSwitcherOp
updateProperties: Bool, updateProperties: Bool,
type: Data.Type type: Data.Type
) where Data: ViewRenderData { ) where Data: ViewRenderData {
updateSwitcher(switcher: storage) if updateProperties {
updateSwitcher(switcher: storage)
}
} }
/// Update a view switcher's style and selection. /// Update a view switcher's style and selection.
@ -84,10 +86,8 @@ public struct ViewSwitcher<Element>: AdwaitaWidget where Element: ViewSwitcherOp
wide ? ADW_VIEW_SWITCHER_POLICY_WIDE : ADW_VIEW_SWITCHER_POLICY_NARROW wide ? ADW_VIEW_SWITCHER_POLICY_WIDE : ADW_VIEW_SWITCHER_POLICY_NARROW
) )
} }
if (switcher.previousState as? Self)?.selectedElement.title != selectedElement.title { let adwStack = adw_view_switcher_get_stack(switcher.opaquePointer)
let stack = adw_view_switcher_get_stack(switcher.opaquePointer) adw_view_stack_set_visible_child_name(adwStack, selectedElement.title)
adw_view_stack_set_visible_child_name(stack, selectedElement.title)
}
switcher.previousState = self switcher.previousState = self
} }

View File

@ -33,10 +33,8 @@ struct ViewSwitcherDemo: View {
VStack { VStack {
Text(selection.title) Text(selection.title)
.padding() .padding()
HStack { Button(bottom ? "Show Top Bar" : "Show Bottom Bar") {
Button(bottom ? "Show Top Bar" : "Show Bottom Bar") { bottom.toggle()
bottom.toggle()
}
} }
.halign(.center) .halign(.center)
} }