콘텐츠 메인

- 단편 탭 UI 페이지 생성
This commit is contained in:
Yu Sung
2025-02-22 01:41:03 +09:00
parent 6bd27c5301
commit e9e7403579
18 changed files with 1018 additions and 95 deletions

View File

@@ -10,93 +10,99 @@ import Kingfisher
struct SectionEventBannerView: View {
@State private var currentIndex = -1
@State private var currentIndex = 0
@State private var timer = Timer.publish(every: 3, on: .main, in: .common).autoconnect()
let items: [EventItem]
var body: some View {
GeometryReader { proxy in
VStack(spacing: 13.3) {
TabView(selection: $currentIndex) {
ForEach(0..<items.count, id: \.self) { index in
let item = items[index]
if let url = item.thumbnailImageUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
KFImage(URL(string: url))
.cancelOnDisappear(true)
.downsampling(
size: CGSize(
width: proxy.size.width,
height: proxy.size.height
)
VStack(spacing: 13.3) {
TabView(selection: $currentIndex) {
ForEach(0..<items.count, id: \.self) { index in
let item = items[index]
if let url = item.thumbnailImageUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
KFImage(URL(string: url))
.cancelOnDisappear(true)
.downsampling(
size: CGSize(
width: screenSize().width,
height: screenSize().width * 300 / 1000
)
.resizable()
.scaledToFill()
.frame(width: proxy.size.width, height: proxy.size.height, alignment: .center)
.tag(index)
.onTapGesture {
if let _ = item.detailImageUrl {
AppState.shared.setAppStep(step: .eventDetail(event: item))
} else if let link = item.link, link.trimmingCharacters(in: .whitespaces).count > 0, let url = URL(string: link), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
}
} else {
KFImage(URL(string: item.thumbnailImageUrl))
.cancelOnDisappear(true)
.downsampling(
size: CGSize(
width: proxy.size.width,
height: proxy.size.height
)
)
.resizable()
.scaledToFill()
.frame(width: proxy.size.width, height: proxy.size.height, alignment: .center)
.tag(index)
.onTapGesture {
if let _ = item.detailImageUrl {
AppState.shared.setAppStep(step: .eventDetail(event: item))
} else if let link = item.link, link.trimmingCharacters(in: .whitespaces).count > 0, let url = URL(string: link), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
}
}
}
}
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
.frame(
width: proxy.size.width,
height: proxy.size.height,
alignment: .center
)
HStack(spacing: 4) {
ForEach(0..<items.count, id: \.self) { index in
Capsule()
.foregroundColor(index == currentIndex ? Color(hex: "3bb9f1") : Color(hex: "909090"))
)
.resizable()
.scaledToFill()
.frame(
width: index == currentIndex ? 18 : 6,
height: 6
width: screenSize().width,
height: screenSize().width * 300 / 1000,
alignment: .center
)
.tag(index)
.onTapGesture {
if let _ = item.detailImageUrl {
AppState.shared.setAppStep(step: .eventDetail(event: item))
} else if let link = item.link, link.trimmingCharacters(in: .whitespaces).count > 0, let url = URL(string: link), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
}
} else {
KFImage(URL(string: item.thumbnailImageUrl))
.cancelOnDisappear(true)
.downsampling(
size: CGSize(
width: screenSize().width,
height: screenSize().width * 300 / 1000
)
)
.resizable()
.scaledToFill()
.frame(
width: screenSize().width,
height: screenSize().width * 300 / 1000,
alignment: .center
)
.tag(index)
.onTapGesture {
if let _ = item.detailImageUrl {
AppState.shared.setAppStep(step: .eventDetail(event: item))
} else if let link = item.link, link.trimmingCharacters(in: .whitespaces).count > 0, let url = URL(string: link), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
}
}
}
}
.onAppear {
timer = Timer.publish(every: 3, on: .main, in: .common).autoconnect()
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
.frame(
width: screenSize().width,
height: screenSize().width * 300 / 1000,
alignment: .center
)
HStack(spacing: 4) {
ForEach(0..<items.count, id: \.self) { index in
Capsule()
.foregroundColor(index == currentIndex ? .button : .gray90)
.frame(
width: index == currentIndex ? 18 : 6,
height: 6
)
.tag(index)
}
}
.onDisappear {
timer.upstream.connect().cancel()
}
.onReceive(timer) { _ in
DispatchQueue.main.async {
withAnimation {
if currentIndex == items.count - 1 {
currentIndex = 0
} else {
currentIndex += 1
}
}
.onAppear {
timer = Timer.publish(every: 3, on: .main, in: .common).autoconnect()
}
.onDisappear {
timer.upstream.connect().cancel()
}
.onReceive(timer) { _ in
DispatchQueue.main.async {
withAnimation {
if currentIndex == items.count - 1 {
currentIndex = 0
} else {
currentIndex += 1
}
}
}