Repository navigation
fix: read px as CSS pixels on foreign children - #171
Merged
Merged
Conversation
A plain NativeScript child of a Mason container (Svg, Canvas, ...) kept core's meaning of px, device pixels, while Mason's own views read px as CSS pixels. `width: 22px` on an Svg was a third of the size on a 3x screen. The foreign Style setters now turn px into a dip number before core stores it, so core's measure (iOS measureChild), Android's LayoutParams and the Windows XAML box agree with the Mason leaf. A px value set before adoption is rewritten through its own value source, keeping CSS/local/keyframe precedence. Windows converts width, height, min/max and margins too, but still leaves copying them to its panels.
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.
Problem
Inside a Mason container,
pxmeant two different things. Mason's own views read it as CSS pixels. Plain NativeScript children (Svg,Canvas, any other foreign view) kept core's meaning, which is device pixels. Soclass="size-[22px]"on an<Svg>was about 7 dip on a 3x screen, a third of the same class on a Mason view. This came up in nativescript-hallow26.Fix
foreign-layout.ts: the foreign Style setters now turnpxinto a dip number before core stores it. Converting only the value written to the Mason leaf would not be enough, because core still uses its own copy:View.measureChild, which useseffectiveWidth.LayoutParams, which core sets.Width/Heightfrom the XAML element.A
pxvalue set before adoption is rewritten through the channel it came from (CSS, local or keyframe), so precedence is unchanged. This neededsourceKeyon aCssPropertyandsourceon aCssAnimationProperty.Windows now converts width, height, min/max sizes and margins as well, but it still leaves copying them to its panels.
Limits
pxas device pixels.pxvalue is shadowed by an inline value before adoption, only the inline value is converted. If the inline value is later unset, the CSS value comes back as device pixels.Testing
npm test: 62 files, 1290 passed.tsc --noEmiton masonkit: clean.