Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Next

- Fixed: Crash with `funcsMap[propKey] is not a function` when the theme has no `textVariants` or a variant contains props that are not Restyle props.
- Chore: Use npm trusted publishing and isolate package builds from publishing permissions.

## 2.4.5 - 2025-03-19
Expand Down
4 changes: 3 additions & 1 deletion src/composeRestyleFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ const composeRestyleFunctions = <
// We make the assumption that the props object won't have extra prototype keys.
// eslint-disable-next-line guard-for-in
for (const key in props) {
const mappedProps = funcsMap[key](props, options);
const func = funcsMap[key];
if (func === undefined) continue;
const mappedProps = func(props, options);
// eslint-disable-next-line guard-for-in
for (const mappedKey in mappedProps) {
styles[mappedKey as keyof ViewStyle] = mappedProps[mappedKey];
Expand Down
41 changes: 41 additions & 0 deletions src/test/createText.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,47 @@ describe('createText', () => {
]);
});

it('ignores textVariant values that are not restyle props', () => {
const themeWithNonRestyleProp = createTheme({
...theme,
textVariants: {
...theme.textVariants,
title: {
...theme.textVariants.title,
transform: [{rotate: '45deg'}],
},
},
});

const {root} = render(
<ThemeProvider theme={themeWithNonRestyleProp}>
<Text variant="title">Some text</Text>
</ThemeProvider>,
);

expect(root.findByType(RNText).props.style).toStrictEqual([
{
color: palette.black,
fontSize: 48,
fontWeight: 'bold',
},
]);
});

it('renders when the theme has no textVariants', () => {
const {textVariants, ...themeWithoutTextVariants} = theme;

const {root} = render(
<ThemeProvider theme={themeWithoutTextVariants}>
<Text color="black">Some text</Text>
</ThemeProvider>,
);

expect(root.findByType(RNText).props.style).toStrictEqual([
{color: palette.black},
]);
});

it('passes all React Native Text Style Props', () => {
const {root} = render(
<ThemeProvider theme={theme}>
Expand Down
22 changes: 22 additions & 0 deletions src/test/createVariant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,28 @@ describe('createVariant', () => {
expect(variant.func({}, {theme, dimensions})).toStrictEqual({});
});

it('ignores variant values that are not restyle props', () => {
const themeWithNonRestyleProp = {
...theme,
textVariants: {
...theme.textVariants,
rotated: {
fontSize: 14,
transform: [{rotate: '45deg'}],
},
},
};
const variant = createVariant({themeKey: 'textVariants'});
expect(
variant.func(
{variant: 'rotated'},
{theme: themeWithNonRestyleProp, dimensions},
),
).toStrictEqual({
fontSize: 14,
});
});

it('supports referencing other theme values in the variant', () => {
const variant = createVariant({themeKey: 'textVariants'});
expect(
Expand Down
Loading