fixed life cycle issue

add LazyView
This commit is contained in:
PangMo5 2021-05-28 13:10:01 +09:00
parent 4dae6bc00e
commit e4f627baeb
7 changed files with 82 additions and 36 deletions

View File

@ -46,6 +46,7 @@
62133890265F83A900A81A2A /* LibraryListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6213388F265F83A900A81A2A /* LibraryListView.swift */; }; 62133890265F83A900A81A2A /* LibraryListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6213388F265F83A900A81A2A /* LibraryListView.swift */; };
621338932660107500A81A2A /* String++.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621338922660107500A81A2A /* String++.swift */; }; 621338932660107500A81A2A /* String++.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621338922660107500A81A2A /* String++.swift */; };
62133895266096EF00A81A2A /* LibraryListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62133894266096EF00A81A2A /* LibraryListViewModel.swift */; }; 62133895266096EF00A81A2A /* LibraryListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62133894266096EF00A81A2A /* LibraryListViewModel.swift */; };
621338B32660A07800A81A2A /* LazyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621338B22660A07800A81A2A /* LazyView.swift */; };
6273DD43265F4195009C1D0B /* Moya in Frameworks */ = {isa = PBXBuildFile; productRef = 6273DD42265F4195009C1D0B /* Moya */; }; 6273DD43265F4195009C1D0B /* Moya in Frameworks */ = {isa = PBXBuildFile; productRef = 6273DD42265F4195009C1D0B /* Moya */; };
6273DD45265F4195009C1D0B /* CombineMoya in Frameworks */ = {isa = PBXBuildFile; productRef = 6273DD44265F4195009C1D0B /* CombineMoya */; }; 6273DD45265F4195009C1D0B /* CombineMoya in Frameworks */ = {isa = PBXBuildFile; productRef = 6273DD44265F4195009C1D0B /* CombineMoya */; };
6273DD48265F41B3009C1D0B /* JellyfinAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6273DD47265F41B3009C1D0B /* JellyfinAPI.swift */; }; 6273DD48265F41B3009C1D0B /* JellyfinAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6273DD47265F41B3009C1D0B /* JellyfinAPI.swift */; };
@ -114,6 +115,7 @@
6213388F265F83A900A81A2A /* LibraryListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibraryListView.swift; sourceTree = "<group>"; }; 6213388F265F83A900A81A2A /* LibraryListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibraryListView.swift; sourceTree = "<group>"; };
621338922660107500A81A2A /* String++.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String++.swift"; sourceTree = "<group>"; }; 621338922660107500A81A2A /* String++.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String++.swift"; sourceTree = "<group>"; };
62133894266096EF00A81A2A /* LibraryListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibraryListViewModel.swift; sourceTree = "<group>"; }; 62133894266096EF00A81A2A /* LibraryListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibraryListViewModel.swift; sourceTree = "<group>"; };
621338B22660A07800A81A2A /* LazyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazyView.swift; sourceTree = "<group>"; };
6273DD47265F41B3009C1D0B /* JellyfinAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JellyfinAPI.swift; sourceTree = "<group>"; }; 6273DD47265F41B3009C1D0B /* JellyfinAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JellyfinAPI.swift; sourceTree = "<group>"; };
6273DD4D265F47B2009C1D0B /* LibrarySearchViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibrarySearchViewModel.swift; sourceTree = "<group>"; }; 6273DD4D265F47B2009C1D0B /* LibrarySearchViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibrarySearchViewModel.swift; sourceTree = "<group>"; };
AE8C3153265D60BF008AA076 /* SettingsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsModel.swift; sourceTree = "<group>"; }; AE8C3153265D60BF008AA076 /* SettingsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsModel.swift; sourceTree = "<group>"; };
@ -162,6 +164,7 @@
5377CBF3263B596A003A4E83 /* JellyfinPlayer */ = { 5377CBF3263B596A003A4E83 /* JellyfinPlayer */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
621338B12660A06F00A81A2A /* SwiftUI */,
621338912660106C00A81A2A /* Extensions */, 621338912660106C00A81A2A /* Extensions */,
6273DD4A265F4794009C1D0B /* Domains */, 6273DD4A265F4794009C1D0B /* Domains */,
6273DD46265F419B009C1D0B /* APIs */, 6273DD46265F419B009C1D0B /* APIs */,
@ -239,6 +242,14 @@
path = Extensions; path = Extensions;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
621338B12660A06F00A81A2A /* SwiftUI */ = {
isa = PBXGroup;
children = (
621338B22660A07800A81A2A /* LazyView.swift */,
);
path = SwiftUI;
sourceTree = "<group>";
};
6273DD46265F419B009C1D0B /* APIs */ = { 6273DD46265F419B009C1D0B /* APIs */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -420,6 +431,7 @@
53E4E649263F725B00F67C6B /* MultiSelector.swift in Sources */, 53E4E649263F725B00F67C6B /* MultiSelector.swift in Sources */,
53E4E647263F6CF100F67C6B /* LibraryFilterView.swift in Sources */, 53E4E647263F6CF100F67C6B /* LibraryFilterView.swift in Sources */,
6213388E265F777C00A81A2A /* LibraryViewModel.swift in Sources */, 6213388E265F777C00A81A2A /* LibraryViewModel.swift in Sources */,
621338B32660A07800A81A2A /* LazyView.swift in Sources */,
62133895266096EF00A81A2A /* LibraryListViewModel.swift in Sources */, 62133895266096EF00A81A2A /* LibraryListViewModel.swift in Sources */,
6273DD48265F41B3009C1D0B /* JellyfinAPI.swift in Sources */, 6273DD48265F41B3009C1D0B /* JellyfinAPI.swift in Sources */,
53892777263CBB000035E14B /* JellyApiTypings.swift in Sources */, 53892777263CBB000035E14B /* JellyApiTypings.swift in Sources */,

View File

@ -220,8 +220,10 @@ struct ContentView: View {
Text("Latest \(library_names[library_id] ?? "")").font(.title2).fontWeight(.bold) Text("Latest \(library_names[library_id] ?? "")").font(.title2).fontWeight(.bold)
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 16)) .padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 16))
Spacer() Spacer()
NavigationLink(destination: LibraryView(viewModel: .init(filter: Filter(parentID: library_id)), NavigationLink(destination: LazyView {
title: library_names[library_id] ?? "")) { LibraryView(viewModel: .init(filter: Filter(parentID: library_id)),
title: library_names[library_id] ?? "")
}) {
Text("See All").font(.subheadline).fontWeight(.bold) Text("See All").font(.subheadline).fontWeight(.bold)
} }
}.padding(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16)) }.padding(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16))

