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
if you already have then go through the installation of Tailwind CSS
border-red
isn’t a valid class in tailwind i guess… instead tryborder-red-50
.you can find all the available tailwind border colors here