@@ -50,21 +50,30 @@ private struct SheetPickerContentView: View {
5050 }
5151
5252 private var listView : some View {
53+ Group {
54+ if #available( iOS 16 . 0 , * ) {
55+ baseList
56+ . scrollContentBackground ( . hidden)
57+ } else {
58+ baseList
59+ }
60+ }
61+ }
62+
63+ private var baseList : some View {
5364 List ( props. filteredOptions) { option in
5465 SheetPickerRow ( option: option, props: props)
5566 . listRowInsets ( EdgeInsets ( ) )
5667 . listRowBackground ( Color . clear)
5768 }
5869 . listStyle ( . plain)
59- . cornerRadius ( 12 )
60- // .scrollContentBackground(.hidden)
70+ . background ( Color . clear)
6171 }
6272}
6373
6474private struct SheetPickerRow : View {
6575 let option : SheetPickerOption
6676 @ObservedObject var props : SheetPickerProps
67- @State private var isPressed = false
6877
6978 var body : some View {
7079 Button {
@@ -84,55 +93,28 @@ private struct SheetPickerRow: View {
8493 . frame ( width: 20 , height: 20 )
8594 }
8695 }
87- . padding ( . vertical, 10 )
96+ }
97+ . buttonStyle ( HighlightableRowButtonStyle ( isSelected: option. value == props. selectedValue) )
98+ }
99+ }
100+
101+ private struct HighlightableRowButtonStyle : ButtonStyle {
102+ let isSelected : Bool
103+
104+ func makeBody( configuration: Configuration ) -> some View {
105+ configuration. label
106+ . padding ( . vertical, 12 )
88107 . padding ( . horizontal, 8 )
89- . background ( rowBackgroundColor)
108+ . frame ( maxWidth: . infinity, alignment: . leading)
109+ . background ( backgroundColor ( isPressed: configuration. isPressed) )
90110 . cornerRadius ( 10 )
91111 . contentShape ( Rectangle ( ) )
92- }
93- . buttonStyle ( . plain)
94- . onChange ( of: props. selectedValue) { _ in
95- isPressed = false
96- }
97- . pressAction {
98- isPressed = true
99- } onRelease: {
100- isPressed = false
101- }
102112 }
103113
104- private var rowBackgroundColor : Color {
105- if option . value == props . selectedValue {
114+ private func backgroundColor ( isPressed : Bool ) -> Color {
115+ if isSelected {
106116 return Color . accentColor. opacity ( 0.12 )
107117 }
108118 return isPressed ? Color . gray. opacity ( 0.15 ) : Color . clear
109119 }
110120}
111-
112- private extension View {
113- func pressAction( onPress: @escaping ( ) -> Void , onRelease: @escaping ( ) -> Void ) -> some View {
114- modifier ( PressActionModifier ( onPress: onPress, onRelease: onRelease) )
115- }
116- }
117-
118- private struct PressActionModifier : ViewModifier {
119- let onPress : ( ) -> Void
120- let onRelease : ( ) -> Void
121-
122- @State private var isPressed = false
123-
124- func body( content: Content ) -> some View {
125- content
126- . simultaneousGesture ( DragGesture ( minimumDistance: 0 )
127- . onChanged { _ in
128- if !isPressed {
129- isPressed = true
130- onPress ( )
131- }
132- }
133- . onEnded { _ in
134- isPressed = false
135- onRelease ( )
136- } )
137- }
138- }
0 commit comments