37 lines
1.1 KiB
Swift
37 lines
1.1 KiB
Swift
import SwiftUI
|
||
import Lottie
|
||
|
||
/// 统一管理盲盒开启动画 4 状态的组件:loading / ready / opening / none
|
||
struct BlindBoxAnimationView: View {
|
||
@Binding var phase: BlindBoxAnimationPhase
|
||
let onTapReady: () -> Void
|
||
let onOpeningCompleted: () -> Void
|
||
|
||
var body: some View {
|
||
ZStack {
|
||
switch phase {
|
||
case .loading:
|
||
LottieView(name: "loading", isPlaying: true)
|
||
case .ready:
|
||
ZStack {
|
||
LottieView(name: "ready", isPlaying: true)
|
||
Color.clear
|
||
.contentShape(Rectangle())
|
||
.onTapGesture {
|
||
onTapReady()
|
||
}
|
||
}
|
||
case .opening:
|
||
BlindBoxLottieOnceView(name: "opening") {
|
||
onOpeningCompleted()
|
||
}
|
||
case .none:
|
||
Image("Empty")
|
||
.resizable()
|
||
.scaledToFit()
|
||
}
|
||
}
|
||
.frame(width: 300, height: 300)
|
||
}
|
||
}
|