wake-ios/wake/View/Blind/BlindBox.swift
2025-08-27 11:36:15 +08:00

87 lines
3.9 KiB
Swift

import SwiftUI
import SwiftData
import AVKit
extension Notification.Name {
static let navigateToMediaViewer = Notification.Name("navigateToMediaViewer")
}
// MARK: -
struct BlindBoxView: View {
@State private var showLottieAnimation = true // Lottie
// MARK: -
var body: some View {
ZStack {
//
Color.themeTextWhiteSecondary.ignoresSafeArea()
//
VStack {
VStack(spacing: 20) {
//
VStack(alignment: .leading, spacing: 4) {
Text("Hi! Click And")
Text("Open Your First Box~")
}
.font(Typography.font(for: .smallLargeTitle))
.fontWeight(.bold)
.foregroundColor(Color.themeTextMessageMain)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal)
//
// SVG
ZStack {
// 1. SVG
SVGImage(svgName: "BlindBg")
.frame(
width: UIScreen.main.bounds.width * 1.8,
height: UIScreen.main.bounds.height * 0.85
)
.position(x: UIScreen.main.bounds.width / 2,
y: UIScreen.main.bounds.height * 0.325)
LottieView(name: "loading", loopMode: .loop)
.frame(width: 200, height: 200)
.position(x: UIScreen.main.bounds.width / 2,
y: UIScreen.main.bounds.height * 0.325)
.onAppear {
// Load image from URL asynchronously
if let url = URL(string: "https://cdn.fairclip.cn/files/7348219809961742336/c5ca6151-91d3-483e-b7e7-c37f2cb69dc0.png") {
URLSession.shared.dataTask(with: url) { data, response, error in
if let data = data, let image = UIImage(data: data) {
let media = MediaType.image(image)
DispatchQueue.main.async {
// Present the outcome view modally
let outcomeView = BlindOutcomeView(media: media)
.ignoresSafeArea()
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first {
window.rootViewController?.present(UIHostingController(rootView: outcomeView), animated: true)
}
}
}
}.resume()
}
}
}
.frame(
maxWidth: .infinity,
maxHeight: UIScreen.main.bounds.height * 0.65
)
.clipped()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.themeTextWhiteSecondary)
.edgesIgnoringSafeArea(.all)
}
}
.navigationBarBackButtonHidden(true)
}
}
// MARK: -
#Preview {
BlindBoxView()
}