Fix view switcher not updating selection
Some checks failed
Deploy Docs / publish (push) Successful in 19m56s
SwiftLint / SwiftLint (push) Failing after 1s

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,
type: Data.Type
) where Data: ViewRenderData {
updateSwitcher(switcher: storage)
if updateProperties {
updateSwitcher(switcher: storage)
}
}
/// 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
)
}
if (switcher.previousState as? Self)?.selectedElement.title != selectedElement.title {
let stack = adw_view_switcher_get_stack(switcher.opaquePointer)
adw_view_stack_set_visible_child_name(stack, selectedElement.title)
}
let adwStack = adw_view_switcher_get_stack(switcher.opaquePointer)
adw_view_stack_set_visible_child_name(adwStack, selectedElement.title)
switcher.previousState = self
}

View File

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