remove force wrapping

This commit is contained in:
PangMo5 2021-08-06 20:11:31 +09:00
parent 3fa97235b1
commit 6e0bd58e1f
1 changed files with 19 additions and 15 deletions

View File

@ -40,8 +40,8 @@ struct SeriesItemView: View {
.fontWeight(.medium) .fontWeight(.medium)
.foregroundColor(.secondary) .foregroundColor(.secondary)
.lineLimit(1) .lineLimit(1)
if viewModel.item.officialRating != nil { if let officialRating = viewModel.item.officialRating {
Text(viewModel.item.officialRating!).font(.subheadline) Text(officialRating).font(.subheadline)
.fontWeight(.semibold) .fontWeight(.semibold)
.foregroundColor(.secondary) .foregroundColor(.secondary)
.lineLimit(1) .lineLimit(1)
@ -62,16 +62,17 @@ struct SeriesItemView: View {
var innerBody: some View { var innerBody: some View {
ScrollView { ScrollView {
LazyVStack(alignment: .leading, spacing: 0) { LazyVStack(alignment: .leading, spacing: 0) {
if !(viewModel.item.taglines ?? []).isEmpty { if let firstTagline = viewModel.item.taglines?.first {
Text(viewModel.item.taglines!.first!).font(.body).italic() Text(firstTagline).font(.body).italic()
.fixedSize(horizontal: false, vertical: true) .fixedSize(horizontal: false, vertical: true)
.padding(.bottom, 8) .padding(.bottom, 8)
} }
if !(viewModel.item.genreItems ?? []).isEmpty { if let genreItems = viewModel.item.genreItems,
!genreItems.isEmpty {
ScrollView(.horizontal, showsIndicators: false) { ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(spacing: 8) { LazyHStack(spacing: 8) {
Text("Genres:").font(.callout).fontWeight(.semibold) Text("Genres:").font(.callout).fontWeight(.semibold)
ForEach(viewModel.item.genreItems!, id: \.id) { genre in ForEach(genreItems, id: \.id) { genre in
NavigationLink(destination: LazyView { NavigationLink(destination: LazyView {
LibraryView(viewModel: .init(genre: genre), title: genre.name ?? "") LibraryView(viewModel: .init(genre: genre), title: genre.name ?? "")
}) { }) {
@ -98,14 +99,15 @@ struct SeriesItemView: View {
} }
.padding(.bottom, 16) .padding(.bottom, 16)
LazyVStack(alignment: .leading, spacing: 0) { LazyVStack(alignment: .leading, spacing: 0) {
if !(viewModel.item.people ?? []).isEmpty { if let people = viewModel.item.people,
!people.isEmpty {
Text("CAST") Text("CAST")
.font(.callout).fontWeight(.semibold) .font(.callout).fontWeight(.semibold)
.padding(.bottom, 8) .padding(.bottom, 8)
ScrollView(.horizontal, showsIndicators: false) { ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(spacing: 16) { LazyHStack(spacing: 16) {
ForEach(viewModel.item.people!, id: \.self) { person in ForEach(people, id: \.self) { person in
if person.type! == "Actor" { if person.type == "Actor" {
NavigationLink(destination: LazyView { NavigationLink(destination: LazyView {
LibraryView(viewModel: .init(person: person), title: person.name ?? "") LibraryView(viewModel: .init(person: person), title: person.name ?? "")
}) { }) {
@ -117,8 +119,9 @@ struct SeriesItemView: View {
.cornerRadius(10) .cornerRadius(10)
Text(person.name ?? "").font(.footnote).fontWeight(.regular).lineLimit(1) Text(person.name ?? "").font(.footnote).fontWeight(.regular).lineLimit(1)
.frame(width: 100).foregroundColor(Color.primary) .frame(width: 100).foregroundColor(Color.primary)
if person.role != "" { if let role = person.role,
Text(person.role!).font(.caption).fontWeight(.medium).lineLimit(1) !role.isEmpty {
Text(role).font(.caption).fontWeight(.medium).lineLimit(1)
.foregroundColor(Color.secondary).frame(width: 100) .foregroundColor(Color.secondary).frame(width: 100)
} }
} }
@ -129,11 +132,12 @@ struct SeriesItemView: View {
} }
.padding(.bottom, 16) .padding(.bottom, 16)
} }
if !(viewModel.item.studios ?? []).isEmpty { if let studios = viewModel.item.studios,
!studios.isEmpty {
ScrollView(.horizontal, showsIndicators: false) { ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(spacing: 16) { LazyHStack(spacing: 16) {
Text("Studios:").font(.callout).fontWeight(.semibold) Text("Studios:").font(.callout).fontWeight(.semibold)
ForEach(viewModel.item.studios!, id: \.id) { studio in ForEach(studios, id: \.id) { studio in
NavigationLink(destination: LazyView { NavigationLink(destination: LazyView {
LibraryView(viewModel: .init(studio: studio), title: studio.name ?? "") LibraryView(viewModel: .init(studio: studio), title: studio.name ?? "")
}) { }) {
@ -179,8 +183,8 @@ struct SeriesItemView: View {
} else { } else {
GeometryReader { geometry in GeometryReader { geometry in
ZStack { ZStack {
ImageView(src: viewModel.item.getSeriesBackdropImage(maxWidth: 200), ImageView(src: viewModel.item.getBackdropImage(maxWidth: 200),
bh: viewModel.item.getSeriesBackdropImageBlurHash()) bh: viewModel.item.getBackdropImageBlurHash())
.opacity(0.4) .opacity(0.4)
.frame(width: geometry.size.width + geometry.safeAreaInsets.leading + geometry.safeAreaInsets.trailing, .frame(width: geometry.size.width + geometry.safeAreaInsets.leading + geometry.safeAreaInsets.trailing,
height: geometry.size.height + geometry.safeAreaInsets.top + geometry.safeAreaInsets.bottom) height: geometry.size.height + geometry.safeAreaInsets.top + geometry.safeAreaInsets.bottom)