I have added the font families on expo mobile app
import React from "react";
import { SafeAreaProvider } from "react-native-safe-area-context";
import Constants from "expo-constants";
import { FontSource, useFonts } from "expo-font";
import { ClerkProvider } from "@clerk/clerk-expo";
import * as Sentry from "sentry-expo";
import { tokenCache } from "./config/tokenCache";
import { Navigation } from "./navigation";
import { TRPCProvider } from "./utils/api";
const fontSources: { [key: string]: FontSource } = {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
"HK Grotesk": require("./assets/fonts/hk-grotesk/HKGrotesk-Regular.otf"),
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
"HK Grotesk-Medium": require("./assets/fonts/hk-grotesk/HKGrotesk-Medium.otf"),
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
"HK Grotesk-SemiBold": require("./assets/fonts/hk-grotesk/HKGrotesk-SemiBold.otf"),
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
"HK Grotesk-Bold": require("./assets/fonts/hk-grotesk/HKGrotesk-Bold.otf"),
};
export const App = () => {
const [loaded] = useFonts(fontSources);
if (!loaded) {
return null;
}
return (
<ClerkProvider publishableKey={Constants.manifest?.extra?.clerkPublicKey as string} tokenCache={tokenCache}>
<TRPCProvider>
<SafeAreaProvider>
<Navigation />
</SafeAreaProvider>
</TRPCProvider>
</ClerkProvider>
);
};
Sentry.init({
dsn: Constants.manifest?.extra?.sentryDsn as string,
enableInExpoDevelopment: false,
debug: false,
enabled: Constants.manifest?.extra?.environment === "production",
});
And also added config to tailwind.config.cjs
/** @type {import("tailwindcss").Config} */
module.exports = {
presets: [require("@acme/tailwind-config")],
theme: {
extend: {
fontFamily: {
'grotesk-medium': ['"HK Grotesk-Medium"', "sans-serif"],
'grotesk-semi-bold': ['"HK Grotesk-SemiBold"', "sans-serif"],
'grotesk-bold': ['"HK Grotesk-Bold"', "sans-serif"],
},
}
}
};
The problem is that now font-family work if I apply them explicitly on <Text />
components,
But I want to set font-family globally and control font-weight by tailwind classes, with current scenario font-weights are not working of course.
I am new in react native, first tried to wrap with parent component, but if I am not mistaken, react-native component styling is not working like that.