Procházet zdrojové kódy

Fix widget preview add button hit testing outside clipped card

The floating +/- control was offset outside the preview’s rounded clip,
so taps on the visible circle missed the parent button. Use a sibling
Button in a ZStack so the control has its own hit target.

Made-with: Cursor
huzaifahayat12 před 3 měsíci
rodič
revize
0348d64ddc
1 změnil soubory, kde provedl 25 přidání a 21 odebrání
  1. 25 21
      google_apps/Widgets/WidgetsRootView.swift

+ 25 - 21
google_apps/Widgets/WidgetsRootView.swift

@@ -308,28 +308,32 @@ private struct WidgetPreviewAddCard: View {
     @State private var hovering = false
 
     var body: some View {
-        Button(action: onToggle) {
-            WidgetPreviewCard(app: app, variant: variant)
-                .contentShape(RoundedRectangle(cornerRadius: 18, style: .continuous))
-                .overlay(alignment: .topTrailing) {
-                    ZStack {
-                        Image(systemName: isAdded ? "minus" : "plus")
-                            .font(.system(size: 12, weight: .bold))
-                            .foregroundStyle(iconForegroundStyle)
-                            .frame(width: 26, height: 26)
-                            .background(
-                                Circle()
-                                    .fill(iconBackgroundFill)
-                            )
-                            .shadow(color: .black.opacity(0.28), radius: 10, x: 0, y: 6)
-                    }
-                    .offset(x: 10, y: -10)
-                    .allowsHitTesting(false)
-                    .opacity(isAdded ? 1 : (hovering ? 1 : 0))
-                    .animation(.easeOut(duration: 0.12), value: hovering)
-                }
+        ZStack(alignment: .topTrailing) {
+            Button(action: onToggle) {
+                WidgetPreviewCard(app: app, variant: variant)
+                    .contentShape(RoundedRectangle(cornerRadius: 18, style: .continuous))
+            }
+            .buttonStyle(.plain)
+
+            // Separate control so taps on the floating + work: the card is clip-shaped, so the
+            // offset circle was outside the label’s hit region when it was only an overlay.
+            Button(action: onToggle) {
+                Image(systemName: isAdded ? "minus" : "plus")
+                    .font(.system(size: 12, weight: .bold))
+                    .foregroundStyle(iconForegroundStyle)
+                    .frame(width: 26, height: 26)
+                    .background(
+                        Circle()
+                            .fill(iconBackgroundFill)
+                    )
+                    .shadow(color: .black.opacity(0.28), radius: 10, x: 0, y: 6)
+                    .contentShape(Circle())
+            }
+            .buttonStyle(.plain)
+            .offset(x: 10, y: -10)
+            .opacity(isAdded ? 1 : (hovering ? 1 : 0))
+            .animation(.easeOut(duration: 0.12), value: hovering)
         }
-        .buttonStyle(.plain)
         .onHover { hovering = $0 }
     }