Product Detail View: Elevating User Experience

Abdullah Bilgin
Swift Insights
Published in
7 min readNov 10, 2023

The ProductDetailView in our Enhanced Components app is designed to provide users with a rich and immersive experience when exploring vehicle details. Let's dive into the key components and functionalities that make this view stand out.

Task#09: Enhancing Product Detail View

#### Overview:

Improve the Product Detail View by adding and refining various components for a better user experience.

#### Tasks:

1. **NavigationBarDetailView Enhancement**:
- [x] Refine the layout and styling of `NavigationBarDetailView`.
- [x] Ensure that the navigation bar looks visually appealing and fits the overall design theme.

2. **HeaderDetailView Improvement**:
- [x] Enhance the `HeaderDetailView` by refining its layout and visual elements.
- [x] Implement dynamic data binding to display relevant product information in the header.

3. **TopPartDetailView Refinement**:
- [x] Improve the layout and styling of `TopPartDetailView`.
- [x] Implement animations or transitions for a smoother user interaction.

4. **RatingsTrimsDetailView Adjustments**:
- [x] Fine-tune the appearance of the rating and trims section.
- [x] Ensure that the content is displayed correctly and consistently across different devices.

5. **Description Section Optimization**:
- [x] Optimize the display of the product description in the `ScrollView`.
- [x] Ensure the text is easy to read, and consider adding any necessary formatting.

6. **QuantityFavouriteDetailView Enhancement**:
- [x] Improve the layout and design of the quantity and favorite section.
- [x] Implement any necessary functionality or visual enhancements.

7. **AddToCartDetailView Refinement**:
- [x] Refine the appearance and behavior of the "Add to Cart" button.
- [x] Ensure that the button is easily noticeable and functions as expected.

8. **Background Color Adjustment**:
- [x] Evaluate and adjust the background color based on the product or design requirements.
- [x] Ensure that the background complements the overall theme of the app.

9. **Testing and Debugging**:
- [x] Test the entire `ProductDetailView` for responsiveness and compatibility.
- [x] Address any layout or rendering issues.
- [x] Verify that all components work seamlessly together.

#### Code Files:

https://github.com/abilgin88/Enhanced-Components-SwiftUI/commit/8511a42a8c733a95c7b3522f11076ea9f2e5635f

#### Notes:

- Ensure that the changes align with the existing style and design principles of the app.
- Test the product detail view on multiple devices and screen sizes.
- Consider implementing SwiftUI previews for each refined component to ease testing and visualization.



![Image](https://github.com/users/abilgin88/projects/11/assets/96279901/e534ef3e-eb50-4a80-877b-9b5935895130)

import SwiftUI

struct ProductDetailView: View {
// Mark: - Properties

// Mark: - Body
var body: some View {
VStack(alignment: .leading, spacing: 5, content: {
// Navigation Bar
NavigationBarDetailView()
.padding()
//.padding(.top, UIApplication.shared.windows.first?.safeAreaInsets.top)
.padding(.top, (UIApplication.shared.connectedScenes.first as? UIWindowScene)?.windows.first?.safeAreaInsets.top)

// Header
HeaderDetailView()
.padding(.horizontal)

// Detail top part
TopPartDetailView()
.padding(.horizontal)
.zIndex(1)


// Detail bottom part
VStack(alignment: .center, spacing: 0, content: {
// Rating and Trims
RatingsTrimsDetailView()
.padding(.top, 10)
.padding(.bottom, 10)

// Description
ScrollView(.vertical, showsIndicators: false, content: {
Text(sampleVehicles.description)
.font(.system(.body, design: .rounded))
.foregroundStyle(.gray)
.multilineTextAlignment(.leading)

}) // End of Scroll

// Quantity + Favourite
QuantityFavouriteDetailView()
.padding(.vertical, 10)

// Add to cart

AddToCartDetailView()
.padding(.bottom, 20)


}) // End of VStack Detail Bottom
.padding(.horizontal)
.background(
Color.white
.clipShape(CustomShape())
.padding(.top, -105)
)
}) // End of VStack Body
.zIndex(0)
.ignoresSafeArea(.all, edges: .all)
.background(
Color(
red: sampleVehicles.red,
green: sampleVehicles.green,
blue: sampleVehicles.blue)
)
//.ignoresSafeArea(.all, edges: .all)
}
}

// Mark: - Preview
#Preview {
ProductDetailView()
.previewLayout(.fixed(width: 375, height: 812))
}

