Skip to content

Conversation

@Twinsen81
Copy link
Contributor

@Twinsen81 Twinsen81 commented Sep 23, 2025

Description

This PR extends the ComposePlaceholderAdapter interface with new optional methods that provide enhanced control over placeholder sizing and measurement, while maintaining full backwards compatibility with existing implementations.

Problem

Previously, placeholder sizing was limited to basic width/height calculations, which could lead to:

  • Layout flicker when content requires multiple measurement passes
  • Inability to properly size wrap-content composables

Solution

New optional methods in ComposePlaceholderAdapter. All methods have defaults that preserve existing behavior.

  • sizingPolicy() - Returns sizing hints to optimize measurement (Unknown - Uses legacy behavior)
  • MatchWidthWrapContentHeight - pre-measures content for accurate height
  • AspectRatio - calculates height from width * ratio
  • FixedHeightPx - sets explicit height in pixels
  • preComposeMeasureHeight() - allows adapters to pre-measure their content offscreen before first paint, eliminating flicker
  • bottomSpacingPx() - adds visual spacing after placeholders without requiring redraws
  • overlayPaddingPx() - customizes padding around the overlay view (defaults to 10px matching the current padding)
  • contentHeightAdjustmentPx() - fine-tunes height to prevent clipping from rounding differences

Implementation Details

The ComposePlaceholderManager now checks the sizingPolicy() and branches accordingly:

  • When sizingPolicy() == Unknown (default), it uses the exact trunk logic, including the EDITOR_INNER_PADDING subtraction
  • For other policies, it uses the enhanced measurement path with customizable padding and spacing

Backwards Compatibility

Existing clients require no changes:

  • All new methods have default implementations
  • Default sizingPolicy() returns Unknown, triggering legacy code path
  • Legacy path matches trunk behavior exactly (verified line-by-line)
  • Default padding values match trunk's hardcoded values

Migration Guide

Existing implementations continue to work unchanged. To opt into new features:

  override fun sizingPolicy(attrs: AztecAttributes) =
      SizingPolicy.MatchWidthWrapContentHeight

  // Optional: Customize padding
  override fun overlayPaddingPx(attrs: AztecAttributes) =
      OverlayPadding(left = 16, top = 16, right = 16, bottom = 16)

Test

Either check out this branch and the client's one to test locally, or just review the code; the testing will be done in the client's PR.

@Twinsen81 Twinsen81 marked this pull request as ready for review September 23, 2025 20:42
Copy link
Contributor

@planarvoid planarvoid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this with the DayOne branch and everything looks good

@Twinsen81 Twinsen81 merged commit 6bc0048 into trunk Sep 24, 2025
11 of 14 checks passed
@Twinsen81 Twinsen81 deleted the plokhoves/add-compose-measure-functions branch September 24, 2025 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants