@@ -44,23 +44,31 @@ struct ASItemModifier<SelectionValue: Hashable, S: View>: ViewModifier {
4444 var selectArea : CGFloat
4545 var select : S ? = nil
4646
47+ private var selection : Binding < SelectionValue > { Binding (
48+ get: { self . selectionValue. selection } ,
49+ set: {
50+ self . selectionValue. onTapReceive ? ( $0)
51+ self . selectionValue. selection = $0
52+ } )
53+ }
54+
4755 var normalSize : CGSize {
4856 if positionValue. constant. axisMode == . horizontal {
49- return CGSize ( width: positionValue. getNormalArea ( selectionValue . selection) ,
57+ return CGSize ( width: positionValue. getNormalArea ( self . selection. wrappedValue ) ,
5058 height: positionValue. size. height)
5159 } else {
5260 return CGSize ( width: positionValue. size. width,
53- height: positionValue. getNormalArea ( selectionValue . selection) )
61+ height: positionValue. getNormalArea ( self . selection. wrappedValue ) )
5462 }
5563 }
5664
5765 var selectSize : CGSize {
5866 if positionValue. constant. axisMode == . horizontal {
59- return CGSize ( width: positionValue. getSelectArea ( selectionValue . selection) ,
67+ return CGSize ( width: positionValue. getSelectArea ( self . selection. wrappedValue ) ,
6068 height: positionValue. size. height)
6169 } else {
6270 return CGSize ( width: positionValue. size. width,
63- height: positionValue. getSelectArea ( selectionValue . selection) )
71+ height: positionValue. getSelectArea ( self . selection. wrappedValue ) )
6472 }
6573 }
6674
@@ -85,7 +93,7 @@ struct ASItemModifier<SelectionValue: Hashable, S: View>: ViewModifier {
8593 ZStack {
8694 if positionValue. isHasStyle {
8795 Button {
88- self . selectionValue . selection = tag
96+ self . selection. wrappedValue = tag
8997 self . stateValue. isInitialRun = false
9098 if positionValue. constant. isActivatedVibration { vibration ( ) }
9199 } label: {
@@ -100,19 +108,19 @@ struct ASItemModifier<SelectionValue: Hashable, S: View>: ViewModifier {
100108 } else {
101109 ZStack {
102110 Button {
103- self . selectionValue . selection = tag
111+ self . selection. wrappedValue = tag
104112 self . stateValue. isInitialRun = false
105113 if positionValue. constant. isActivatedVibration { vibration ( ) }
106114 } label: {
107115 content
108116 }
109117 . contentShape ( Rectangle ( ) )
110118 . buttonStyle ( . plain)
111- . opacity ( tag != selectionValue . selection ? 1 : 0 )
119+ . opacity ( tag != self . selection. wrappedValue ? 1 : 0 )
112120
113121 select?
114122 . contentShape ( Rectangle ( ) )
115- . opacity ( tag == selectionValue . selection ? 1 : 0 )
123+ . opacity ( tag == self . selection. wrappedValue ? 1 : 0 )
116124
117125 }
118126 . frame ( width: getItemSize ( ) . width, height: getItemSize ( ) . height)
@@ -136,7 +144,7 @@ struct ASItemModifier<SelectionValue: Hashable, S: View>: ViewModifier {
136144 . onAppear {
137145 self . setupStateValue ( )
138146 }
139- . onChange ( of: self . selectionValue . selection) { newValue in
147+ . onChange ( of: self . selection. wrappedValue ) { newValue in
140148 self . setupStateValue ( )
141149 }
142150 . onChange ( of: selectArea) { newValue in
@@ -147,15 +155,15 @@ struct ASItemModifier<SelectionValue: Hashable, S: View>: ViewModifier {
147155
148156 private func getItemSize( ) -> CGSize {
149157 if positionValue. constant. axisMode == . horizontal {
150- return CGSize ( width: tag == selectionValue . selection ? selectSize. width : normalSize. width, height: positionValue. size. height)
158+ return CGSize ( width: tag == self . selection. wrappedValue ? selectSize. width : normalSize. width, height: positionValue. size. height)
151159 } else {
152- return CGSize ( width: positionValue. size. width, height: tag == selectionValue . selection ? selectSize. height : normalSize. height)
160+ return CGSize ( width: positionValue. size. width, height: tag == self . selection. wrappedValue ? selectSize. height : normalSize. height)
153161 }
154162 }
155163
156164 private func isShowDivideLine( ) -> Bool {
157165 let currentIndex = positionValue. indexOfTag ( tag)
158- let selectionIndex = positionValue. indexOfTag ( selectionValue . selection)
166+ let selectionIndex = positionValue. indexOfTag ( self . selection. wrappedValue )
159167 if positionValue. constant. divideLine. isShowSelectionLine {
160168 return currentIndex != 0
161169 } else {
@@ -165,14 +173,14 @@ struct ASItemModifier<SelectionValue: Hashable, S: View>: ViewModifier {
165173
166174 private func getItemView( _ content: Content ) -> some View {
167175 ZStack {
168- if tag == selectionValue . selection {
176+ if tag == self . selection. wrappedValue {
169177 ZStack {
170178 if let select = select {
171179 select
172180 . onAppear {
173181 DispatchQueue . main. async {
174182 stateValue. previousIndex = stateValue. selectionIndex
175- stateValue. previousFrame = positionValue. getSelectFrame ( self . selectionValue . selection, selectionIndex: stateValue. selectionIndex)
183+ stateValue. previousFrame = positionValue. getSelectFrame ( self . selection. wrappedValue , selectionIndex: stateValue. selectionIndex)
176184
177185 if positionValue. constant. axisMode == . horizontal {
178186 stateValue. otherSize = CGSize ( width: normalSize. width, height: positionValue. size. height)
@@ -198,11 +206,11 @@ struct ASItemModifier<SelectionValue: Hashable, S: View>: ViewModifier {
198206 }
199207
200208 private func setupStateValue( ) {
201- let selectionIndex = positionValue. indexOfTag ( self . selectionValue . selection)
209+ let selectionIndex = positionValue. indexOfTag ( self . selection. wrappedValue )
202210 stateValue. constant = positionValue. constant
203211 stateValue. itemCount = positionValue. itemCount
204212 stateValue. selectionIndex = selectionIndex
205- stateValue. selectionFrame = positionValue. getSelectFrame ( self . selectionValue . selection, selectionIndex: selectionIndex)
213+ stateValue. selectionFrame = positionValue. getSelectFrame ( self . selection. wrappedValue , selectionIndex: selectionIndex)
206214 stateValue. size = positionValue. size
207215 }
208216
0 commit comments