Howdy I’m new to SwiftUI so dont thoughts my foolish errors.What i’m attempting to do is i’ve a house view inside dwelling view there’s a films scroll view which on clikc on every goes to a moviedetailview that is working effective however in dwelling view there’s a see all navigation button which on click on goes to the favored films view then if i click on on every film once more i would like to come back to moviedetail view ,however right here i’m dealing with the difficulty the place the favored film view once more seems and on again there’s moviedetail view.
enter picture description right hereenter picture description right here
enter picture description right hereenter picture description right here
Howdy I’m new to SwiftUI so dont thoughts my foolish errors.What i’m attempting to do is i’ve a house view inside dwelling view there’s a films scroll view which on clikc on every goes to a moviedetailview that is working effective however in dwelling view there’s a see all navigation button which on click on goes to the favored films view then if i click on on every film once more i would like to come back to moviedetail view ,however right here i’m dealing with the difficulty the place the favored film view once more seems and on again there’s moviedetail view.
struct HomeView: View {
@State var moviesListViewModel = MoviesListViewModel()
@State var peopleListViewModel = PeopleListViewModel()
@State var tvShowListViewMoedel = TvShowListViewModel()
var physique: some View {
NavigationStack{
ZStack {
Shade.black.opacity(0.9)
.ignoresSafeArea(edges: .all)
VStack {
ScrollView{
//MARK: - MoviesList
HStack{
ExtractedView(title: "Fashionable films", subTitle: "Fashionable films this week")
NavigationLink {
PopularMovies()
.surroundings(moviesListViewModel)
} label: {
Textual content("See all")
.foregroundStyle(.blue)
.padding(.trailing)
.daring()
.body(maxHeight: .infinity,alignment:.middle)
}
}
//MARK: - MoviesListScrollView
MoviesScrollView()
.surroundings(moviesListViewModel)
//MARK: - PeopleList
HStack{
ExtractedView(title: "Fashionable celebreties", subTitle: "Fashionable celebreties this week")
NavigationLink {
PopularPeople()
.surroundings(peopleListViewModel)
} label: {
Textual content("See all")
.foregroundStyle(.blue)
.padding(.trailing)
.daring()
.body(maxHeight: .infinity,alignment:.middle)
}
}
.padding(.prime,20)
//MARK: - PeopleScrollView
PeopleScrollView()
.surroundings(peopleListViewModel)
HStack{
ExtractedView(title: "Fashionable Television Reveals", subTitle: "Fashionable TV reveals this week")
NavigationLink {
PopularTvShow()
.surroundings(tvShowListViewMoedel)
} label: {
Textual content("See all")
.foregroundStyle(.blue)
.padding(.trailing)
.daring()
.body(maxHeight: .infinity,alignment:.middle)
}
}
.padding(.prime,20)
TvShowScrollView()
.surroundings(tvShowListViewMoedel)
}
.body(maxWidth:.infinity,maxHeight:.infinity,alignment: .topLeading)
}
.navigationDestination(for: Film.self, vacation spot: { merchandise in
MovieDetailView(movieDetails: merchandise)
.navigationBarBackButtonHidden()
})
}
}
}
}
#Preview {
HomeView()
}
struct ExtractedView: View {
// @Setting(MoviesListViewModel.self) var moviesListViewModel
@State var title:String
@State var subTitle:String
//var someView: T
var physique: some View {
VStack{
HStack{
RoundedRectangle(cornerRadius: 2)
.body(width: 6,top: 25)
.foregroundStyle(Shade("yellowColor"))
HStack {
Textual content(title)
.foregroundStyle(.white)
.font(.title)
.daring()
Spacer()
}
}
Textual content(subTitle)
.foregroundStyle(.white.opacity(0.8))
.body(maxWidth:.infinity,alignment: .topLeading)
}
.body(maxWidth:.infinity,alignment: .topLeading)
.padding([.leading,.vertical])
}
}
struct PopularMovies: View {
init(){
print("Poppular Films Display")
}
@State var isLoading:Bool = true
@State var pageNumber:Int = 1
@Setting(MoviesListViewModel.self) var moviesListViewModel
@Setting(.dismiss) var dismiss
var physique: some View {
ZStack{
Shade.black.opacity(0.9)
.ignoresSafeArea(edges: .all)
//if !isLoading{
VStack{
HStack{
Picture(systemName: "arrow.left")
.imageScale(.giant)
.onTapGesture {
dismiss()
}
Textual content("Fashionable films")
.font(.title2)
Spacer()
HStack{
if pageNumber > 1{
Button {
pageNumber -= 1
Process{
strive await moviesListViewModel.getAllPopularMoviesList(web page: pageNumber)
}
} label: {
Picture(systemName: "arrow.left")
}
.disabled(pageNumber<1 ? true : false)
}
Textual content("(pageNumber)")
Button {
pageNumber += 1
Process{
strive await moviesListViewModel.getAllPopularMoviesList(web page: pageNumber)
}
} label: {
Picture(systemName: "arrow.proper")
}
}
.daring()
.foregroundStyle(Shade("yellowColor"))
.padding(.trailing)
}
.foregroundStyle(.white)
.daring()
.body(maxWidth: .infinity,alignment:.main)
.padding(.main)
ScrollView(.vertical){
if isLoading != true {
LazyVStack(spacing: 10) {
ForEach(moviesListViewModel.movieAllPopularListArray, id: .id) { knowledge in
if let outcomes = knowledge.outcomes {
ForEach(outcomes, id: .id) { innerData in
NavigationLink(worth:innerData){
MovieCard2(imageURL: innerData.posterPath, ranking: innerData.voteAverage, movieTitle: innerData.title, releaseDate: innerData.releaseDate, viewersCount: innerData.voteCount)
Divider()
.background(Shade.grey)
}
}
}
}
}
.padding(.main)
}
else{
ProgressView("Loading...")
.controlSize(.giant)
.foregroundStyle(Shade("yellowColor"))
}
}
}
.scrollContentBackground(.hidden)
.navigationBarBackButtonHidden()
.body(maxWidth: .infinity,alignment:.main)
.scrollIndicators(.hidden)
}
.job {
Process{
strive await moviesListViewModel.getAllPopularMoviesList(web page: pageNumber)
}
}
.onChange(of: moviesListViewModel.isLoading) { oldValue, newValue in
isLoading = newValue
}
}
}
struct MovieDetailView: View {
@State var videoPlayerViewModel = VideoPlayerViewModel()
let movieDetails:Film
@Setting(.dismiss) var dismiss
init(movieDetails: Film) {
self.movieDetails = movieDetails
print("Film Element Display")
}
var physique: some View {
ZStack{
Shade(.black.opacity(0.9))
.ignoresSafeArea()
ScrollView(.vertical){
VStack{
VStack(spacing:0) {
Textual content(movieDetails.originalTitle)
.font(.largeTitle)
.padding(.backside,5)
.padding(.prime,25)
.body(maxWidth: .infinity,alignment:.main)
HStack{
Textual content(movieDetails.releaseDate)
Textual content(movieDetails.grownup ? "Rated" : "Not Rated")
.body(maxWidth: .infinity,alignment:.main)
}
.foregroundStyle(.grey)
}
.body(maxWidth: .infinity,alignment:.main)
.padding(.main)
.daring()
ExtractedVideoView()
.surroundings(videoPlayerViewModel)
HStack{
LazyImage(supply: "https://picture.tmdb.org/t/p/w500/(movieDetails.posterPath)") { state in
if let picture = state.picture{
picture
.resizingMode(.aspectFit)
.aspectRatio(contentMode: .fill)
}
}
.scaledToFill()
.body(width: 150,top: 220)
.body(maxHeight: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/,alignment:.topLeading)
NavigationLink(worth: movieDetails.overview) {
Textual content(movieDetails.overview)
.multilineTextAlignment(.main)
.fixedSize(horizontal: false, vertical: true)
.body(maxHeight: .infinity,alignment:.topLeading)
.body(maxWidth: .infinity,alignment:.main)
.body(width: 200)
.foregroundStyle(.white)
.lineLimit(6)
}
}
.padding(.prime)
.padding(.horizontal)
Textual content("(movieDetails.id)")
}
.navigationDestination(for: String.self, vacation spot: { overview in
SummaryView(summanry: overview)
})
.foregroundStyle(.white)
.body(maxWidth: .infinity,maxHeight: .infinity,alignment:.topLeading)
}
.scrollIndicators(.hidden)
}
.job{
Process{
strive await videoPlayerViewModel.getVideoDetails(videoID: movieDetails.id)
}
}
.onAppear{
print(movieDetails.posterPath)
}
.toolbar(content material: {
ToolbarItem(placement: .topBarLeading) {
HStack{
Picture(systemName: "arrow.left")
.onTapGesture {
dismiss()
}
Textual content(movieDetails.originalTitle)
}
//.body(maxWidth: .infinity,alignment:.prime)
.foregroundStyle(.white)
.daring()
.font(.title2)
}
})
.toolbar{
}
}
}
struct MoviesScrollView: View {
// @State var moviesListViewModel = MoviesListViewModel()
@Setting(MoviesListViewModel.self) var moviesListViewModel
var physique: some View {
ScrollView(.horizontal){
HStack(spacing:10) {
ForEach(moviesListViewModel.moviesWeekPopularListArray,id: .id) { knowledge in
if let outcomes = knowledge.outcomes {
ForEach(outcomes, id: .id) { insideData in
NavigationLink(worth: insideData) {
MovieCard(imageURL: insideData.posterPath, ranking: insideData.voteAverage, movieTitle: insideData.title, releaseDate: insideData.releaseDate, viewersCount: insideData.voteCount)
}
}
}
}
}
.padding(.main)
}
.body(maxWidth: .infinity,alignment:.main)
.scrollIndicators(.hidden)
.onAppear{
Process{
strive await moviesListViewModel.getWeeksPopularMoviesList()
}
}
}
}
struct MovieList: Codable,Hashable{
var id = UUID().uuidString
let web page: Int
var outcomes: [Movie]?
let totalPages, totalResults: Int
enum CodingKeys: String, CodingKey {
case web page, outcomes
case totalPages = "total_pages"
case totalResults = "total_results"
}
func hash(into hasher: inout Hasher) {
hasher.mix(outcomes)
}
}
struct Film: Codable,Hashable{
let grownup: Bool
let backdropPath: String?
let genreIDS: [Int]
let id: Int
let originalLanguage, originalTitle, overview: String
let reputation: Double
let posterPath, releaseDate, title: String
let video: Bool
let voteAverage: Double
let voteCount: Int
enum CodingKeys: String, CodingKey {
case grownup
case backdropPath = "backdrop_path"
case genreIDS = "genre_ids"
case id
case originalLanguage = "original_language"
case originalTitle = "original_title"
case overview, reputation
case posterPath = "poster_path"
case releaseDate = "release_date"
case title, video
case voteAverage = "vote_average"
case voteCount = "vote_count"
}
}