Skip to content

Commit

Permalink
feat: 플레이스홀더 UI 구현 및 네트워크 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
hooni0918 committed Jan 22, 2025
1 parent e7d7388 commit 879d9b5
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 182 deletions.
15 changes: 9 additions & 6 deletions Spoony-iOS/Spoony-iOS/Network/Model/MapFocusResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import Foundation

struct MapFocusResponse: Codable {
let zzimFocusResponseList: [MapFocusItem]
let zzimFocusResponseList: [FocusPlaceResponse]
}

struct MapFocusItem: Codable {
struct FocusPlaceResponse: Codable {
let placeId: Int
let placeName: String
let categoryColorResponse: MapFocusCategoryColorResponse
Expand All @@ -24,22 +24,25 @@ struct MapFocusItem: Codable {
}

struct MapFocusCategoryColorResponse: Codable {
let categoryId: Int
let categoryName: String
let iconUrl: String
let iconTextColor: String
let iconBackgroundColor: String
}

extension MapFocusItem {
extension FocusPlaceResponse {
func toCardPlace() -> CardPlace {
return CardPlace(
name: placeName,
visitorCount: "\(zzimCount)",
visitorCount: "\(zzimCount)",
address: authorRegionName,
images: photoUrlList,
title: postTitle,
subTitle: categoryColorResponse.categoryName,
description: "by \(authorName)"
subTitle: postTitle,
description: categoryColorResponse.categoryName,
categoryColor: categoryColorResponse.iconBackgroundColor,
categoryTextColor: categoryColorResponse.iconTextColor
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ final class DefaultHomeService: HomeServiceType {
}
}
}

func fetchFocusedPlace(userId: Int, placeId: Int) async throws -> MapFocusResponse {
return try await withCheckedThrowingContinuation { continuation in
provider.request(.getMapFocus(userId: userId, placeId: placeId)) { result in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ struct CardPlace: Identifiable {
let title: String
let subTitle: String
let description: String
let categoryColor: String
let categoryTextColor: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,75 @@
import SwiftUI

struct PlaceCard: View {
let placeName: String
let visitorCount: String
let address: String
let images: [String]
let title: String
let subTitle: String
let description: String
let places: [CardPlace]
@Binding var currentPage: Int

var body: some View {
VStack(spacing: 0) {
PlaceImagesLayout(images: images)

VStack(alignment: .leading) {
HStack(spacing: 6) {

Text(placeName)
.customFont(.body1b)

// TODO: 칩으로 대체
HStack(spacing: 4) {
Image(systemName: "mug.fill")

Text("카페")
.customFont(.system(size: 14.5))
TabView(selection: $currentPage) {
ForEach(places.indices, id: \.self) { index in
VStack(spacing: 0) {
VStack(spacing: 0) {
PlaceImagesLayout(images: places[index].images)

VStack(alignment: .leading) {
HStack(spacing: 6) {
Text(places[index].name)
.customFont(.body1b)
.lineLimit(1)

HStack(spacing: 4) {
Image(systemName: "mug.fill")
Text(places[index].description)
.customFont(.system(size: 14.5))
}
.foregroundColor(Color(hex: places[index].categoryTextColor))
.padding(.horizontal, 12)
.padding(.vertical, 4)
.background(Color(hex: places[index].categoryColor).opacity(0.1))
.clipShape(RoundedRectangle(cornerRadius: 10))

Spacer()

HStack(spacing: 4) {
Image(.icAddmapGray400)
Text(places[index].visitorCount)
.customFont(.caption2b)
}
}
}
.padding(15)
}
.foregroundColor(.pink400)
.padding(.horizontal, 12)
.padding(.vertical, 4)
.background(Color.pink400.opacity(0.1))
.cornerRadius(16)
.background(Color.white)

Spacer()
HStack(spacing: 4) {
Image(.icAddmapGray400)
Text(visitorCount)
.customFont(.caption2b)
// 하단 정보 부분
VStack(alignment: .leading, spacing: 6) {
HStack {
Text(places[index].title)
.customFont(.body2b)
.lineLimit(1)
Text(places[index].address)
.customFont(.caption1m)
.foregroundColor(.gray600)
}
Text(places[index].subTitle)
.customFont(.caption1m)
.foregroundColor(.spoonBlack)
}
.padding(15)
.frame(maxWidth: .infinity, alignment: .leading)
.background(Color.gray0)
.clipShape(RoundedRectangle(cornerRadius: 10))
.padding(.horizontal, 15)
.padding(.bottom, 15)
}
.background(Color.white)
.clipShape(RoundedRectangle(cornerRadius: 10))
.tag(index)
}
.padding(15)

VStack(alignment: .leading, spacing: 6) {
HStack {
Text(title)
.customFont(.body2b)
Text(subTitle)
.customFont(.caption1m)
.foregroundColor(.gray600)

}
Text(description)
.customFont(.caption1m)
.foregroundColor(.spoonBlack)
}
.padding(15)
.frame(maxWidth: .infinity, alignment: .leading)
.background(Color.gray0)
.cornerRadius(10)
.padding(.horizontal, 15)
.padding(.bottom, 15)
}
.background(Color.white)
.cornerRadius(16)
.padding(.horizontal, 26)
.frame(height: 280.adjusted)
.tabViewStyle(.page(indexDisplayMode: .never))
.background(Color.clear)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,34 @@

import SwiftUI

struct PlaceCardsContainer: View {
@EnvironmentObject private var navigationManager: NavigationManager
let places: [CardPlace]
@Binding var currentPage: Int

var body: some View {
TabView(selection: $currentPage) {
ForEach(Array(places.enumerated()), id: \.element.id) { index, place in
PlaceCard(
placeName: place.name,
visitorCount: place.visitorCount,
address: place.address,
images: place.images,
title: place.title,
subTitle: place.subTitle,
description: place.description
)
.padding(.horizontal, 16)
.tag(index)
.onTapGesture {
navigationManager.push(.detailView)
}
}
}
.frame(height: 280.adjusted)
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
}
}
//struct PlaceCardsContainer: View {
// let places: [CardPlace]
// @Binding var currentPage: Int
//
// var body: some View {
// TabView(selection: $currentPage) {
// ForEach(Array(places.enumerated()), id: \.element.id) { index, place in
// PlaceCard(
// placeName: place.name,
// visitorCount: place.visitorCount,
// address: place.address,
// images: place.images,
// title: place.title,
// subTitle: place.subTitle,
// description: place.description,
// categoryColor: place.categoryColor,
// categoryTextColor: place.categoryTextColor
// )
// .tag(index)
// }
// }
// .padding(.horizontal, 16)
// .frame(height: 280.adjusted)
// .tabViewStyle(.page(indexDisplayMode: .never))
// .background(Color.clear) // 배경을 투명하게 설정
// }
//}
//
//#Preview {
// Home()
//}
Original file line number Diff line number Diff line change
Expand Up @@ -14,88 +14,66 @@ struct PlaceImagesLayout: View {
HStack(spacing: 1) {
switch images.count {
case 1:
if let url = URL(string: images[0]) {
AsyncImage(url: url) { phase in
switch phase {
case .success(let image):
image
.resizable()
.scaledToFill()
case .failure(_):
Image(systemName: "photo")
.foregroundColor(.gray)
case .empty:
ProgressView()
@unknown default:
EmptyView()
}
}
.frame(maxWidth: .infinity)
.frame(height: 132.adjusted)
.clipShape(RoundedCorner(radius: 12, corners: [.topLeft, .topRight]))
}

imageView(
urlString: images[0],
width: nil,
height: 132.adjusted,
corners: [.topLeft, .topRight]
)
case 2:
ForEach(0..<2, id: \.self) { index in
if let url = URL(string: images[index]) {
AsyncImage(url: url) { phase in
switch phase {
case .success(let image):
image
.resizable()
.scaledToFill()
case .failure(_):
Image(systemName: "photo")
.foregroundColor(.gray)
case .empty:
ProgressView()
@unknown default:
EmptyView()
}
}
.frame(maxWidth: .infinity)
.frame(height: 132.adjusted)
.clipShape(
RoundedCorner(
radius: 12,
corners: index == 0 ? [.topLeft] : [.topRight]
)
)
}
imageView(
urlString: images[index],
width: nil,
height: 132.adjusted,
corners: index == 0 ? [.topLeft] : [.topRight]
)
.frame(maxWidth: .infinity)
}

case 3:
ForEach(0..<3, id: \.self) { index in
if let url = URL(string: images[index]) {
AsyncImage(url: url) { phase in
switch phase {
case .success(let image):
image
.resizable()
.scaledToFill()
case .failure(_):
Image(systemName: "photo")
.foregroundColor(.gray)
case .empty:
ProgressView()
@unknown default:
EmptyView()
}
}
.frame(maxWidth: .infinity)
.frame(height: 132.adjusted)
.clipShape(
RoundedCorner(
radius: 12,
corners: index == 0 ? [.topLeft] : (index == 2 ? [.topRight] : [])
)
)
}
imageView(
urlString: images[index],
width: 108.adjusted,
height: 108.adjusted,
corners: index == 0 ? [.topLeft] : (index == 2 ? [.topRight] : [])
)
}

default:
EmptyView()
}
}
.frame(maxWidth: .infinity)
.frame(height: images.count == 3 ? 108.adjusted : 132.adjusted)
.background(
RoundedRectangle(cornerRadius: 10)
.fill(Color.white)
.mask(
RoundedCorner(radius: 10, corners: [.topLeft, .topRight])
)
)
}

private func imageView(urlString: String, width: CGFloat?, height: CGFloat, corners: UIRectCorner) -> some View {
AsyncImage(url: URL(string: urlString)) { phase in
switch phase {
case .empty:
ProgressView()
case .success(let image):
image
.resizable()
.aspectRatio(contentMode: .fill)
case .failure:
Color.gray
@unknown default:
Color.gray
}
}
.frame(width: width, height: height)
.frame(maxWidth: width == nil ? .infinity : nil)
.clipped()
.mask(
RoundedCorner(radius: 10, corners: corners)
)
}
}
Loading

0 comments on commit 879d9b5

Please sign in to comment.