rundfunk47 / stinsen

Coordinators in SwiftUI. Simple, powerful and elegant.
MIT License
822 stars 87 forks source link

Add onTapped to TabItems #77

Closed LePips closed 1 year ago

LePips commented 2 years ago

Adds an onTapped method for TabChildItems that can be passed through the property wrapper and indicate whether the tab was just tapped through the isRepeat parameter: false if the tab was just selected and true if it was previously selected and was selected again. The coordinator used along with the tab item is passed to the function for whatever behavior, like popping to the root of a navigation view which I provided in the sample app.

A probable solution to https://github.com/rundfunk47/stinsen/issues/56 is to have an internal notification fire when the tab is repeated and the corresponding view listens to that notification as I don't think that a ScrollView/List or any other information can be grabbed just by being passed a Coordinator or View. I would have to look more into that.

There is a small undesirable behavior where at least a few (3-4) views/coordinators are pushed, and then popToRoot() is called, instead of a single push occurring a few of the views/coordinators pop one at a time. I don't know if this was previous behavior with popToRoot() but was just an observation of mine.

I'm only iffy in the using function on Content by implicitly setting _output and force unwrapping it in onTapped. I just quickly took this shortcut as using is implicitly called when a TabChildItem is created but I would want to move setting _output to init. Let me know if this is requested and I'll readily make the change.

rundfunk47 commented 1 year ago

This is awesome! Really great! 🥳