Skip to content

Commit a53bad8

Browse files
authored
fix(native): rn-web vertical-align positioning + broaden iOS warning (#5743)
* ci: trim prerelease release notes to changesets new since last tag * fix(native): broaden iOS verticalAlign warning to TextInput * fix(native): use align-content for vertical-align on rn-web * feat(showcase): add TextInput vertical alignment widget * docs(showcase): clarify TextInput alignment summary per-platform * fix(native): use RN-canonical flex-start/flex-end for align-content emission
1 parent 3c34a08 commit a53bad8

9 files changed

Lines changed: 147 additions & 19 deletions

File tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
"styled-components": patch
2+
'styled-components': patch
33
---
44

5-
Development builds now warn when `vertical-align` is set on a native `<Text>` running on iOS.
5+
Development builds now warn when `vertical-align` is set on a native `<Text>` or `<TextInput>` running on iOS.
66

7-
React Native 0.85 has no platform API for vertically aligning text inside a fixed-height `<Text>` on iOS, so the declaration silently has no effect there. Android and rn-web continue to render the property as authored. The warning names the situation and points to the workaround: wrap the Text in a View and use `justify-content` for the vertical alignment.
7+
React Native 0.85 has no platform API for vertically aligning text content inside a fixed-height `<Text>` or `<TextInput>` on iOS, so the declaration silently has no effect there. Android and rn-web continue to render the property as authored. For `<Text>`, the warning points to the workaround: wrap the Text in a View and use `justify-content` for the vertical alignment. `<TextInput>` has no Text-level workaround on iOS today.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'styled-components': patch
3+
---
4+
5+
`vertical-align: top | middle | bottom` on a styled `<Text>` now positions text content within the Text's box on `react-native-web`, matching the visual semantic of React Native's `verticalAlign` on Android (textAlignVertical). Other `vertical-align` values pass through unchanged so the browser's native baseline-shifting semantics still apply.

‎.github/workflows/release.yml‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,38 @@ jobs:
144144
}
145145
}
146146
147+
// Per-package previous tag. Snapshot publishes don't consume
148+
// `.changeset/*.md`, so without this filter every prerelease
149+
// re-emits the full pending pile — including changesets that
150+
// were already announced in earlier prereleases.
151+
const prevTagByPkg = new Map();
152+
for (const pkg of packages) {
153+
let prevTag = '';
154+
try {
155+
prevTag = execSync(`git tag --list '${pkg.name}@*' --sort=-v:refname`, { encoding: 'utf8' })
156+
.split('\n').filter(Boolean)[0] || '';
157+
} catch {}
158+
prevTagByPkg.set(pkg.name, prevTag);
159+
}
160+
161+
// True when `commit` is reachable from `tag` (i.e. already
162+
// shipped in that release). Conservatively returns false on
163+
// any error so unknown commits surface in the next release.
164+
function isCommitInTag(commit, tag) {
165+
if (!commit || !tag) return false;
166+
try {
167+
execSync(`git merge-base --is-ancestor ${commit} ${tag}`, { stdio: 'ignore' });
168+
return true;
169+
} catch {
170+
return false;
171+
}
172+
}
173+
147174
const byPkg = new Map();
148175
for (const cs of changesets) {
149176
for (const release of cs.releases) {
150177
if (release.type === 'none') continue;
178+
if (isCommitInTag(cs.commit, prevTagByPkg.get(release.name))) continue;
151179
let groups = byPkg.get(release.name);
152180
if (!groups) {
153181
groups = { major: [], minor: [], patch: [] };
@@ -171,13 +199,9 @@ jobs:
171199
parts.push('');
172200
}
173201
}
174-
if (parts.length === 0) parts.push('Internal changes only.', '');
202+
if (parts.length === 0) parts.push('No new changes since the previous release.', '');
175203
176-
let prevTag = '';
177-
try {
178-
prevTag = execSync(`git tag --list '${pkg.name}@*' --sort=-v:refname`, { encoding: 'utf8' })
179-
.split('\n').filter(Boolean)[0] || '';
180-
} catch {}
204+
const prevTag = prevTagByPkg.get(pkg.name);
181205
if (prevTag) {
182206
const currentTag = `${pkg.name}@${pkg.version}`;
183207
const compareUrl = `https://github.com/${repo}/compare/${encodeURIComponent(prevTag)}...${encodeURIComponent(currentTag)}`;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import { TextInput } from 'react-native';
3+
import styled from 'styled-components/native';
4+
import { theme as t } from '@/theme/tokens';
5+
6+
const Stack = styled.View`
7+
gap: ${t.space.sm}px;
8+
`;
9+
10+
const Tag = styled.Text`
11+
font-family: ${t.fontFamily.monoStrong};
12+
font-size: ${t.fontSize.monoSm}px;
13+
letter-spacing: 0.6px;
14+
text-transform: uppercase;
15+
color: ${t.colors.fgFaint};
16+
`;
17+
18+
const Field = styled(TextInput)<{ $align: 'top' | 'middle' | 'bottom' }>`
19+
height: 120px;
20+
background-color: ${t.colors.surfaceMuted};
21+
color: ${t.colors.fg};
22+
font-size: 20px;
23+
padding: ${t.space.sm}px;
24+
vertical-align: ${p => p.$align};
25+
`;
26+
27+
const ROWS: ReadonlyArray<'top' | 'middle' | 'bottom'> = ['top', 'middle', 'bottom'];
28+
29+
export function TextInputAlignment() {
30+
return (
31+
<Stack>
32+
{ROWS.map(align => (
33+
<React.Fragment key={align}>
34+
<Tag>multiline TextInput · {align}</Tag>
35+
<Field $align={align} multiline defaultValue="Type here" />
36+
</React.Fragment>
37+
))}
38+
</Stack>
39+
);
40+
}

‎packages/native-showcase/src/widgets/registry.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { SafeAreaInsetsBadge } from './SafeAreaInsetsBadge';
2121
import { ShadowComposer } from './ShadowComposer';
2222
import { StandaloneTransforms } from './StandaloneTransforms';
2323
import { TextDecorationAlignment } from './TextDecorationAlignment';
24+
import { TextInputAlignment } from './TextInputAlignment';
2425
import { TextWrapShelf } from './TextWrapShelf';
2526
import { ThemeOverrides } from './ThemeOverrides';
2627
import { TransformPlayground } from './TransformPlayground';
@@ -230,6 +231,15 @@ export const fidgets: ReadonlyArray<FidgetEntry> = [
230231
category: 'Typography',
231232
Widget: TextDecorationAlignment,
232233
},
234+
{
235+
slug: 'text-input-alignment',
236+
title: 'TextInput vertical alignment',
237+
summary:
238+
'Tall multiline `TextInput` fields with `vertical-align` `top` / `middle` / `bottom`. On Android and rn-web the caret and placeholder should sit at the requested position before any text is typed, and follow the content once the user starts typing. iOS has no `textAlignVertical` API for TextInput in RN 0.85 and the declaration has no effect.',
239+
feature: 'TextInput + textAlignVertical',
240+
category: 'Typography',
241+
Widget: TextInputAlignment,
242+
},
233243
{
234244
slug: 'safe-area-insets-badge',
235245
title: 'Safe-area insets badge',

‎packages/styled-components/src/native/transform/dev.ts‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,12 @@ export function warnIfAndroidSkew(value: unknown): void {
144144
}
145145

146146
/**
147-
* Warn once if `vertical-align` is set on iOS. RN's `Text.js` translates
148-
* `verticalAlign` to `textAlignVertical` at the JS layer, but iOS Fabric
149-
* has no `textAlignVertical` handler (the prop only registers on Android
150-
* via `ReactTextViewManager`). So on iOS the declaration looks like it
151-
* works but never repositions the glyphs. There is no Text-level
152-
* workaround in RN 0.85; wrap the Text in a View and use flex
153-
* justification to vertically align the content within a fixed-height
154-
* container.
147+
* Warn once if `vertical-align` is set on iOS. RN's `Text.js` and
148+
* `TextInput.js` both translate `verticalAlign` to `textAlignVertical`
149+
* at the JS layer, but iOS Fabric exposes no `textAlignVertical`
150+
* handler (`ReactTextViewManager` / `ReactTextInputManager` only
151+
* register the prop on Android). On iOS the declaration looks like it
152+
* works but never repositions the glyphs or the caret.
155153
*
156154
* No-op outside iOS. Callers must wrap in `if (__DEV__)`.
157155
*/
@@ -166,7 +164,7 @@ export function warnIfIosVerticalAlign(value: string): void {
166164
if (os !== 'ios') return;
167165
warnOnce(
168166
'native-vertical-align-ios',
169-
`\`vertical-align: ${value}\` has no effect on iOS \`<Text>\` in React Native 0.85 (no platform API; the prop only renders on Android and rn-web). To vertically align text within a fixed-height container on iOS, wrap the Text in a View with \`justify-content: <flex-start | center | flex-end>\`.`,
167+
`\`vertical-align: ${value}\` has no effect on iOS \`<Text>\` or \`<TextInput>\` in React Native 0.85 (no platform API; the prop only renders on Android and rn-web). For \`<Text>\`, wrap it in a View with \`justify-content: <flex-start | center | flex-end>\` to align glyphs within a fixed-height container. \`<TextInput>\` has no Text-level workaround; iOS positions the caret and content at the platform default.`,
170168
value
171169
);
172170
}

‎packages/styled-components/src/native/transform/index.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ export function camelize(prop: string): string {
5959
// full shorthand set).
6060
import './shorthands.register';
6161

62+
const VERTICAL_ALIGN_TO_ALIGN_CONTENT: Record<
63+
string,
64+
'flex-start' | 'center' | 'flex-end' | undefined
65+
> = {
66+
top: 'flex-start',
67+
middle: 'center',
68+
bottom: 'flex-end',
69+
};
70+
6271
/**
6372
* Transform a single CSS declaration into an RN style partial.
6473
*
@@ -87,6 +96,16 @@ export function transformDecl(prop: string, rawValue: string): Dict<any> {
8796
}
8897
const value = isLayeredCommaProp(camel) ? collapseIdenticalCommas(rawValue) : rawValue;
8998
if (passthroughKeys.length === 1) {
99+
// rn-web's `vertical-align` is baseline-only; emit `align-content`
100+
// for the box-positioning keywords so they reposition content
101+
// like Android's `textAlignVertical`. Other values fall through
102+
// to the browser's native baseline-shifting semantics.
103+
if (__NATIVE_WEB__ && camel === 'verticalAlign') {
104+
const alignContent = VERTICAL_ALIGN_TO_ALIGN_CONTENT[rawValue];
105+
if (alignContent !== undefined) {
106+
return { verticalAlign: value, alignContent };
107+
}
108+
}
90109
return { [passthroughKeys[0]]: value };
91110
}
92111
// Dual-emit (background props): write every key in order so the

‎packages/styled-components/src/native/transform/test/devWarn.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ describe('warnIfIosVerticalAlign', () => {
191191
warnIfIosVerticalAlign('middle');
192192
expect(warnSpy).toHaveBeenCalledTimes(1);
193193
expect(warnSpy.mock.calls[0][0]).toMatch(/`vertical-align: middle` has no effect on iOS/);
194-
expect(warnSpy.mock.calls[0][0]).toMatch(/wrap the Text in a View with `justify-content/);
194+
expect(warnSpy.mock.calls[0][0]).toMatch(/`<Text>` or `<TextInput>`/);
195+
expect(warnSpy.mock.calls[0][0]).toMatch(/wrap it in a View with `justify-content/);
196+
expect(warnSpy.mock.calls[0][0]).toMatch(/`<TextInput>` has no Text-level workaround/);
195197
});
196198

197199
it('warns for top and bottom too', () => {

‎packages/styled-components/src/native/transform/test/passthrough.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,36 @@ describe('passthrough mapping', () => {
124124
});
125125
});
126126

127+
describe('vertical-align align-content polyfill on rn-web', () => {
128+
// CSS Box Alignment L3 §5.3.
129+
const g = global as { __NATIVE_WEB__?: boolean };
130+
const originalNativeWeb = g.__NATIVE_WEB__;
131+
beforeAll(() => {
132+
g.__NATIVE_WEB__ = true;
133+
});
134+
afterAll(() => {
135+
g.__NATIVE_WEB__ = originalNativeWeb;
136+
});
137+
138+
it.each([
139+
['top', 'flex-start'],
140+
['middle', 'center'],
141+
['bottom', 'flex-end'],
142+
])('vertical-align: %s also emits align-content: %s', (value, alignContent) => {
143+
expect(transformDecl('vertical-align', value)).toEqual({
144+
verticalAlign: value,
145+
alignContent,
146+
});
147+
});
148+
149+
it.each([['baseline'], ['sub'], ['super'], ['text-top'], ['text-bottom'], ['auto']])(
150+
'vertical-align: %s passes through unchanged',
151+
value => {
152+
expect(transformDecl('vertical-align', value)).toEqual({ verticalAlign: value });
153+
}
154+
);
155+
});
156+
127157
describe('helpers', () => {
128158
it('getPassthroughKeys returns the array form', () => {
129159
expect(getPassthroughKeys('backgroundImage')).toEqual([

0 commit comments

Comments
 (0)