[SwiftUI | iOS] Nested Button Styles Are Incorrectly Applied

Number:rdar://FB9939086 Date Originated:2022-03-02
Status:Open Resolved:
Product:SwiftUI Product Version:
Classification:Incorrect/Unexpected Behavior Reproducible:Yes
Issue Description
When applying ButtonStyles to nested buttons, outer Buttons are modified despite the interaction happening on inner Buttons.

Steps To Reproduce
1. Create a button style that can "accumulate" when applied to multiple buttons (for instance, a background color with opacity).
2. Create a Button and add the button style to it.
3. Create a new Button within the first one and add the same style to it.
4. Tap and hold the inner button.
5. Note how the style gets applied to both buttons, not just the inner one.

This behavior can be observed in the NestedButtonStyleExample.swift file of the attached project

Expected Behavior
The outer button shouldn't have been modified since it was the inner Button that was tapped. It seems the only verification being made is if the coordinates of the tap is within the component's hit area, without checking for the first responder or layout priority.



Check https://github.com/fjcaetano/not-awesome-swiftui

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!