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
31 changes: 31 additions & 0 deletions packages/react-strict-dom/src/native/stylex/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,37 @@ export function props(
if (boxSizingValue === 'content-box' && !version.experimental) {
nextStyle = fixContentBox(nextStyle);
}

// Print an error message if flex properties are used without
// "display:flex" being set. React Native is always using "flex"
// layout but web uses "flow" layout by default, which can lead
// to layout divergence if building for native first.
if (__DEV__) {
if (
nextStyle.display == null ||
(nextStyle.display !== 'flex' && nextStyle.display !== 'none')
) {
if (
nextStyle.alignContent != null ||
nextStyle.alignItems != null ||
nextStyle.alignSelf != null ||
nextStyle.columnGap != null ||
nextStyle.flex != null ||
nextStyle.flexBasis != null ||
nextStyle.flexDirection != null ||
nextStyle.flexGrow != null ||
nextStyle.flexShrink != null ||
nextStyle.flexWrap != null ||
nextStyle.gap != null ||
nextStyle.justifyContent != null ||
nextStyle.placeContent != null ||
nextStyle.rowGap != null
) {
errorMsg('"display:flex" is required to use flexbox properties');
}
}
}

nativeProps.style = nextStyle;

return nativeProps;
Expand Down
26 changes: 26 additions & 0 deletions packages/react-strict-dom/tests/css-test.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,32 @@ describe('properties: general', () => {
expect(css.props.call(mockOptions, styles.rtl)).toMatchSnapshot('rtl');
});

test('display', () => {
const styles = css.create({
flex: {
display: 'flex'
},
align: {
alignItems: 'center'
},
row: {
flexDirection: 'row'
}
});
css.props.call(mockOptions, [styles.flex, styles.align]);
expect(console.error).not.toHaveBeenCalledWith(
expect.stringContaining(
'"display:flex" is required to use flexbox properties'
)
);
css.props.call(mockOptions, [styles.align, styles.row]);
expect(console.error).toHaveBeenCalledWith(
expect.stringContaining(
'"display:flex" is required to use flexbox properties'
)
);
});

test('filter', () => {
const { underTest } = css.create({
underTest: {
Expand Down