1. Navigation Bar Detail View:

The top of the screen features a sleek NavigationBarDetailView that ensures easy navigation and provides a seamless transition between views. It maintains a consistent and aesthetically pleasing design, enhancing the overall user interface.

//
// NavigationBarDetailView.swift
// Enhanced-Components
//
// Created by Abdullah Bilgin on 11/6/23.

import SwiftUI

struct NavigationBarDetailView: View {
// Mark: - Properties

// Mark: - Body
var body: some View {
HStack {
Button(action: {}, label: {
Image(systemName: "chevron.left")
.font(.title)
.foregroundColor(.white)
})

Spacer()

Button(action: {}, label: {
Image(systemName: "cart")
.font(.title)
.foregroundColor(.white)
})
} // End of HStack Body
}
}

// Mark: - Preview
#Preview {
NavigationBarDetailView()
.padding()
.background(Color.gray)
}

2. Header Detail View:

Following the navigation bar, the HeaderDetailView section captures attention with its well-balanced layout. This area is strategically designed to present essential details and set the stage for the user to explore the product further.

//
// HeaderDetailView.swift
// Enhanced-Components
//
// Created by Abdullah Bilgin on 11/6/23.
//

import SwiftUI

struct HeaderDetailView: View {
// Mark: - Properties

// Mark: - Body
var body: some View {
VStack(alignment: .leading, spacing: 6, content: {
Text("Your Journey, Your Way")

Text(sampleVehicles.name)
.font(.largeTitle)
.fontWeight(.black)
}) // End of VStack Body
.foregroundColor(.white)
}
}

// Mark: - Body
#Preview {
HeaderDetailView()
.padding()
.background(Color.gray)
}

3. Top Part Detail View:

The top part of the product detail view, represented by TopPartDetailView, is where users get an initial glimpse of the vehicle. This section is carefully crafted to highlight key features and create an impactful visual impression.

//
// TopPartDetailView.swift
// Enhanced-Components
//
// Created by Abdullah Bilgin on 11/6/23.
//

import SwiftUI

struct TopPartDetailView: View {
// Mark: - Properties
@State private var isAnimating: Bool = false

// Mark: - Body
var body: some View {
HStack(alignment: .center, spacing: 6, content: {
// Price
VStack(alignment: .leading, spacing: 6, content: {
Text("Price")
.fontWeight(.semibold)

Text(sampleVehicles.formattedPrice)
.font(.title3)
.fontWeight(.black)
.scaleEffect(1.35, anchor: .leading)

}) // End of VStack Price
.offset(y: isAnimating ? -50 : -75)

Spacer()

// Photo
Image(sampleVehicles.icon)
.resizable()
//.scaledToFit()
.frame(width: 200, height: 200)
.offset(y: isAnimating ? 0 : -35)

}) //End of HStack Body
.onAppear(perform: {
withAnimation(.easeOut(duration: 0.75)) {
isAnimating.toggle()
}
})
}
}

// Mark: - Preview
#Preview {
TopPartDetailView()
.padding()
}

4. Ratings and Trims Detail View:

User feedback is crucial, and the RatingsTrimsDetailView ensures that ratings and trims are easily accessible. This user-friendly approach enhances transparency, helping users make informed decisions.

//
// RatingsSizesDetailView.swift
// Enhanced-Components
//
// Created by Abdullah Bilgin on 11/6/23.
//

import SwiftUI

struct RatingsTrimsDetailView: View {
// Mark: - Properties
let trim_levels: [String] = ["E", "SE", "L", "S", "P"]

// Mark: - Body
var body: some View {
HStack(alignment: .top, spacing: 3, content: {
// Rating
VStack(alignment: .leading, spacing: 3, content: {
Text("Rating")
.font(.footnote)
.fontWeight(.semibold)
.foregroundStyle(Color.gray)

HStack(alignment: .center, spacing: 3, content: {
ForEach(1...5, id: \.self) { item in
Button(action: {}, label: {
Image(systemName: "star.fill")
})
.frame(width: 28, height: 28, alignment: .center)
.background(Color.gray.cornerRadius(5))
.foregroundColor(.white)
} // End of Loop
}) // End of HStack Button
}) // End of VStack Rating

Spacer()

// Trims
VStack(alignment: .trailing, spacing: 3, content: {
Text("Trims")
.font(.footnote)
.fontWeight(.semibold)
.foregroundStyle(Color.gray)

HStack(alignment: .center, spacing: 5, content: {
ForEach(trim_levels, id: \.self) { trim in
Button(action: {}, label: {
Text(trim)
.font(.footnote)
.fontWeight(.heavy)
.foregroundStyle(Color.gray)
.frame(width: 28, height: 28, alignment: .center)
.background(Color.white.cornerRadius(5))
.background(
RoundedRectangle(cornerRadius: 5)
.stroke(Color.gray, lineWidth: 2))
}) // End of Buttom
} // End of Loop
}) // End of HStack Button
}) // End of VStack Trims
}) // End of HStack Body
}
}

