Repository navigation
feat(NitroInput): tabularNums for tabular digits in any font; Android edit text asks for tnum - #72
Merged
Merged
Conversation
…bular digits A font with proportional digits and no tnum (Open Runde) made every typed "1" narrower than the placeholder "0" it replaced, so keepPlaceholder's tail slid left on each keystroke and an amount changed width with its digits. Each digit of such a font is now laid out in a slot as wide as the widest digit, centred, in the overlay, the field's own text, the placeholder, the tail and the JS-thread measure: - Android: a ReplacementSpan per digit (letter spacing can't do it: API 35+ trims it at line edges), only the changed spans touched per keystroke. - iOS: per-character kern plus a first-line indent, the font's pair kerning (which a non-zero kern brings back) taken out. Android's edit text also asks for tnum now, as the paints did, which fixes fonts whose tabular figures are off by default (ABC Diatype). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Default true, as on NitroNumber. false keeps each digit at the font's own width (pnum / kProportionalNumbersSelector), for prose in a proportional face, and skips the digit slots on both platforms. Without the prop a style's fontVariant: ['proportional-nums'] turns it off, as on TextInput. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Unset (the default) the field asks for the font's tabular figures, at no cost, as before; true also lays out every digit as wide as the widest for a font without them (the slots, a little work per change); false asks for the proportional figures. Natively the two halves are tabularNums (tnum) and slotDigits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Problem
In a font with proportional digits, the
keepPlaceholdertail shifted while typing. Reproduced with the example's Open Runde, which is byte-identical to Uno's:1171178into a0000 0000 0000mask moved the tail's end from 172.6 to 158.1 dp on Android and from 173.0 to 159.7 pt on iOS.Open Runde ships no
tnumat all; the request is open upstream as lauridskern/open-runde#10. Uno's ABC Diatype hastnum, but it's off by default, and Android's edit text never asked for it.Changes
tabularNumsproptruefalsefontVariant: ['proportional-nums']means the same.Natively these are two props:
tabularNums(requesttnum) andslotDigits(lay digits out in slots).Android:
tnumon the edit text (always on)The overlay's paints already asked for
tnum, but the edit text didn't. That alone fixes the shift for Diatype.How the slots work
ReplacementSpanper digit, and only the changed spans are touched per keystroke. The spans areNoCopySpan, so they never leave with copied text.letter_spacing_justification)..kern, plus a first-line indent for the first digit's leading half.Verification
Tail end per keystroke with
tabularNums, typing7474 1178(dp / pt):tabularNums, an Open Runde mask keeps its width whatever digits are typed (plain and reflow), plus a first-layout case;false, digits keep their own widths.fontVariant. Typecheck clean.setAttributedText:ran async on a focused field ([iOS][Fabric] TextInput drops a keystroke right after the first character typed into an empty field (_textOf:equals: compares attributes of a focused field) react/react-native#58904); ours runs inside our own edit handler.tabularNumsin Open Runde:false: none.Known limits
tabularNumsand a non-zeroletterSpacingon Android 15+, the mask's separator space still moves the tail by about 1 dp, because the platform trims that space's spacing.🤖 Generated with Claude Code