fix video
This commit is contained in:
@ -3,7 +3,6 @@ import AVKit
|
||||
import NukeUI
|
||||
|
||||
struct SightView: View {
|
||||
let sightId: Int
|
||||
@StateObject private var viewModel = SightViewModel()
|
||||
@EnvironmentObject private var appState: AppState
|
||||
|
||||
@ -75,16 +74,18 @@ struct SightView: View {
|
||||
.padding(.horizontal, 8)
|
||||
.padding(.bottom, 4)
|
||||
}
|
||||
// MARK: - Initial load
|
||||
.task(id: sightId) {
|
||||
// MARK: - Initial load and reload on sight change
|
||||
.task(id: appState.sightId) {
|
||||
guard let currentSightId = appState.sightId else { return }
|
||||
viewModel.setLanguage(appState.selectedLanguage)
|
||||
await viewModel.loadInitialData(sightId: sightId)
|
||||
await viewModel.loadInitialData(sightId: currentSightId)
|
||||
}
|
||||
// MARK: - Reload on language change
|
||||
.onChange(of: appState.selectedLanguage) { newLang in
|
||||
guard let currentSightId = appState.sightId else { return }
|
||||
viewModel.setLanguage(newLang)
|
||||
Task {
|
||||
await viewModel.loadInitialData(sightId: sightId)
|
||||
await viewModel.loadInitialData(sightId: currentSightId)
|
||||
}
|
||||
}
|
||||
.blockStyle(cornerRadius: 25)
|
||||
@ -98,34 +99,49 @@ struct SightView: View {
|
||||
case .loading:
|
||||
ZStack {
|
||||
Color.gray.opacity(0.3)
|
||||
ProgressView()
|
||||
.progressViewStyle(.circular)
|
||||
.tint(.white)
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.frame(height: 160)
|
||||
.cornerRadius(24, corners: [.topLeft, .topRight])
|
||||
.clipped()
|
||||
case .image(let url):
|
||||
LazyImage(url: url) { state in
|
||||
if let image = state.image {
|
||||
image.resizable().scaledToFit()
|
||||
} else {
|
||||
ZStack {
|
||||
Color.gray.opacity(0.3)
|
||||
ProgressView()
|
||||
.progressViewStyle(.circular)
|
||||
if let progress = viewModel.downloadProgress {
|
||||
VStack {
|
||||
ProgressView(value: progress)
|
||||
.progressViewStyle(.linear)
|
||||
.tint(.white)
|
||||
Text("\(Int(progress * 100))%")
|
||||
.foregroundColor(.white)
|
||||
.font(.caption)
|
||||
}
|
||||
.padding()
|
||||
} else {
|
||||
ProgressView()
|
||||
.progressViewStyle(.circular)
|
||||
.tint(.white)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, minHeight: 200)
|
||||
.cornerRadius(24, corners: [.topLeft, .topRight])
|
||||
.clipped()
|
||||
|
||||
case .image(let url):
|
||||
if let uiImage = UIImage(contentsOfFile: url.path) {
|
||||
Image(uiImage: uiImage)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.cornerRadius(24, corners: [.topLeft, .topRight])
|
||||
.clipped()
|
||||
} else {
|
||||
Image(systemName: "photo")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.foregroundColor(.gray)
|
||||
.frame(maxWidth: .infinity, minHeight: 200)
|
||||
.cornerRadius(24, corners: [.topLeft, .topRight])
|
||||
.clipped()
|
||||
}
|
||||
|
||||
case .video(let player):
|
||||
VideoPlayer(player: player)
|
||||
.aspectRatio(16/9, contentMode: .fit)
|
||||
.cornerRadius(24, corners: [.topLeft, .topRight])
|
||||
.clipped()
|
||||
|
||||
case .error:
|
||||
Image(systemName: "photo")
|
||||
.resizable()
|
||||
|
Reference in New Issue
Block a user