// Mark: - Preview
#Preview {
RatingsTrimsDetailView()
.padding()
}

5. Description Section:

To provide users with comprehensive information, a dedicated scrolling section for the vehicle description is incorporated. The use of a clean and readable font, along with a thoughtfully chosen color palette, contributes to a pleasant reading experience.

6. Quantity, Favourite, and Add to Cart:

The bottom part of the detail view features QuantityFavouriteDetailView for easy quantity adjustments and favoriting options. The AddToCartDetailView component streamlines the process of adding the product to the cart, ensuring a smooth user journey.

//
// QuantityFavouriteDetailView.swift
// Enhanced-Components
//
// Created by Abdullah Bilgin on 11/6/23.
//

import SwiftUI

struct QuantityFavouriteDetailView: View {
// Mark: - Properties
@State private var counter: Int = 0

// Mark: - Body
var body: some View {
HStack(alignment: .center, spacing: 6, content: {
Button(action: {
if counter > 0 {
counter -= 1
}
}, label: {
Image(systemName: "minus.circle")
}) // End of minus button

Text("\(counter)")
.fontWeight(.semibold)
.frame(minWidth: 36)

Button(action: {
if counter < 100 {
counter += 1
}
}, label: {
Image(systemName: "plus.circle")
}) // End of plus button

Spacer()

Button(action: /*@START_MENU_TOKEN@*/{}/*@END_MENU_TOKEN@*/, label: {
Image(systemName: "heart.circle")
.foregroundStyle(Color.pink)
}) // End of heart button

}) // End of HStack Body
.font(.system(.title, design: .rounded))
.foregroundStyle(Color.black)
.imageScale(.large)
}
}

// Mark: - Preview
#Preview {
QuantityFavouriteDetailView()
.padding()
}
//
// AddToCartDetailView.swift
// Enhanced-Components
//
// Created by Abdullah Bilgin on 11/6/23.
//

import SwiftUI

struct AddToCartDetailView: View {
// Mark: - Properties

// Mark: - Body
var body: some View {
Button(action: {}, label: {

Spacer()

Text("Add to cart".uppercased())
.font(.system(.title2, design: .rounded))
.fontWeight(.bold)
.foregroundStyle(Color.white)

Spacer()

}) // End of button
.padding()
.background(
Color(
red: sampleVehicles.red,
green: sampleVehicles.green,
blue: sampleVehicles.blue
)
)
.clipShape(Capsule())
}
}

// Mark: - Preview
#Preview {
AddToCartDetailView()
.padding()
}

7. Aesthetic Design and Color Palette:

The entire ProductDetailView is not just about functionality but also about aesthetics. The carefully selected color palette and design elements create a visually appealing interface, making the user experience delightful.

8. Seamless Background Integration:

The background is intelligently integrated, using a custom shape and a dynamic color scheme derived from the product details. This ensures that the background complements the overall design, providing a unified and immersive feel.

Conclusion:

The ProductDetailView is more than just a screen; it's a user-centric journey through vehicle details. From navigation to aesthetics, every element is meticulously designed to enhance the overall user experience. As we continue refining and expanding our Enhanced Components app, this attention to detail will remain at the core of our development philosophy. Explore the future of vehicle exploration with the ProductDetailView in the Enhanced Components app!

Your time spent exploring the intricacies of the ProductDetailView in our Enhanced Components app is truly appreciated. We hope you found the journey through vehicle details delightful and user-centric.

For more exciting updates and enhanced features, stay tuned. Your engagement is a valuable part of our development philosophy, and we look forward to bringing you even more innovative experiences.

--

--

Abdullah Bilgin
Swift Insights

"iOS engineer & IT head, crafting code & innovation. Leading with tech prowess & strategic vision. Bridging iOS dev & IT realms. Lifelong learner. 📱💡"