Files
sodalive-ios/SodaLive/Sources/Chat/Character/Detail/Gallery/ImageViewerView.swift
2025-10-23 14:42:50 +09:00

71 lines
2.1 KiB
Swift

//
// ImageViewerView.swift
// SodaLive
//
// Created by klaus on 9/2/25.
//
import SwiftUI
import Kingfisher
struct ImageViewerView: View {
let images: [String]
@Binding var selectedIndex: Int
@Environment(\.dismiss) private var dismiss
var body: some View {
ZStack {
Color.black.ignoresSafeArea()
TabView(selection: $selectedIndex) {
ForEach(Array(images.enumerated()), id: \.offset) { index, imageUrl in
KFImage(URL(string: imageUrl))
.placeholder {
ProgressView()
.tint(.white)
}
.cancelOnDisappear(true)
.downsampling(size: CGSize(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
.resizable()
.aspectRatio(contentMode: .fit)
.tag(index)
}
}
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
VStack {
HStack {
Spacer()
Button {
dismiss()
} label: {
Image(systemName: "xmark")
.font(.title2)
.foregroundColor(.white)
.padding()
}
}
Spacer()
//
HStack(spacing: 8) {
ForEach(0..<images.count, id: \.self) { index in
Circle()
.fill(selectedIndex == index ? Color.white : Color.white.opacity(0.3))
.frame(width: 8, height: 8)
}
}
.padding(.bottom, 50)
}
}
}
}
#Preview {
ImageViewerView(
images: ["https://picsum.photos/400/500"],
selectedIndex: .constant(0)
)
}