UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Best practice(s) for handling tap actions in subviews

Forums > SwiftUI

Assume I have a primary view (View1), which has two subviews (View2, View3). Both View2 and View3 have tappable areas on them. Should View2 and View3 handle the tap actions themselves, or should they "communicate" the tap has occurred and let View1 handle it?

I think it boils down to whether the tap is an action that needs to be performed, e.g. a delete action, or if the tap is just to signify that a tap occurred, but that the action should be left up to the containing view. For example, if View2 was a calendar, then tapping on a day could initiate any number of actions so should propogate that tap to the containing view. If View3 displays calendar events, then a tap action to delete an event should probably be handled in View3 itself.

Does that sound like a sensible approach?

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.