@@ -62,7 +62,7 @@ public struct FioriButton: View {
62
62
let image : ( UIControl . State ) -> any View
63
63
let imagePosition : FioriButtonImagePosition
64
64
let imageTitleSpacing : CGFloat
65
- private let touchAreaInset : CGFloat = 50
65
+ private let touchAreaInset : CGFloat = 3
66
66
67
67
@Environment ( \. isEnabled) private var isEnabled
68
68
@Environment ( \. fioriButtonStyle) private var fioriButtonStyle
@@ -157,24 +157,15 @@ public struct FioriButton: View {
157
157
} , imagePosition: self . imagePosition, imageTitleSpacing: self . imageTitleSpacing)
158
158
159
159
return Group {
160
- if self . isSelectionPersistent {
161
- self . fioriButtonStyle. makeBody ( configuration: config)
162
- . overlay ( GeometryReader { proxy in
163
- Color . clear. contentShape ( Rectangle ( ) ) . gesture ( self . createGesture ( proxy. size) )
164
- } )
165
- } else {
166
- Button {
167
- self . action ? ( . normal)
168
- } label: {
169
- EmptyView ( )
170
- }
171
- . buttonStyle ( _ButtonStyleImpl ( fioriButtonStyle: self . fioriButtonStyle, label: self . label, image: self . image, imagePosition: self . imagePosition, imageTitleSpacing: self . imageTitleSpacing, isEnabled: self . isEnabled) )
172
- }
160
+ self . fioriButtonStyle. makeBody ( configuration: config)
161
+ . overlay ( GeometryReader { proxy in
162
+ Color . clear. contentShape ( Rectangle ( ) ) . gesture ( self . createGesture ( proxy. size) )
163
+ } )
173
164
}
174
165
}
175
166
176
167
func createGesture( _ size: CGSize ) -> some Gesture {
177
- let touchArea = CGRect ( origin: . zero, size: size) . insetBy ( dx: - self . touchAreaInset , dy: - self . touchAreaInset)
168
+ let touchArea = CGRect ( origin: . zero, size: size) . insetBy ( dx: 0 , dy: - self . touchAreaInset)
178
169
var isCancelled = false
179
170
180
171
return DragGesture ( minimumDistance: 0 )
@@ -185,6 +176,9 @@ public struct FioriButton: View {
185
176
186
177
if !touchArea. contains ( value. location) {
187
178
isCancelled = true
179
+ } else if !self . isSelectionPersistent {
180
+ self . _state = self . state == . normal ? . selected : . normal
181
+ self . action ? ( self . state)
188
182
}
189
183
}
190
184
. onEnded { _ in
@@ -226,33 +220,6 @@ public extension FioriButton {
226
220
}
227
221
}
228
222
229
- private struct _ButtonStyleImpl : ButtonStyle {
230
- let fioriButtonStyle : AnyFioriButtonStyle
231
- let label : ( UIControl . State ) -> any View
232
- let image : ( UIControl . State ) -> any View
233
- let imagePosition : FioriButtonImagePosition
234
- let imageTitleSpacing : CGFloat
235
- let isEnabled : Bool
236
-
237
- func makeBody( configuration: Configuration ) -> some View {
238
- let state : UIControl . State = self . isEnabled ? ( configuration. isPressed ? . highlighted : . normal) : . disabled
239
-
240
- let config = FioriButtonStyleConfiguration ( state: state, _label: { state in
241
- let v = self . label ( state)
242
- return FioriButtonStyleConfiguration . Label ( v)
243
- } , _image: { state in
244
- let v = self . image ( state)
245
- return FioriButtonStyleConfiguration . Image ( v)
246
- } , imagePosition: self . imagePosition, imageTitleSpacing: self . imageTitleSpacing)
247
-
248
- return ZStack {
249
- self . fioriButtonStyle. makeBody ( configuration: config)
250
-
251
- configuration. label. hidden ( )
252
- }
253
- }
254
- }
255
-
256
223
/// Place the image along the top, leading, bottom, or trailing edge of the button.
257
224
public enum FioriButtonImagePosition {
258
225
/// place the image along the top edge of the button.
0 commit comments