View File

@ -345,10 +345,12 @@ struct EpisodeItemView: View {
HStack { HStack {
Text("Genres:").font(.callout).fontWeight(.semibold) Text("Genres:").font(.callout).fontWeight(.semibold)
ForEach(fullItem.Genres, id: \.Id) { genre in ForEach(fullItem.Genres, id: \.Id) { genre in
NavigationLink(destination: LibraryView(viewModel: .init(filter: Filter(genres: [ NavigationLink(destination: LazyView {
genre LibraryView(viewModel: .init(filter: Filter(genres: [
.Name, genre
])), title: genre.Name)) { .Name,
])), title: genre.Name)
}) {
Text(genre.Name).font(.footnote) Text(genre.Name).font(.footnote)
} }
} }
@ -362,10 +364,12 @@ struct EpisodeItemView: View {
HStack { HStack {
Spacer().frame(width: 16) Spacer().frame(width: 16)
ForEach(fullItem.Cast, id: \.Id) { cast in ForEach(fullItem.Cast, id: \.Id) { cast in
NavigationLink(destination: LibraryView(viewModel: .init(filter: Filter(personIds: [ NavigationLink(destination: LazyView {
cast LibraryView(viewModel: .init(filter: Filter(personIds: [
.Id, cast
])), title: cast.Name)) { .Id,
])), title: cast.Name)
}) {
VStack { VStack {
WebImage(url: cast.Image) WebImage(url: cast.Image)
.resizable() // Resizable like SwiftUI.Image, you must use this modifier or the view will use the image bitmap size .resizable() // Resizable like SwiftUI.Image, you must use this modifier or the view will use the image bitmap size
@ -564,10 +568,12 @@ struct EpisodeItemView: View {
HStack { HStack {
Text("Genres:").font(.callout).fontWeight(.semibold) Text("Genres:").font(.callout).fontWeight(.semibold)
ForEach(fullItem.Genres, id: \.Id) { genre in ForEach(fullItem.Genres, id: \.Id) { genre in
NavigationLink(destination: LibraryView(viewModel: .init(filter: Filter(genres: [ NavigationLink(destination: LazyView {
genre LibraryView(viewModel: .init(filter: Filter(genres: [
.Name, genre
])), title: genre.Name)) { .Name,
])), title: genre.Name)
}) {
Text(genre.Name).font(.footnote) Text(genre.Name).font(.footnote)
} }
} }
@ -582,10 +588,12 @@ struct EpisodeItemView: View {
HStack { HStack {
Spacer().frame(width: 16) Spacer().frame(width: 16)
ForEach(fullItem.Cast, id: \.Id) { cast in ForEach(fullItem.Cast, id: \.Id) { cast in
NavigationLink(destination: LibraryView(viewModel: .init(filter: Filter(personIds: [ NavigationLink(destination: LazyView {
cast LibraryView(viewModel: .init(filter: Filter(personIds: [
.Id, cast
])), title: cast.Name)) { .Id,
])), title: cast.Name)
}) {
VStack { VStack {
WebImage(url: cast.Image) WebImage(url: cast.Image)
.resizable() // Resizable like SwiftUI.Image, you must use this modifier or the view will use the image bitmap size .resizable() // Resizable like SwiftUI.Image, you must use this modifier or the view will use the image bitmap size

View File

@ -20,22 +20,22 @@ struct LibraryListView: View {
List(viewModel.libraryIDs, id: \.self) { id in List(viewModel.libraryIDs, id: \.self) { id in
switch id { switch id {
case "favorites": case "favorites":
NavigationLink(destination: LibraryView(viewModel: .init(filter: Filter(filterTypes: [.isFavorite])), NavigationLink(destination: LazyView { LibraryView(viewModel: .init(filter: Filter(filterTypes: [.isFavorite])),
title: viewModel.libraryNames[id] ?? "")) { title: viewModel.libraryNames[id] ?? "") }) {
Text(viewModel.libraryNames[id] ?? "").foregroundColor(Color.primary) Text(viewModel.libraryNames[id] ?? "").foregroundColor(Color.primary)
} }
case "genres": case "genres":
Text(viewModel.libraryNames[id] ?? "").foregroundColor(Color.primary) Text(viewModel.libraryNames[id] ?? "").foregroundColor(Color.primary)
default: default:
NavigationLink(destination: LibraryView(viewModel: .init(filter: Filter(parentID: id)), NavigationLink(destination: LazyView { LibraryView(viewModel: .init(filter: Filter(parentID: id)),
title: viewModel.libraryNames[id] ?? "")) { title: viewModel.libraryNames[id] ?? "") }) {
Text(viewModel.libraryNames[id] ?? "").foregroundColor(Color.primary) Text(viewModel.libraryNames[id] ?? "").foregroundColor(Color.primary)
} }
} }
} }
.navigationTitle("All Media") .navigationTitle("All Media")
.navigationBarItems(trailing: .navigationBarItems(trailing:
NavigationLink(destination: LibrarySearchView(viewModel: .init(filter: .init()))) { NavigationLink(destination: LazyView { LibrarySearchView(viewModel: .init(filter: .init())) }) {
Image(systemName: "magnifyingglass") Image(systemName: "magnifyingglass")
}) })
} }

View File

@ -96,7 +96,7 @@ struct LibraryView: View {
Image(systemName: "chevron.right") Image(systemName: "chevron.right")
} }
} }
NavigationLink(destination: LibrarySearchView(viewModel: .init(filter: viewModel.filter))) { NavigationLink(destination: LazyView { LibrarySearchView(viewModel: .init(filter: viewModel.filter)) }) {
Image(systemName: "magnifyingglass") Image(systemName: "magnifyingglass")
} }
Button { Button {

View File

@ -434,11 +434,13 @@ struct MovieItemView: View {
HStack { HStack {
Text("Genres:").font(.callout).fontWeight(.semibold) Text("Genres:").font(.callout).fontWeight(.semibold)
ForEach(fullItem.Genres, id: \.Id) { genre in ForEach(fullItem.Genres, id: \.Id) { genre in
NavigationLink(destination: LibraryView(viewModel: .init(filter: Filter(genres: [ NavigationLink(destination: LazyView {
LibraryView(viewModel: .init(filter: Filter(genres: [
genre genre
.Name, .Name,
])), ])),
title: genre.Name)) { title: genre.Name)
}) {
Text(genre.Name).font(.footnote) Text(genre.Name).font(.footnote)
} }
} }
@ -452,10 +454,12 @@ struct MovieItemView: View {
HStack { HStack {
Spacer().frame(width: 16) Spacer().frame(width: 16)
ForEach(fullItem.Cast, id: \.Id) { cast in ForEach(fullItem.Cast, id: \.Id) { cast in
NavigationLink(destination: LibraryView(viewModel: .init(filter: Filter(personIds: [ NavigationLink(destination: LazyView {
cast LibraryView(viewModel: .init(filter: Filter(personIds: [
.Id, cast
])), title: cast.Name)) { .Id,
])), title: cast.Name)
}) {
VStack { VStack {
WebImage(url: cast.Image) WebImage(url: cast.Image)
.resizable() // Resizable like SwiftUI.Image, you must use this modifier or the view will use the image bitmap size .resizable() // Resizable like SwiftUI.Image, you must use this modifier or the view will use the image bitmap size
@ -653,11 +657,13 @@ struct MovieItemView: View {
HStack { HStack {
Text("Genres:").font(.callout).fontWeight(.semibold) Text("Genres:").font(.callout).fontWeight(.semibold)
ForEach(fullItem.Genres, id: \.Id) { genre in ForEach(fullItem.Genres, id: \.Id) { genre in
NavigationLink(destination: LibraryView(viewModel: .init(filter: Filter(genres: [ NavigationLink(destination: LazyView {
LibraryView(viewModel: .init(filter: Filter(genres: [
genre genre
.Name, .Name,
])), ])),
title: genre.Name)) { title: genre.Name)
}) {
Text(genre.Name).font(.footnote) Text(genre.Name).font(.footnote)
} }
} }
@ -672,10 +678,12 @@ struct MovieItemView: View {
HStack { HStack {
Spacer().frame(width: 16) Spacer().frame(width: 16)
ForEach(fullItem.Cast, id: \.Id) { cast in ForEach(fullItem.Cast, id: \.Id) { cast in
NavigationLink(destination: LibraryView(viewModel: .init(filter: Filter(personIds: [ NavigationLink(destination: LazyView {
cast LibraryView(viewModel: .init(filter: Filter(personIds: [
.Id, cast
])), title: cast.Name)) { .Id,
])), title: cast.Name)
}) {
VStack { VStack {
WebImage(url: cast.Image) WebImage(url: cast.Image)
.resizable() // Resizable like SwiftUI.Image, you must use this modifier or the view will use the image bitmap size .resizable() // Resizable like SwiftUI.Image, you must use this modifier or the view will use the image bitmap size

View File

@ -0,0 +1,16 @@
//
// LazyView.swift
// JellyfinPlayer
//
// Created by PangMo5 on 2021/05/28.
//
import Foundation
import SwiftUI
struct LazyView<Content: View>: View {
var content: () -> Content
var body: some View {
self.content()
}
}