wake-ios/wake/ContentView.swift
2025-08-29 15:33:05 +08:00

311 lines
12 KiB
Swift

import SwiftUI
import SwiftData
import AVKit
// MARK: -
extension AnyTransition {
///
static var slideFromLeading: AnyTransition {
.asymmetric(
insertion: .move(edge: .trailing).combined(with: .opacity), //
removal: .move(edge: .leading).combined(with: .opacity) //
)
}
}
// MARK: - Video Player View
struct VideoPlayerView: View {
let player: AVPlayer
@Binding var isFullscreen: Bool
var body: some View {
ZStack(alignment: .bottomTrailing) {
VideoPlayer(player: player)
.frame(width: 300, height: 200)
.cornerRadius(12)
.overlay(
RoundedRectangle(cornerRadius: 12)
.stroke(Color.gray.opacity(0.3), lineWidth: 1)
)
//
Button(action: {
isFullscreen = true
player.play()
}) {
Image(systemName: "arrow.up.left.and.arrow.down.right")
.font(.system(size: 20))
.foregroundColor(.white)
.padding(8)
.background(Color.black.opacity(0.6))
.clipShape(Circle())
}
.padding(16)
}
.frame(width: 300, height: 200)
.onTapGesture {
player.play()
}
.onAppear {
player.play()
}
.fullScreenCover(isPresented: $isFullscreen) {
ZStack(alignment: .topLeading) {
//
VideoPlayer(player: player)
.edgesIgnoringSafeArea(.all)
.onAppear { player.play() }
//
Button(action: {
isFullscreen = false
player.pause()
}) {
Image(systemName: "xmark.circle.fill")
.font(.title)
.foregroundColor(.white)
.padding()
.background(Color.black.opacity(0.4))
.clipShape(Circle())
}
.padding(.top, 50)
.padding(.leading, 20)
}
.background(Color.black.edgesIgnoringSafeArea(.all))
.statusBar(hidden: true)
}
}
}
// MARK: -
struct ContentView: View {
// MARK: -
@State private var showModal = false //
@State private var showSettings = false //
@State private var contentOffset: CGFloat = 0 //
@State private var showLogin = false
@State private var animateGradient = false
@State private var showLottieAnimation = true // Lottie
@State private var showVideoPlayer = false //
@State private var isVideoFullscreen = false //
let timer = Timer.publish(every: 0.02, on: .main, in: .common).autoconnect()
//
@Environment(\.modelContext) private var modelContext
// -
@Query private var login: [Login]
//
private let player: AVPlayer?
init() {
// 使URL
if let videoURL = URL(string: "https://cdn.fairclip.cn/files/7342843896868769793/飞书20250617-144935.mp4") {
self.player = AVPlayer(url: videoURL)
} else {
self.player = nil
print("Error: Invalid video URL")
}
}
// MARK: -
var body: some View {
NavigationView {
ZStack {
//
Color.themeTextWhiteSecondary.ignoresSafeArea()
//
VStack {
VStack(spacing: 20) {
//
HStack {
//
Button(action: showUserProfile) {
SVGImage(svgName: "User")
.frame(width: 24, height: 24)
}
Spacer()
// //
// NavigationLink(destination: TestView()) {
// Text("TestView")
// .font(.subheadline)
// .padding(.horizontal, 12)
// .padding(.vertical, 6)
// .background(Color.brown)
// .foregroundColor(.white)
// .cornerRadius(8)
// }
// //
// NavigationLink(destination: SubscribeView()) {
// Text("Subscribe")
// .font(.subheadline)
// .padding(.horizontal, 12)
// .padding(.vertical, 6)
// .background(Color.orange)
// .foregroundColor(.white)
// .cornerRadius(8)
// }
// .padding(.trailing)
// .fullScreenCover(isPresented: $showLogin) {
// LoginView()
// }
NavigationLink(destination: SubscribeView()) {
Text("3290")
.font(Typography.font(for: .subtitle))
.fontWeight(.bold)
.padding(.horizontal, 12)
.padding(.vertical, 6)
.background(Color.black)
.foregroundColor(.white)
.cornerRadius(16)
}
.padding(.trailing)
.fullScreenCover(isPresented: $showLogin) {
LoginView()
}
}
.padding(.horizontal)
.padding(.top, 20)
//
VStack(alignment: .leading, spacing: 4) {
Text("Hi! Click And")
Text("Open Your 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.65
)
.position(x: UIScreen.main.bounds.width / 2,
y: UIScreen.main.bounds.height * 0.325)
// 2. Lottie
if showLottieAnimation {
GIFView(name: "Blind") {
//
Router.shared.navigate(to: .blindBox(mediaType: .video))
}
.frame(width: 300, height: 300)
}
// 3.
if showVideoPlayer, let player = player {
VideoPlayerView(player: player, isFullscreen: $isVideoFullscreen)
} else if showVideoPlayer {
Text("Video not found")
.foregroundColor(.red)
}
}
.frame(
maxWidth: .infinity,
maxHeight: UIScreen.main.bounds.height * 0.65
)
.clipped()
//
Button(action: showUserProfile) {
Text("Go to Buy")
.font(Typography.font(for: .body))
.fontWeight(.bold)
.frame(maxWidth: .infinity)
.padding()
.background(Color.themePrimary)
.foregroundColor(Color.themeTextMessageMain)
.cornerRadius(32)
}
.padding(.horizontal)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.themeTextWhiteSecondary)
.offset(x: showModal ? UIScreen.main.bounds.width * 0.8 : 0)
.animation(.spring(response: 0.6, dampingFraction: 0.8), value: showModal)
.edgesIgnoringSafeArea(.all)
}
//
SlideInModal(
isPresented: $showModal,
onDismiss: hideUserProfile
) {
UserProfileModal(
showModal: $showModal,
showSettings: $showSettings
)
}
.offset(x: showSettings ? UIScreen.main.bounds.width : 0)
.animation(.spring(response: 0.6, dampingFraction: 0.8), value: showSettings)
//
ZStack {
if showSettings {
Color.black.opacity(0.3)
.edgesIgnoringSafeArea(.all)
.onTapGesture(perform: hideSettings)
.transition(.opacity)
}
if showSettings {
SettingsView(isPresented: $showSettings)
.transition(.move(edge: .leading))
.zIndex(1)
}
}
.animation(.spring(response: 0.6, dampingFraction: 0.8), value: showSettings)
}
.background(Color.themeTextWhiteSecondary)
.navigationBarHidden(true)
.navigationBarBackButtonHidden(true)
}
.navigationViewStyle(StackNavigationViewStyle())
.navigationBarHidden(true)
.navigationBarBackButtonHidden(true)
}
///
private func showUserProfile() {
withAnimation(.spring(response: 0.6, dampingFraction: 0.8)) {
// print(": \(login.count)")
// for (index, item) in login.enumerated() {
// print(" \(index + 1): =\(item.email), =\(item.name)")
// }
print("当前登录记录:")
for (index, item) in login.enumerated() {
print("记录 \(index + 1): 邮箱=\(item.email), 姓名=\(item.name)")
}
showModal.toggle()
}
}
///
private func hideUserProfile() {
withAnimation(.spring(response: 0.6, dampingFraction: 0.8)) {
showModal = false
}
}
///
private func hideSettings() {
withAnimation(.spring(response: 0.6, dampingFraction: 0.8)) {
showSettings = false
}
}
}
// MARK: -
#Preview {
ContentView()
}