106 lines
4.2 KiB
Swift
106 lines
4.2 KiB
Swift
// MARK: - Blind Box Animation View
|
|
import SwiftUI
|
|
|
|
struct BlindBoxAnimationView: View {
|
|
let mediaType: BlindBoxMediaType
|
|
let animationPhase: BlindBoxAnimationPhase
|
|
let blindCount: BlindCount?
|
|
let blindGenerate: BlindBoxData?
|
|
let scale: CGFloat
|
|
let showScalingOverlay: Bool
|
|
let showMedia: Bool
|
|
let onBoxTap: () -> Void
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
// 1. 背景SVG
|
|
if !showScalingOverlay {
|
|
SVGImage(svgName: "BlindBg", contentMode: .fit)
|
|
.opacity(showScalingOverlay ? 0 : 1)
|
|
.animation(.easeOut(duration: 1.5), value: showScalingOverlay)
|
|
}
|
|
|
|
if mediaType == .all && !showScalingOverlay {
|
|
ZStack {
|
|
SVGImage(svgName: "BlindCount")
|
|
.frame(width: 100, height: 60)
|
|
|
|
Text("\(blindCount?.availableQuantity ?? 0) Boxes")
|
|
.font(Typography.font(for: .body, family: .quicksandBold))
|
|
.foregroundColor(.white)
|
|
.offset(x: 6, y: -18)
|
|
}
|
|
.position(x: UIScreen.main.bounds.width * 0.7,
|
|
y: UIScreen.main.bounds.height * 0.18)
|
|
.opacity(showScalingOverlay ? 0 : 1)
|
|
.animation(.easeOut(duration: 1.5), value: showScalingOverlay)
|
|
}
|
|
|
|
if !showScalingOverlay {
|
|
VStack(spacing: 20) {
|
|
switch animationPhase {
|
|
case .loading:
|
|
GIFView(name: "BlindLoading")
|
|
.frame(width: 300, height: 300)
|
|
|
|
case .ready:
|
|
ZStack {
|
|
GIFView(name: "BlindReady")
|
|
.frame(width: 300, height: 300)
|
|
|
|
// Add a transparent overlay to capture taps
|
|
Color.clear
|
|
.contentShape(Rectangle()) // Make the entire area tappable
|
|
.frame(width: 300, height: 300)
|
|
.onTapGesture {
|
|
onBoxTap()
|
|
}
|
|
}
|
|
.frame(width: 300, height: 300)
|
|
|
|
case .opening:
|
|
ZStack {
|
|
GIFView(name: "BlindOpen")
|
|
.frame(width: 300, height: 300)
|
|
.scaleEffect(scale)
|
|
.opacity(showMedia ? 0 : 1) // 当显示媒体时隐藏GIF
|
|
}
|
|
.frame(width: 300, height: 300)
|
|
|
|
case .none:
|
|
SVGImage(svgName: "BlindNone")
|
|
.frame(width: 300, height: 300)
|
|
}
|
|
}
|
|
.offset(y: -50)
|
|
.compositingGroup()
|
|
.padding()
|
|
}
|
|
|
|
// 只在未显示媒体且未播放动画时显示文字
|
|
if !showScalingOverlay && !showMedia {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
Text(blindGenerate?.videoGenerateTime ?? "hhsdshjsjdhn")
|
|
.font(Typography.font(for: .body, family: .quicksandBold))
|
|
.foregroundColor(Color.themeTextMessageMain)
|
|
Text(blindGenerate?.description ?? "informationinformationinformationinformationinformationinformation")
|
|
.font(.system(size: 14))
|
|
.foregroundColor(Color.themeTextMessageMain)
|
|
}
|
|
.frame(width: UIScreen.main.bounds.width * 0.70, alignment: .leading)
|
|
.padding()
|
|
.offset(x: -10, y: UIScreen.main.bounds.height * 0.2)
|
|
}
|
|
}
|
|
.padding()
|
|
.frame(
|
|
maxWidth: .infinity,
|
|
maxHeight: UIScreen.main.bounds.height * 0.65
|
|
)
|
|
.opacity(showScalingOverlay ? 0 : 1)
|
|
.animation(.easeOut(duration: 1.5), value: showScalingOverlay)
|
|
.offset(y: showScalingOverlay ? -100 : 0)
|
|
.animation(.easeInOut(duration: 1.5), value: showScalingOverlay)
|
|
}
|
|
}
|