Customer Reviews with Ratings
SwiftUI Mastery Travel Discovery
Let's render out some more nested JSON in today's lesson. We'll finish up the restaurant details screen by laying out custom reviews from out network api. https://travel.letsbuildthatapp.com/travel_discovery/restaurant?id=0

Comments (3)
iTollMouS
2 years ago
I believe I have taken my refactoring to the furthest possible struct RestaurantDetailsView: View { @ObservedObject var vm = RestaurantDetailsViewModel() let restaurant: Restaurants @State var rating: Double = 5.0 @State var starSize = 18.0 @State var updateOnTouch = false var body: some View{ ScrollView { // separate view HeaderContainerView(restaurant: restaurant) // separate view RestaurantInfoView(restaurantsDetails: vm.restaurantsDetails?.description ?? "" ) // divider view HStack { Text("Popular dishes") .font(.system(size: 16, weight: .bold)) Spacer() }.padding(.horizontal) // separate view if let dishes = vm.restaurantsDetails?.popularDishes { // pass the dishes array DishCell(dishes: dishes) } // divider view HStack{ Text("Customer Reviews") .font(.system(size: 16, weight: .bold)) Spacer() }.padding(.all) // separate view if let reviews = vm.restaurantsDetails?.reviews { ReviewCell(reviews: reviews, rating: $rating, starSize: $starSize, updateOnTouch: $updateOnTouch) } }.navigationBarTitle("\(restaurant.name) Details", displayMode: .inline) } }
Daryl Wong
2 years ago
json url: https://travel.letsbuildthatapp.com/travel_discovery/restaurant?id=0
dniswhite
2 years ago
For the stars I love ternary operators. HStack(spacing: 2) { ForEach(0..<5, id: \.self) { num in Image(systemName: "star.fill") .foregroundColor(num < review.rating ? .orange : .gray) } }
Brian Voong
2 years ago
HELP & SUPPORT