marklawlor / nativewind

React Native utility-first universal design system - powered by Tailwind CSS
https://nativewind.dev
MIT License
4.3k stars 233 forks source link

v4 cssInterop does not work with custom native component #891

Open ospfranco opened 3 weeks ago

ospfranco commented 3 weeks ago

Describe the bug I'm trying to apply native wind styles to a native component, the component is very bare-bones:


@objc(BlurViewManager)
class BlurViewManager: RCTViewManager {
  override static func requiresMainQueueSetup() -> Bool {
    return true
  }

  override func view() -> NSView! {
    return BlurView()
  }
}

When I try to import it and apply cssInterop to it:

import {requireNativeComponent, ViewStyle} from 'react-native'

import {cssInterop} from 'nativewind'

export const BlurView = requireNativeComponent<{
  children?: any
  onLayout?: (e: any) => void
  startColor?: string
  endColor?: string
  style?: ViewStyle
  cornerRadius?: number
  disabled?: boolean
  className?: string
}>('BlurView')

// export const BlurView = (...props: any) => <BlurViewNative {...props} />

cssInterop(BlurView, {
  className: 'style',
})

However on runtime I get the following error:

Oscar Franco Screen 001343

ospfranco commented 3 weeks ago

I managed to get this working, seems the cssInterop call is passing an array of props and not and object, therefore the destructuring is actually not working:

import {requireNativeComponent, ViewStyle} from 'react-native'

import {cssInterop} from 'nativewind'

export const BlurViewNative = requireNativeComponent<{
  children?: any
  onLayout?: (e: any) => void
  startColor?: string
  endColor?: string
  style?: ViewStyle
  cornerRadius?: number
  disabled?: boolean
  className?: string
}>('BlurView')

export const BlurView = (props: any) => {
  return <BlurViewNative {...props} />
}

cssInterop(BlurView, {
  className: 'style',
})

Is this a bug? I'm not sure, maybe at least it needs to be documented properly