@@ -14,7 +14,7 @@ public struct CustomizableSegmentedControl<Option: Hashable & Identifiable, Sele
1414 @Binding private var selection : Option
1515 private let options : [ Option ]
1616 private let selectionView : ( ) -> SelectionView
17- private let segmentContent : ( Option , Bool ) -> SegmentContent
17+ private let segmentContent : ( _ option : Option , _ isSelected : Bool , _ isPressed : Bool ) -> SegmentContent
1818
1919 @State private var optionIsPressed : [ Option . ID : Bool ] = [ : ]
2020
@@ -41,13 +41,12 @@ public struct CustomizableSegmentedControl<Option: Hashable & Identifiable, Sele
4141 selection: Binding < Option > ,
4242 options: [ Option ] ,
4343 selectionView: @escaping ( ) -> SelectionView ,
44- @ViewBuilder segmentContent: @escaping ( Option , Bool ) -> SegmentContent
44+ @ViewBuilder segmentContent: @escaping ( _ option : Option , _ isSelected : Bool , _ isPressed : Bool ) -> SegmentContent
4545 ) {
4646 self . _selection = selection
4747 self . options = options
4848 self . selectionView = selectionView
4949 self . segmentContent = segmentContent
50- self . optionIsPressed = Dictionary ( uniqueKeysWithValues: options. lazy. map { ( $0. id, false ) } )
5150 }
5251
5352 // MARK: - UI
@@ -56,17 +55,14 @@ public struct CustomizableSegmentedControl<Option: Hashable & Identifiable, Sele
5655 HStack ( spacing: interSegmentSpacing) {
5756 ForEach ( Array ( zip ( options. indices, options) ) , id: \. 1 . id) { index, option in
5857 Segment (
59- content: segmentContent ( option, optionIsPressed [ option. id, default: false ] ) ,
58+ content: segmentContent ( option, option . id == selection . id , optionIsPressed [ option. id, default: false ] ) ,
6059 selectionView: selectionView ( ) ,
6160 isSelected: selection == option,
6261 animation: slidingAnimation,
6362 contentBlendMode: contentStyle. contentBlendMode,
6463 firstLevelOverlayBlendMode: contentStyle. firstLevelOverlayBlendMode,
6564 highestLevelOverlayBlendMode: contentStyle. highestLevelOverlayBlendMode,
66- isPressed: . init(
67- get: { optionIsPressed [ option. id, default: false ] } ,
68- set: { optionIsPressed [ option. id] = $0 }
69- ) ,
65+ isPressed: $optionIsPressed [ option. id] ,
7066 backgroundID: buttonBackgroundID,
7167 namespaceID: namespaceID,
7268 accessibiltyValue: segmentAccessibilityValueCompletion ( index + 1 , options. count) ,
@@ -95,7 +91,7 @@ extension CustomizableSegmentedControl {
9591 let contentBlendMode : BlendMode ?
9692 let firstLevelOverlayBlendMode : BlendMode ?
9793 let highestLevelOverlayBlendMode : BlendMode ?
98- @Binding var isPressed : Bool
94+ @Binding var isPressed : Bool ?
9995 let backgroundID : String
10096 let namespaceID : Namespace . ID
10197 let accessibiltyValue : String
@@ -159,7 +155,7 @@ extension CustomizableSegmentedControl {
159155 selection: Binding < Option > ,
160156 options: [ Option ] ,
161157 selectionView: SelectionView ,
162- @ViewBuilder segmentContent: @escaping ( Option , Bool ) -> SegmentContent
158+ @ViewBuilder segmentContent: @escaping ( _ option : Option , _ isSelected : Bool , _ isPressed : Bool ) -> SegmentContent
163159 ) {
164160 self . init (
165161 selection: selection,
@@ -177,7 +173,7 @@ extension CustomizableSegmentedControl.Segment {
177173
178174 private struct SegmentButtonStyle : ButtonStyle {
179175
180- @Binding var isPressed : Bool
176+ @Binding var isPressed : Bool ?
181177
182178 func makeBody( configuration: Configuration ) -> some View {
183179 configuration. label
0 commit comments