Repository navigation
fix(swiftui): map Image.fit with CSS object-fit semantics, as a2ui_flutter does - #4097
Merged
Merged
Conversation
…utter does The catalog default fit "fill" mapped to aspect-fill, which crops instead of stretching, "none" took the same path, and "scaleDown" scaled small images up. Add A2UIImage.Fit, which resolves the property and lays the image out with object-fit rules. The feature variants size their frame from the image's aspect ratio, like an <img> with an automatic height, so "fill" does not stretch an image when a scroll view leaves the height open. The avatar and header variants now honor an explicit fit and still default to cover.
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a new Fit enum to A2UIImage to support CSS object-fit semantics (contain, cover, fill, none, scaleDown) and adds corresponding unit tests. Feedback on the changes highlights two key issues: first, the need to re-apply .clipped() to several feature variants to prevent overflow bleeding; second, a layout constraint issue in aspectBox that breaks cover and fill behaviors when the frame height is capped, which can be resolved by conditionally applying the aspect-ratio container.
pinieb
reviewed
Nov 10, 2026
…s upscaling The header variant reported the fitted image's width, so a wide banner with cover or none pushed its column wider than the container. It now sizes a 200-point slot with Color.clear and fits the image in an overlay. The feature variants sized their aspect-ratio box with an aspect-fit image, which scales a small image up to the full width. The box now uses scaleDown, like max-width: 100%; height: auto on the web. Fit and applyVariantSizing are package instead of public, the fallback in Fit.init is a guard and a switch, and the tests lay out each variant.
8 tasks done
pinieb
added a commit
that referenced
this pull request
Nov 13, 2026
# Description Backfills missing `## Unreleased` entries in [`swift/CHANGELOG.md`](https://github.com/a2ui-project/a2ui/blob/b52b2cda6/swift/CHANGELOG.md?plain=1#L5-L58) for Swift pull requests that merged since [`v0.10.0+swift`](https://github.com/a2ui-project/a2ui/releases/tag/v0.10.0%2Bswift) (`ae2b6baae`) while [#4133](#4133) was open or shortly after it landed: 1. [#4140](#4140), [#4037](#4037), and [#4044](#4044) (**BREAKING CHANGE**): Gate component `metadata` and `catalogId` envelope handling to v1.0 and later surfaces, and support `@catalogId`, `@metadata`, `@accessibility`, and `@checks` on v1.0 components with dual-read fallback for undeclared bare keys. 2. [#4022](#4022) (**BREAKING CHANGE**): Migrate `A2UIAudioPlayerModel` and `A2UIVideoPlayerModel` from `ObservableObject` to `@Observable`, take direct model instances in `A2UIAudioPlayer.init(node:model:)` and `A2UIVideo.init(node:model:)`, skip redundant `AVPlayer` seeks during `A2UIAudioPlayer` playback, and adopt `ContentUnavailableView` and a poster play button accessibility label in `A2UIVideo`. 3. [#4030](#4030): Inherit the enclosing function's resolved `catalogId` for catalogless calls inside v1.0 `FormatStringFunction` `${...}` template expressions, add `DataContext.activeFunctionCatalogID` and `FunctionHandler.resolvedFunctionCatalogID(forCallCatalogID:)`, and scope `RPCHandler` `callRendererFunction` evaluation to the target catalog. 4. [#4092](#4092): Include `$defs.anyComponent` and `$defs.anyFunction` unions in v1.0 or later inline catalogs emitted by `MessageProcessor.getRendererCapabilities(options:)`. 5. [#4097](#4097): Map `A2UIImage` `fit` values (`contain`, `cover`, `fill`, `none`, `scaleDown`) to CSS `object-fit` semantics and fix variant sizing in `BasicCatalogSwiftUI`. 6. [#4099](#4099): Drop `theme` from v1.0 `createSurface` payloads when `ValidationConfig.allowUnknownElements` is `true` and add `allowUnknownElements` overloads to `VersionAdapter` and `BaseVersionAdapter`. ## Pre-launch Checklist One time: - [x] I signed the [CLA]. - [x] I read the [Contributors Guide]. - [x] I read the [Style Guide]. - [x] I have built and run at least one [sample]. For this PR: - [x] I have updated the relevant CHANGELOG.md file. - [x] I updated/added relevant documentation. - [x] My code changes (if any) have tests. - [x] If my branch is on a fork, I have verified that [scripts/e2e_test.sh](https://github.com/a2ui-project/a2ui/blob/main/scripts/e2e_test.sh) passes. If you need help, consider asking for advice on the [discussion board]. <!-- Links --> [CLA]: https://cla.developers.google.com/ [Contributors Guide]: https://github.com/a2ui-project/a2ui/blob/main/CONTRIBUTING.md [discussion board]: https://github.com/a2ui-project/a2ui/discussions [Style Guide]: https://github.com/a2ui-project/a2ui/blob/main/CONTRIBUTING.md#coding-style [sample]: https://github.com/a2ui-project/a2ui/blob/main/samples/README.md#samples --------- Signed-off-by: Pete Biencourt <piebie@google.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
A2UIImagemappedfit: "fill"(the catalog default) to aspect-fill, which crops instead of stretching.nonetook the same path, andscaleDownscaled small images up.This PR adds an
A2UIImage.Fitenum (packageaccess), which reads the property and lays the image out with CSSobject-fitrules, as a2ui_flutter does withBoxFit:fillstretches the image to the frame.containscales it to fit, keeping the aspect ratio.coverscales it to cover the frame and clips the overflow.nonekeeps the intrinsic size, centered and clipped.scaleDownusesnoneorcontain, whichever is smaller.The variant frames are unchanged. The
smallFeature,mediumFeatureandlargeFeaturevariants now size the frame from the image's aspect ratio, like an<img>withmax-width: 100%; height: auto, sofilldoesn't stretch an image to the full width when a scroll view leaves the height open, and an image smaller than the frame isn't scaled up. One visible change: when the height is capped (for examplelargeFeatureat 400 points with a tall image), the image keeps its proportions and is letterboxed instead of cropped, as an<img>is on the web.avatarandheadernow honor an explicitfit, andheadercrops a wide image to the container's width instead of widening it. Without an explicitfitthey still default tocover(Flutter does the same forheader, but usesfillforavatar). An unknown value falls back to the default.Tests: the new
A2UIImageTestscover every catalog value, the defaults per variant, unknown values, the laid-out size of each fit for an image smaller and larger than its frame, and the size of theheader,mediumFeatureandlargeFeaturevariants. The fullswift testrun passes, and the sample app builds for the iOS Simulator.Fixes #4096
Pre-launch Checklist
One time:
For this PR:
If you need help, consider asking for advice on the discussion board.