forked from aparoksha/adwaita-swift
Fix view switcher not updating selection
This commit is contained in:
parent
4913c0a382
commit
8c50494c74
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user