Skip to content

feat(core): support max-width and max-height CSS properties#11300

Merged
NathanWalker merged 2 commits into
mainfrom
feat/max-width-height
Jul 3, 2026
Merged

feat(core): support max-width and max-height CSS properties#11300
NathanWalker merged 2 commits into
mainfrom
feat/max-width-height

Conversation

@edusperoni

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

NativeScript supports width, height, min-width and min-height, but there is no max-width / max-height. There is no way to cap a view's size — including the common responsive max-width: 100% pattern. The Android flexbox port even contained dead MAX_SIZE /* lp.maxWidth */ placeholders showing the feature was anticipated but never wired up.

What is the new behavior?

Adds first-class max-width / max-height style properties on both iOS and Android, accepting fixed lengths and percentages (e.g. max-width: 200, max-width: 50%).

Because percentages resolve against the parent size, the properties follow the width/height pattern rather than min-*: the effective pixel value is computed at measure time (effectiveMaxWidth / effectiveMaxHeight, defaulting to Infinity = unconstrained). The max clamp is applied after the min clamp, so max wins when min > max, matching CSS.

  • iOS: measure-time clamps in the base view and every layout container, plus a central cap in ViewHelper.getMeasureSpec; wires up the previously-dead MAX_SIZE flexbox placeholders.
  • Android: enforced natively in the org.nativescript.widgets library — maxWidth/maxHeight (+percent) on CommonLayoutParams, clamped in getMeasureSpec and resolved in adjustChildrenLayoutParams, exposed via new ViewHelper setters. The now-shadowing maxWidth/maxHeight fields were removed from FlexboxLayout.LayoutParams so flexbox inherits the unified fields and honors the properties (including percent). widgets-release.aar was rebuilt.

Adds automated tests for style-property parsing/sync, flexbox measure (enabling four previously-stubbed max tests), StackLayout measure, and Label max-width/height including percent.

Implements #1511
Implements #6441

@nx-cloud

nx-cloud Bot commented Jul 2, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit bc41f86

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 4m 23s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-07-02 20:34:43 UTC

Add `max-width` / `max-height` style properties on iOS and Android,
accepting fixed lengths and percentages (e.g. `max-width: 100%`), the
CSS-standard complement to the existing `min-width` / `min-height`.

Because percentages resolve against the parent size, the properties
follow the `width`/`height` pattern rather than `min-*`: the effective
pixel value is computed at measure time in `_updateEffectiveLayoutValues`
(stored as `effectiveMaxWidth`/`effectiveMaxHeight`, defaulting to
Infinity = unconstrained). Applied after the min clamp so `max` wins
when `min > max`, matching CSS.

iOS: measure-time clamps in the base view, all layout containers, and a
central cap in `ViewHelper.getMeasureSpec`; wires up the long-dead
`MAX_SIZE /* lp.maxWidth */` flexbox placeholders.

Android: enforced natively in the widgets library — `maxWidth`/`maxHeight`
(+percent) on `CommonLayoutParams`, clamped in `getMeasureSpec` and
resolved in `adjustChildrenLayoutParams`, exposed via new `ViewHelper`
setters. Removes the now-shadowing `maxWidth`/`maxHeight` fields from
`FlexboxLayout.LayoutParams` so flexbox inherits the unified fields and
honors the properties (including percent). Requires rebuilding
`widgets-release.aar`.

Adds automated tests for style-property parsing/sync, flexbox measure
(enabling four previously-stubbed tests), StackLayout measure, and
Label max-width/height including percent.
@edusperoni edusperoni force-pushed the feat/max-width-height branch 3 times, most recently from 599fd0a to bc41f86 Compare July 2, 2026 20:27
@CatchABus

CatchABus commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

I leave this here for future reference since most people think that {N} fully supports minWidth/minHeight.
The minWidth/minHeight are partial CSS implementations and rather complete android implementations with their corresponding layout limitations which do not match with what CSS does: https://developer.android.com/reference/android/view/View#setMinimumWidth(int)

In simple words, {N} minWidth/minHeight will have no effect if users sets width/height to a fixed size due to how android uses these properties along with its measure modes.

@NathanWalker NathanWalker merged commit 6c158ca into main Jul 3, 2026
9 checks passed
@NathanWalker NathanWalker deleted the feat/max-width-height branch July 3, 2026 19:44
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