Skip to content

Commit

Permalink
Fix crash when opening the PDF preview for an empty song
Browse files Browse the repository at this point in the history
  • Loading branch information
Desbeers committed Oct 31, 2024
1 parent 78da2c1 commit 220c2b7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
4 changes: 3 additions & 1 deletion Chord Provider/PDFBuild/SongExport/SongExport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ extension SongExport {
items.append(PDFBuild.Spacer(10))
items.append(PDFBuild.SongDetails(song: song))
items.append(PDFBuild.Spacer(10))
items.append(PDFBuild.Chords(chords: song.chords, options: song.settings.diagram))
if !song.chords.isEmpty {
items.append(PDFBuild.Chords(chords: song.chords, options: song.settings.diagram))
}
items.append(PDFBuild.Spacer(10))
/// Add all the sections
for section in song.sections {
Expand Down
55 changes: 30 additions & 25 deletions Chord Provider/Views/SongView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,39 @@ import SwiftUI
@Environment(SceneStateModel.self) private var sceneState
/// The body of the `View`
var body: some View {
VStack {
switch sceneState.settings.song.paging {
case .asList:
ScrollView {
ViewThatFits {
RenderView(
song: sceneState.song,
paging: .asList,
labelStyle: .grid
)
RenderView(
song: sceneState.song,
paging: .asList,
labelStyle: .inline
)
if sceneState.song.sections.isEmpty {
ContentUnavailableView("The Song is Empty", systemImage: "music.quarternote.3")
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else {
VStack {
switch sceneState.settings.song.paging {
case .asList:
ScrollView {
ViewThatFits {
RenderView(
song: sceneState.song,
paging: .asList,
labelStyle: .grid
)
RenderView(
song: sceneState.song,
paging: .asList,
labelStyle: .inline
)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
case .asColumns:
RenderView(
song: sceneState.song,
paging: .asColumns,
labelStyle: .inline
)
}
case .asColumns:
RenderView(
song: sceneState.song,
paging: .asColumns,
labelStyle: .inline
)
}
.contentMargins(.all, sceneState.settings.song.scale * 20, for: .scrollContent)
.contentShape(Rectangle())
.scaleModifier
}
.contentMargins(.all, sceneState.settings.song.scale * 20, for: .scrollContent)
.contentShape(Rectangle())
.scaleModifier
}
}

0 comments on commit 220c2b7

Please sign in to comment.