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
34 changes: 33 additions & 1 deletion src/__tests__/native/components.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Button as RNButton, type ButtonProps } from "react-native";
import {
Button as RNButton,
View as RNView,
type ButtonProps,
type ViewProps,
} from "react-native";

import { render } from "@testing-library/react-native";
import { copyComponentProperties } from "react-native-css/components/copyComponentProperties";
Expand Down Expand Up @@ -54,3 +59,30 @@ test("Component preserves props when mapping specifies 'target: false'", () => {
expect(titleElement.props.style).toHaveLength(2);
expect(titleElement.props.style[1]).toEqual({ color: "#ffa500" });
});

test("Component maps style onto a same-named prop when nativeStyleMapping uses the `true` shorthand", () => {
registerCSS(`.fill { background-color: red; }`);

const mapping: StyledConfiguration<typeof RNView> = {
className: {
target: "style",
nativeStyleMapping: {
backgroundColor: true,
},
},
};

const Component = copyComponentProperties(
RNView,
(props: StyledProps<ViewProps, typeof mapping>) => {
return useCssElement(RNView, props, mapping);
},
);

const result = render(<Component testID={testID} className="fill" />);

const renderedProps = result.getByTestId(testID).props;

expect(renderedProps.backgroundColor).toBe("#f00");
expect(renderedProps.style?.backgroundColor).toBeUndefined();
});
2 changes: 1 addition & 1 deletion src/native/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ function nativeStyleMapping(
}

let target = props;
const tokens = path.split(".");
const tokens = (typeof path === "string" ? path : key).split(".");
const lastToken = tokens.pop();
for (const token of tokens) {
target[token] ??= {};
Expand Down