@@ -14,8 +14,8 @@ public struct PokitSelect<Item: PokitSelectItem>: View {
1414 private var selectedItem : Item ?
1515 @State
1616 private var state : PokitSelect . SelectState
17- @State
18- private var showSheet : Bool = false
17+ @Binding
18+ private var isPresented : Bool
1919
2020 private let label : String
2121 private let list : [ Item ] ?
@@ -24,13 +24,15 @@ public struct PokitSelect<Item: PokitSelectItem>: View {
2424
2525 public init (
2626 selectedItem: Binding < Item ? > = . constant( nil ) ,
27+ isPresented: Binding < Bool > ,
2728 state: PokitSelect . SelectState = . default,
2829 label: String ,
2930 list: [ Item ] ? ,
3031 action: @escaping ( Item ) -> Void ,
3132 addAction: ( ( ) -> Void ) ?
3233 ) {
3334 self . _selectedItem = selectedItem
35+ self . _isPresented = isPresented
3436 if selectedItem. wrappedValue != nil {
3537 self . state = . input
3638 } else {
@@ -49,7 +51,7 @@ public struct PokitSelect<Item: PokitSelectItem>: View {
4951 partSelectButton
5052 }
5153 . onChange ( of: selectedItem) { onChangedSeletedItem ( $0) }
52- . sheet ( isPresented: $showSheet ) {
54+ . sheet ( isPresented: $isPresented ) {
5355 PokitSelectSheet (
5456 list: list,
5557 itemSelected: { item in
@@ -104,22 +106,22 @@ public struct PokitSelect<Item: PokitSelectItem>: View {
104106 }
105107
106108 private func partSelectButtonTapped( ) {
107- showSheet = true
109+ isPresented = true
108110 }
109111
110112 private func listCellTapped( _ item: Item ) {
111113 withAnimation ( . pokitDissolve) {
112114 self . selectedItem = item
113115 }
114- showSheet = false
116+ isPresented = false
115117 }
116118
117119 private func onChangedSeletedItem( _ newValue: Item ? ) {
118120 state = newValue != nil ? . input : . default
119121 }
120122
121123 private func listDismiss( ) {
122- showSheet = false
124+ isPresented = false
123125 }
124126}
125127
0 commit comments