skip to Main Content

I’m making a custom Button component with React Native & Nativewind. But the styling doesn’t work when className is applied to TouchableOpacity.

Component:

import {TouchableOpacity} from "react-native";

 <TouchableOpacity className="border border-red" {...rest}>
   <View className={cn(base(), className)}>
     {IconLeft && <IconLeft color={icon()} />}

     <Text className={text()}>
       {loading && <LoaderIcon className={spinner()} />}
       {!loading && children}
     </Text>

     {IconRight && <IconRight color={icon()} />}
   </View>
 </TouchableOpacity>

Works with style={{ borderWidth: 1, borderColor: "red" }}. ClassName styling works normal on other components.

Tried swapping places between the inside <View /> and <TouchableOpacity /> (as suggested here). But then it becomes too small to be clicked.

2

Answers


  1. Note : NativeWind does not work with TailwindCSS >3.3.2. If you wish
    to use the most current version, please upgrade to NativeWind v4

    if you already have then go through the installation of Tailwind CSS

    Login or Signup to reply.
  2. border-red isn’t a valid class in tailwind i guess… instead try border-red-50.

    you can find all the available tailwind border colors here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search