diff --git a/Sources/Core/View/ViewSwitcher.swift b/Sources/Core/View/ViewSwitcher.swift index 0c4a1f3..b5658a1 100644 --- a/Sources/Core/View/ViewSwitcher.swift +++ b/Sources/Core/View/ViewSwitcher.swift @@ -65,7 +65,9 @@ public struct ViewSwitcher: 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: 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 } diff --git a/Sources/Demo/ViewSwitcherDemo.swift b/Sources/Demo/ViewSwitcherDemo.swift index 84fb02b..c72c5ee 100644 --- a/Sources/Demo/ViewSwitcherDemo.swift +++ b/Sources/Demo/ViewSwitcherDemo.swift @@ -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) }