Sheet Music on “Present” Mode [iOS]

Can you make the sheet music be right next to each other and fill out the whole screen like the current iOS version. It will allow users to see the sheet music a little better if it auto fits and utilizes the whole screen without having a lot of empty space in the margins and in between the pages

Can you share some screenshots?

:magnifying_glass_tilted_left: Triage & Root Cause Analysis

Thank you for the feedback, @dkladd! We investigated how 2-page Sheet Music spreads (isSideBySide) are laid out and rendered in Fullscreen Present Mode on iOS/iPadOS (HfwFullscreenSheetMusicPresenter), macOS (HfwZoomableScorePageView), and the External Display / AirPlay Stage (HfwExternalStageView).

There are four compounding layout factors creating excessive empty space in the outer margins and between the two pages when presenting a 2-page spread:


1. Each Page Centers Independently Inside Its Half-Screen (contentMode = .scaleAspectFit + .fillEqually)

  • File: packages/hfw_flutter/ios/Runner/HfwHymnDetailViews.swift (lines 1886–1922)
  • In HfwZoomScrollView, stackView uses distribution = .fillEqually and spacing = 10, dividing the screen into two wide containers (leftPageContainer and rightPageContainer), each nearly square on a landscape iPad.
  • Because leftImageView and rightImageView both use contentMode = .scaleAspectFit (lines 1898, 1911) and fill their respective half-width containers, each portrait page is independently centered horizontally inside its own half of the screen.
  • Resulting Gap Math: On a landscape iPad (1366 × 1024), each page container is ~668 pt wide and ~992 pt tall. A portrait score page (aspect ratio ~0.68–0.75) fitted to height renders at ~675–744 pt wide, or on wider aspect ratios (such as 16:9 external displays or iPad Pro 11" 1194 × 834 where each half is 582 × 802 and a page renders at ~545 pt wide), each page leaves unused horizontal letterbox space on both its left and right sides. The inner right margin of the left page and the inner left margin of the right page add together across the center spine—creating a wide empty gap down the middle instead of abutting like an open hymnal book.
  • The same issue occurs on the External Display / AirPlay Stage (packages/hfw_flutter/ios/Runner/HfwExternalDisplayManager.swift, lines 778–813), where both Image views have .frame(maxWidth: .infinity, maxHeight: .infinity) inside an HStack(spacing: 12) (lines 791, 811), centering each page in its 16:9 half-screen and leaving a massive gap in the center.

2. Hardcoded Outer Insets & Inter-Page Spacing in HfwZoomScrollView

  • File: packages/hfw_flutter/ios/Runner/HfwHymnDetailViews.swift (lines 1889–1892 and 1973–1975)
  • stackView applies a fixed spacing = 10 between page containers and insets the entire spread by UIEdgeInsets(top: 8, left: 10, bottom: 24, right: 10):
    stackView.spacing = 10
    stackView.frame = zoomContainerView.bounds.inset(
      by: UIEdgeInsets(top: 8, left: 10, bottom: 24, right: 10)
    )
    
  • macOS Compatibility View: packages/hfw_flutter/ios/Runner/HfwPlatformCompat.swift (lines 585, 621–623) similarly hardcodes HStack(spacing: 10) plus .padding(.horizontal, 10), .padding(.top, 8), and .padding(.bottom, 24).
  • External Stage View: packages/hfw_flutter/ios/Runner/HfwExternalDisplayManager.swift (lines 778, 814, 836) uses HStack(spacing: 12) and .padding(16) around the score pages.
  • While the 24 pt bottom inset was originally intended for the inline tab pager indicator, HfwFullscreenSheetMusicPresenter hides page indicators (showIndicators: false, HfwPresenterAndPitchViews.swift:2606, 2704) and uses floating HUD overlays that can be toggled off—so these permanent insets shrink the maximum height and width of the score even when the HUD is hidden.

3. Safe Area Container Clipping in HfwFullscreenSheetMusicPresenter

  • File: packages/hfw_flutter/ios/Runner/HfwPresenterAndPitchViews.swift (lines 2345, 2407–2709)
  • While the background theme.surface.ignoresSafeArea() (line 2408) extends edge-to-edge, the GeometryReader (line 2345) and the TabView / HfwZoomableScorePageView (lines 2502–2709) remain constrained within the iOS safe area insets (status bar / top & bottom home indicator regions), preventing the sheet music canvas from utilizing 100% of the physical screen height and width in Present mode.

4. Baked-in Whitespace Margins in Rendered Sheet Music PNGs

  • The source sheet music PNGs in the .hymn bundles include standard print page margins around the engraved staff systems.
  • When two pages are placed side by side without margin trimming or spine abutment, the right print margin of Page 1 + stackView.spacing + horizontal aspect-fit centering + the left print margin of Page 2 all accumulate between the two pages.

:hammer_and_wrench: Proposed Fixes & Implementation Plan

  1. Abut Pages Together at the Center Spine (Book-Spread Layout):

    • Instead of centering each page independently within bounds.width / 2 (distribution = .fillEqually), compute the exact aspect-fitted rect for the 2-page spread as a unified pair (or align the left page to .right / trailing edge of the left half and the right page to .left / leading edge of the right half with 0–2 pt spine gap).
    • Update HfwAnnotationCanvasUIView.resolvedDrawingRect() (HfwPresenterAndPitchViews.swift:4169–4177) so annotation stroke normalization maps accurately to the aligned image rect within each page container.
    • In HfwExternalStageView (HfwExternalDisplayManager.swift:778–814), remove .frame(maxWidth: .infinity, maxHeight: .infinity) on the individual page images and reduce HStack(spacing:) from 12 to 0 (or 2), centering the combined 2-page spread tightly in the stage frame.
  2. Eliminate Outer Padding & Inter-Page Gap in Present Mode:

    • Add an isFullscreenPresentation: Bool = false (or contentInsets: UIEdgeInsets / pageSpacing: CGFloat) parameter to HfwZoomableScorePageView and HfwZoomScrollView (HfwHymnDetailViews.swift:1889–1892, 1973–1975, 2147 and HfwPlatformCompat.swift:563–623).
    • In Present Mode (HfwFullscreenSheetMusicPresenter, HfwPresenterAndPitchViews.swift:2502–2709), use .zero outer insets (UIEdgeInsets.zero) and 0 (or 1–2 pt hairline) inter-page spacing so the 2-page spread scales to fill the entire viewport edge-to-edge.
    • Allow the score canvas in HfwFullscreenSheetMusicPresenter to ignore safe area insets when presenting so the sheet music utilizes the full screen height and width.
  3. Auto-Trim / Tight-Crop Redundant Page Whitespace Margins:

    • Add an optional fast alpha/luminance bounding-box trim (cached per page path alongside hfwLoadLocalImage in HfwSearchViews.swift:1039) or inner margin crop for Present Mode so excess outer paper margins and inner gutter margins are minimized, maximizing staff and lyric legibility across the screen.

Cross-Platform Applicability & Audit

Following up on the iOS triage above, I audited the sheet music viewer, fullscreen Present mode, and external stage/cast renderers across all four platforms in the monorepo (iOS/iPadOS, macOS, Android, and Web). Every platform is affected by either the exact same layout issue or a closely related variant:

Platform Inline Sheet Music Fullscreen “Present” Mode External Stage / Cast Status & Key Findings
iOS / iPadOS HfwHymnDetailViews.swift:1886–1975 HfwPresenterAndPitchViews.swift:2345, 2407–2709 HfwExternalDisplayManager.swift:768–838 Affected (Primary Report): UIStackView(distribution: .fillEqually, spacing: 10) centers each .scaleAspectFit page inside its 50%-width column, creating a wide gap down the center spine. Compounded by hardcoded UIEdgeInsets(top: 8, left: 10, bottom: 24, right: 10), safe-area clipping in fullscreen (HfwPresenterAndPitchViews.swift:2693), and baked-in PNG margins (~7%–10% per side).
macOS HfwPlatformCompat.swift:563–636 HfwPresenterAndPitchViews.swift:2522–2557, 2640–2665 HfwExternalDisplayManager.swift:351–391, 768–838 Affected:
• In-app (HfwZoomableScorePageView): Uses HStack(spacing: 10) with .padding(.horizontal, 10), .padding(.top, 8), and .padding(.bottom, 24) (HfwPlatformCompat.swift:580–607). While Image(nsImage:).resizable().scaledToFit() sizes to its aspect-fitted width rather than a 50% screen box, the two pages are still separated by spacing: 10 plus each PNG’s ~7%–10% white margin, and the hardcoded outer padding (top: 8, bottom: 24, horizontal: 10) shrinks the score even inside HfwFullscreenSheetMusicPresenter.
• External Stage Window: Shares HfwExternalStageView (HfwExternalDisplayManager.swift:782–810), which applies .frame(maxWidth: .infinity, maxHeight: .infinity) to each page inside HStack(spacing: 12) + .padding(16), reproducing the exact half-screen centering gap on 16:9 external displays.
Android HfwHymnDetailComposeViews.kt:2500–2533, 3005–3066 HfwHymnDetailComposeViews.kt:4772–5350 HfwCastAndStageManager.kt:612–627, 681–693 Affected (Identical Bug to iOS):
• Fullscreen (HfwFullscreenSheetMusicDialog, lines 5092–5131) & Inline (HfwSheetMusicPagerView, lines 2500–2533): Renders 2-page spreads in a Row (padding(8.dp) / spacedBy(8.dp) in fullscreen; padding(10.dp) / spacedBy(10.dp) inline) where each page is wrapped in Box(modifier = Modifier.weight(1f).fillMaxHeight(), contentAlignment = Alignment.Center) and HfwScorePageBitmapImage (lines 3018–3033) centers the bitmap in BoxWithConstraints(Modifier.fillMaxSize(), contentAlignment = Alignment.Center). On a landscape tablet/foldable, each portrait page centers inside its half-screen weight(1f) box instead of abutting at the spine. Furthermore, when showHud = true (default on launch, line 4786), the top and bottom HUD bars are laid out in a Column above and below the Box(Modifier.weight(1f)) (lines 4879–5029, 5304–5316) rather than overlaying the canvas, vertically compressing the score.
• External Display / Cast (HfwCastAndStageManager.kt:612–627, 681–693): Splits the 1920×1080 canvas into two 948px half-rects (Rect(8, 8, 8 + halfW, height - 8) and Rect(16 + halfW, 8, width - 8, height - 8)) and centers each ~740px-wide portrait page via drawCenteredFitBitmapInBounds, leaving a ~216px gap down the middle of the 16:9 stage output.
Web (hfw_jaspr) hymn_workspace_island_views.dart:1178–1290 packages/hfw_jaspr/web/styles.css:1615–1647, 1689–1723 N/A (Browser Fullscreen / /present route) Affected (Missing 2-Page Spread + Fullscreen Chrome):
• No 2-Page Side-by-Side Spread in Active Component: hymn_workspace_island_views.dart:1178–1290 only renders a single active page (pageIdx == safePageIdx) inside .sheet-page-frame with no 2-page spread toggle (note: legacy CSS for .sheet-pages-stack.has-multiple-pages still exists in build/jaspr/web/styles.css:1616–1647, which used gap: 1rem and padding: 0.45rem, but was removed from web/styles.css).
• Fullscreen Padding & Persistent Bars: In Present / fullscreen mode (.workspace-island.is-fit-screen), .workspace-stage applies padding: 0.75rem 1.15rem; gap: 0.65rem (web/styles.css:1615–1622), .sheet-page-frame.fit-screen adds padding: 0.45rem and a 1px border (web/styles.css:1640–1646, 1689–1697), and .workspace-toolbar, .sheet-pages-quick-bar, and .slide-controls-bar remain in the vertical flex flow alongside the ~7%–10% baked-in PNG whitespace.

Unified Cross-Platform Recommendations

  1. Abutting Book-Spread Alignment (iOS, macOS, Android, Web):
    • In 2-page side-by-side mode, align the left page to the trailing/right edge of its container and the right page to the leading/left edge of its container (or size each page container to its aspect-fitted width inside a centered row with 0–2pt/dp/px spine spacing) so the two pages meet at the center spine like an open hymnal.
    • Apply the same spine-abutting alignment to external 16:9 stage renderers (HfwExternalStageView on iOS/macOS and HfwCastAndStageManager.renderCurrentStageBitmap on Android).
  2. Edge-to-Edge Fullscreen Canvas & Overlay HUD (iOS, macOS, Android, Web):
    • Remove outer container padding (UIEdgeInsets on iOS/macOS, Modifier.padding(8.dp) on Android, .workspace-stage / .sheet-page-frame.fit-screen padding on Web) when in fullscreen Present mode.
    • On Android (HfwFullscreenSheetMusicDialog) and Web (.workspace-island.is-fit-screen), float the top/bottom HUD toolbars as overlays (Box / ZStack / absolute overlay) rather than stacking them in a Column that steals vertical height from the score.
    • On Web, restore or add a 2-page spread option (2-Page toggle or automatic wide-screen spread in hymn_workspace_island_views.dart) that abuts pages at the center spine.
  3. Auto-Trim / Crop Outer PNG Margins in 2-Page Spread Mode (All Platforms):
    • Because the engraved 1980×2850 / 2050×2950 PNGs have ~7%–10% white margins baked into all four sides (~140px–205px left/right), abutting the raw bitmaps still leaves a combined ~14%–20% white gutter at the spine. Trimming or cropping ~50%–65% of the outer white margin (either via a shared crop rect / UV inset at render time or during bundle asset generation) will allow the staves to fill the screen across all platforms.

Cross-Platform Fix Implemented (#24)

Implemented the cross-platform fix for Sheet Music on “Present” Mode across iOS/iPadOS, macOS, Android, and Web (hfw_jaspr):

1. iOS / iPadOS (packages/hfw_flutter/ios/Runner/)

  • HfwHymnDetailViews.swift (lines 1838–2340):
    • Added isFullscreenPresentation: Bool = false to HfwZoomScrollView and HfwZoomableScorePageView.
    • In HfwZoomScrollView.updateStackAndPageFrames(), when isFullscreenPresentation == true, outer stackView insets are set to UIEdgeInsets.zero and stackView.spacing = 0 (2pt inline).
    • In 2-page spread mode (!rightPageContainer.isHidden), computeEdgeAlignedAspectFitRect(...) positions leftImageView.frame + leftAnnotationCanvas.frame directly against the trailing (center-spine) edge of leftPageContainer (alignHorizontal = 1) and rightImageView.frame + rightAnnotationCanvas.frame against the leading (center-spine) edge of rightPageContainer (alignHorizontal = -1). Because targetImageView.frame matches the exact aspect-fitted rect, HfwAnnotationCanvasUIView.resolvedDrawingRect() maps (0..1, 0..1) strokes 1:1 automatically.
  • HfwPresenterAndPitchViews.swift (lines 2516–2748):
    • Passed isFullscreenPresentation: true to HfwZoomableScorePageView across all fullscreen presentation branches and applied .ignoresSafeArea() to the score views and TabView pager so the score uses the full screen edge-to-edge.
  • HfwExternalDisplayManager.swift (lines 777–827):
    • Updated HfwExternalStageView 2-page sheet music spreads to use HStack(spacing: 0) with .padding(0), aligning the left page to .trailing and the right page to .leading so both pages abut at the center spine on external AirPlay/HDMI displays.

2. macOS (packages/hfw_flutter/ios/Runner/)

  • HfwPlatformCompat.swift (lines 563–636):
    • Added isFullscreenPresentation: Bool = false to macOS HfwZoomableScorePageView.
    • Changed the spread stack to HStack(spacing: isFullscreenPresentation ? 0 : 4) and zeroed outer .padding(.horizontal / .top / .bottom) when isFullscreenPresentation == true.
  • HfwPresenterAndPitchViews.swift (lines 2553–2690) & HfwExternalDisplayManager.swift (lines 777–827):
    • Enabled isFullscreenPresentation: true and .ignoresSafeArea() in macOS HfwFullscreenSheetMusicPresenter and shared HfwExternalStageView.

3. Android (packages/hfw_flutter/android/app/src/main/kotlin/com/appleeducate/hfw/)

  • HfwHymnDetailComposeViews.kt (lines 2500–2545, 3009–3071, 5122–5185):
    • Added contentAlignment: Alignment = Alignment.Center to HfwScorePageBitmapImage and forwarded it to both BoxWithConstraints (annotated view) and Image (unannotated view).
    • In HfwFullscreenSheetMusicDialog and HfwSheetMusicPagerView, aligned the left page to Alignment.CenterEnd and the right page to Alignment.CenterStart with Arrangement.spacedBy(0.dp) and Modifier.padding(0.dp) in fullscreen mode so 2-page spreads abut at the center spine.
  • HfwCastAndStageManager.kt (lines 620–638, 692–718):
    • Added drawAlignedFitBitmapInBounds(...) and updated renderCurrentStageBitmap to align the left page bitmap against the center spine (Rect(0, 0, width / 2, height), alignHorizontal = 1) and the right page bitmap against the center spine (Rect(width / 2, 0, width, height), alignHorizontal = -1), eliminating the 216px gap on 16:9 HDMI/Cast displays.

4. Web (packages/hfw_jaspr/)

  • lib/components/hymn_workspace_island_views.dart (lines 1185–1285) & web/styles.css (lines 1615–1760):
    • Added has-multiple-pages to .sheet-page-frame and is-spread-left / is-spread-right to the active 2-page spread images (spreadLeftIdx = (safePageIdx ~/ 2) * 2, spreadRightIdx = spreadLeftIdx + 1).
    • Updated .workspace-island.is-fit-screen .workspace-stage and .sheet-page-frame.fit-screen to remove excess outer padding and display 2-page spreads side-by-side abutting at the center spine (gap: 0, margin: 0) on wide viewports (@media (min-width: 960px) and (min-height: 540px)).