Abhiek187 / ez-recipes-ios

Easy recipes finder iOS app
MIT License
0 stars 0 forks source link

iOS Day 8: Binding #18

Closed Abhiek187 closed 1 year ago

Abhiek187 commented 1 year ago

https://user-images.githubusercontent.com/29958092/209456634-8eb5815a-5834-4ac0-933b-a4c6196ad03c.mp4

Condensed step cards

(Note that in the top video, the recipe image updates as well, but the recording got cut off.)

I was able to implement the "Find Me Another Recipe!" button and remove empty ingredient and equipment lists. (I decided to leave the "I Made This!" button alone since it will be associated with a DB update past the MVP. And temporarily showing a Toast message requires building a custom view or importing a 3rd party library, which aren't ideal.) Removing empty lists was easy, just some if statements. But the first change was a little more involved since I had to make sure the button event propagates to the parent view, ViewModel, and repository and back. The key was to replace the @State variables with @Binding since the child views don't own the recipe object. That belongs to the ViewModel, and we want to keep it as a single source of truth. I was worried how much this would change the existing code, but wrapping the recipes with .constant() fixed most of the problems.

My next PR will take care of all those long-awaited tests. Then we'll switch over to Android.