-
-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get color as string typed value #157
Comments
Yeah, i was wondering how to solve this also? @fumiki have you found a solution? |
@kneza23 No, unfortunately, I don't know the solution yet. |
I have the same problem. I don't know why they have removed the getColor function, in my opinion the API was more comfortable that way. would it be possible to add a second hook like "useColor"? |
Is there a way to create a useColor hook to be able to get a colour value? Some components require to set colours as attributes like react-native-calendars |
I've created the following hooks. Maybe its not optimum but it works. hooks.ts export function useColor() : ((colorName: string) => string) {
const tailwind = useTailwind();
return (colorName) => (tailwind(`text-${colorName}`) as any).color;
} And how to use it : [...]
import { useColor } from "@/api/hooks";
export function ComponentExample() {
const [markedDates, setMarkedDates] = useState<MarkedDate>({});
const tailwind = useTailwind();
const getColor = useColor();
return (
<View style={tailwind("h-full flex flex-col")}>
<CalendarList
pastScrollRange={50}
futureScrollRange={50}
scrollEnabled
showScrollIndicator
onDayPress={async (day) => {
await navigation.navigate("Quizz", { date: day.dateString as TimesheetDate });
}}
theme={{
textSectionTitleColor: getColor("gray-800"),
textSectionTitleDisabledColor: getColor("gray-400"),
todayBackgroundColor: getColor("blue-400"),
todayTextColor: getColor("gray-200")
}}
disabledDaysIndexes={[0, 6]}
markedDates={markedDates}
/>
</View>
);
} |
Now I'm migrating tailwind-rn from 3.x to 4.2.0.
In 3.x, we could get string typed color value from tailwind to pass it component as props like this.
However, by 4.x way, type of color is 'unknown' and so we can no longer use it the way we used to..
Is there any way to solve this problem? Or should I just give up on this problem?
I thought about modifying the type.d.ts and sending a pull request, but so far it hasn't worked.
Thanks!
The text was updated successfully, but these errors were encountered: