Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ describe('differential parity', () => {
expect(normalize(boost.props)).toEqual(normalize(wrapper.props));
});

it('Text: static userSelect overrides selectable from a later spread', async () => {
const jsx =
'<Text aria-disabled={_b0} style={{ verticalAlign: "middle", fontWeight: 400, userSelect: "none", width: 10 }} selectionColor={"blue"} {..._s0}>hello</Text>';
const preamble = 'const _b0 = false;\nconst _s0 = { selectable: true };';
const boost = await captureBoost(os, jsx, preamble);
expect(boost.optimized).toBe(true);
if (!boost.optimized) throw new Error('expected Text static userSelect spread case to optimize');
const wrapper = await captureWrapper(os, jsx, preamble);
expect(boost.which).toEqual(wrapper.which);
expect(normalize(boost.props)).toEqual(normalize(wrapper.props));
});

it.each(VIEW_CASES)('View: %s', async (jsx) => {
const boost = await captureBoost(os, jsx);
expect(boost.optimized).toBe(!BAILED_VIEW_CASES.has(jsx));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
} from 'react-native-boost/runtime';
import { Text } from 'react-native';
<_NativeText
selectable={true}
style={{
color: 'red',
}}
allowFontScaling={true}
ellipsizeMode={'tail'}
selectable={true}
accessible={_getDefaultTextAccessible()}
/>;
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
} from 'react-native-boost/runtime';
import { Text } from 'react-native';
<_NativeText
selectable={false}
style={{
color: 'red',
}}
allowFontScaling={true}
ellipsizeMode={'tail'}
selectable={false}
accessible={_getDefaultTextAccessible()}
/>;
10 changes: 5 additions & 5 deletions packages/react-native-boost/src/plugin/optimizers/text/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,16 +427,16 @@ function processProps(
// ============================================
// 4. Assemble the final attribute list
// ============================================
// `styleSpread` (the runtime `processTextStyle` call) is emitted AFTER the direct attributes so a
// `userSelect`-derived `selectable` it computes at runtime overrides a direct `selectable`, mirroring
// `Text`'s late `userSelect` override. `selectionColorSpread` writes a disjoint key (`selectionColor`),
// so its position is free — it leads for readability.
// `selectableAttribute` and `styleSpread` are emitted AFTER the remaining attributes so style-derived
// `userSelect` overrides direct or spread-carried `selectable`, mirroring `Text`'s late override.
// `selectionColorSpread` writes a disjoint key (`selectionColor`), so its position is free — it leads
// for readability.
path.node.attributes = [
selectionColorSpread,
accessibilitySpread,
selectableAttribute,
staticStyleAttribute,
...remainingAttributes,
selectableAttribute,
styleSpread,
accessibleAttribute,
].filter((attribute): attribute is t.JSXAttribute | t.JSXSpreadAttribute => attribute !== undefined);
Expand Down