nandorojo / solito

🧍‍♂️ React Native + Next.js, unified.
https://solito.dev
MIT License
3.54k stars 181 forks source link

How to implement responsive SolitoImage using nativewind ? #269

Closed xinha-sh closed 1 year ago

xinha-sh commented 1 year ago

Hi I'm using nativewind for styling. And my image component looks like this

import { styled } from 'nativewind'
import { SolitoImage } from 'solito/image'

export const Img = styled(SolitoImage)
<Img
  className="h-16 w-16 self-center rounded-full border-2 border-slate-600 hover:border-4 hover:border-yellow-600 md:h-32 md:w-32"
  src={vertical.imageUrl}
  resizeMode="contain"
  alt={vertical.name}
 />

Error shown is

Screenshot 2022-12-06 at 5 44 03 PM

I'm able to bypass this error via adding a style prop with {{}} as value. ie

<Img
  className="h-16 w-16 self-center rounded-full border-2 border-slate-600 hover:border-4 hover:border-yellow-600 md:h-32 md:w-32"
  src={vertical.imageUrl}
  resizeMode="contain"
  alt={vertical.name}
  style={{}}
 />

But after that I'm getting following error:

Screenshot 2022-12-06 at 5 46 10 PM
nandorojo commented 1 year ago

I’ll look into the style issue. Width is required unless you use the fill property.

nandorojo commented 1 year ago

I actually don’t think this is a solito image issue. If you use it directly, the style prop isn’t required. So it must be an issue with nativewind’s styled()

xinha-sh commented 1 year ago

I actually don’t think this is a solito image issue. If you use it directly, the style prop isn’t required. So it must be an issue with nativewind’s styled()

Got it.Thanks.

If not using tailwind how would you recommend dynamic width height for Image component

xinha-sh commented 1 year ago

@nandorojo I stumbled upon this youtube video regarding next/image. It's in-dept and I felt should be included in solito docs. Hence raising a PR https://github.com/nandorojo/solito/pull/271

nandorojo commented 1 year ago

You should wrap solito/image with styled by the way.