Skip to content

fix: handle boolean true in nativeStyleMapping#323

Merged
danstepanov merged 2 commits into
mainfrom
fix/native-style-mapping-boolean
Jun 17, 2026
Merged

fix: handle boolean true in nativeStyleMapping#323
danstepanov merged 2 commits into
mainfrom
fix/native-style-mapping-boolean

Conversation

@danstepanov

Copy link
Copy Markdown
Member

Summary

  • nativeStyleMapping allows true as a value (e.g. textAlign: true on TextInput, backgroundColor: true on ImageBackground), meaning "extract this property from style and set it as a prop with the same name"
  • The runtime called path.split(".") which throws TypeError on boolean true
  • Fixed by converting true to the key name during config creation in useNativeCss, so the runtime always receives strings

Test plan

  • Added 3 tests: boolean mapping extracts prop, works alongside other styles, works on custom styled() components
  • Full suite passes (1043 passed, 0 failures)

Fixes #232
Supersedes #251

@YevheniiKotyrlo

Copy link
Copy Markdown
Contributor

Thanks for picking this up! One small thing that might be worth an extra test: src/components/ImageBackground.tsx also uses the true form (backgroundColor: true), so the same crash reproduces on <ImageBackground className="bg-*">, not just TextInput. Issue #232 only mentioned TextInput, and the tests here cover TextInput + a custom styled() — adding an ImageBackground case would lock in the second shipped wrapper that hits this path.

@danstepanov danstepanov moved this to Ready for Release in Roadmap Apr 15, 2026
When nativeStyleMapping uses `true` (e.g. `textAlign: true`), the value
should be treated as the key name itself. Previously, `true.split(".")`
would throw a TypeError at runtime, breaking TextInput and
ImageBackground components that use this pattern.

Converts boolean `true` values to the key name during config creation
in useNativeCss so the runtime always receives strings.

Fixes #232
@danstepanov danstepanov force-pushed the fix/native-style-mapping-boolean branch from 6b4c0c8 to 72c2f6a Compare April 15, 2026 06:49
@5ZYSZ3K

5ZYSZ3K commented May 13, 2026

Copy link
Copy Markdown
Contributor

Hi, what is the state of this PR? I just ran into that issue

@5ZYSZ3K

5ZYSZ3K commented May 13, 2026

Copy link
Copy Markdown
Contributor

Specifically, it breaks, when I try to use TextInput. I see here: https://github.com/nativewind/react-native-css/blob/b5f2a4d5db480fdb8e8b95b3bd790d9d27b2dd17/src/components/TextInput.tsx, that you are using the following mapping:

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

And true value isn't really supported - using TextInput is not possible

@5ZYSZ3K

5ZYSZ3K commented May 21, 2026

Copy link
Copy Markdown
Contributor

What's interesting, I see the issue caused by this only when i pass text-center as a className to TextInput. I see the following error then:

 ERROR  [TypeError: path.split is not a function (it is undefined)] 

Code: base.tsx
  28 | export const BaseTextInput = forwardRef(
  29 |   ({ children, className, ...props }: BaseTextInputProps, ref: ForwardedRef<ReactNativeTextInput>) => {
> 30 |     return <ReactNativeTextInput className={`font-boston ${className}`}></ReactNativeTextInput>;
     |            ^
  31 |   },
  32 | );
  33 | BaseTextInput.displayName = "BaseTextInput";

@danstepanov danstepanov enabled auto-merge (squash) June 17, 2026 00:36
@danstepanov danstepanov merged commit a752625 into main Jun 17, 2026
6 checks passed
@danstepanov danstepanov deleted the fix/native-style-mapping-boolean branch June 17, 2026 00:38
@github-project-automation github-project-automation Bot moved this from Ready for Release to Done in Roadmap Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[V5] - TextInput crashes when using "text-center" or "text-right" or "text-left" in NativeWind v5 (react-native-css: path.split is undefined)

3 participants