133 lines
3.3 KiB
TypeScript
133 lines
3.3 KiB
TypeScript
import { Stack } from "expo-router";
|
|
import React from "react";
|
|
import * as RN from "react-native";
|
|
import {
|
|
useFonts,
|
|
Inter_400Regular,
|
|
Inter_500Medium,
|
|
Inter_600SemiBold,
|
|
Inter_700Bold,
|
|
} from "@expo-google-fonts/inter";
|
|
|
|
import { AppProvider } from "@/providers";
|
|
|
|
// Helper to resolve font family based on styles
|
|
const resolveCustomStyle = (style: any) => {
|
|
if (!style) {
|
|
return { fontFamily: "Inter-Regular" };
|
|
}
|
|
|
|
const flat = RN.StyleSheet.flatten(style);
|
|
|
|
// If fontFamily is already specified (like icons), don't override it!
|
|
if (flat && flat.fontFamily && flat.fontFamily !== "System" && flat.fontFamily !== "sans-serif") {
|
|
return style;
|
|
}
|
|
|
|
// Map font weight to Inter weights
|
|
const weight = flat?.fontWeight;
|
|
let fontFamily = "Inter-Regular";
|
|
|
|
if (weight === "bold" || weight === "700" || weight === "800" || weight === "900") {
|
|
fontFamily = "Inter-Bold";
|
|
} else if (weight === "600") {
|
|
fontFamily = "Inter-SemiBold";
|
|
} else if (weight === "500") {
|
|
fontFamily = "Inter-Medium";
|
|
}
|
|
|
|
// Merge the new fontFamily with the rest of the styles
|
|
return [
|
|
style,
|
|
{ fontFamily }
|
|
];
|
|
};
|
|
|
|
const OriginalText = RN.Text;
|
|
const OriginalTextInput = RN.TextInput;
|
|
|
|
// Custom Text HOC
|
|
const CustomText = React.forwardRef((props: any, ref: any) => {
|
|
const { style, allowFontScaling, ...rest } = props;
|
|
const newStyle = resolveCustomStyle(style);
|
|
return (
|
|
<OriginalText
|
|
{...rest}
|
|
ref={ref}
|
|
style={newStyle}
|
|
allowFontScaling={false}
|
|
/>
|
|
);
|
|
});
|
|
|
|
// Bind static props/methods if any
|
|
Object.assign(CustomText, OriginalText);
|
|
|
|
try {
|
|
const rnExports = require("react-native");
|
|
const descText = Object.getOwnPropertyDescriptor(rnExports, "Text");
|
|
if (descText && descText.configurable) {
|
|
Object.defineProperty(rnExports, "Text", {
|
|
get: () => CustomText,
|
|
configurable: true,
|
|
});
|
|
}
|
|
} catch (e) {
|
|
// Silently ignore if module exports are immutable in web bundle environment
|
|
}
|
|
|
|
// Custom TextInput HOC
|
|
const CustomTextInput = React.forwardRef((props: any, ref: any) => {
|
|
const { style, allowFontScaling, ...rest } = props;
|
|
const newStyle = resolveCustomStyle(style);
|
|
return (
|
|
<OriginalTextInput
|
|
{...rest}
|
|
ref={ref}
|
|
style={newStyle}
|
|
allowFontScaling={false}
|
|
/>
|
|
);
|
|
});
|
|
|
|
Object.assign(CustomTextInput, OriginalTextInput);
|
|
|
|
try {
|
|
const rnExports = require("react-native");
|
|
const descInput = Object.getOwnPropertyDescriptor(rnExports, "TextInput");
|
|
if (descInput && descInput.configurable) {
|
|
Object.defineProperty(rnExports, "TextInput", {
|
|
get: () => CustomTextInput,
|
|
configurable: true,
|
|
});
|
|
}
|
|
} catch (e) {
|
|
// Silently ignore if module exports are immutable in web bundle environment
|
|
}
|
|
|
|
import { GestureHandlerRootView } from "react-native-gesture-handler";
|
|
|
|
export default function RootLayout() {
|
|
const [fontsLoaded] = useFonts({
|
|
"Inter-Regular": Inter_400Regular,
|
|
"Inter-Medium": Inter_500Medium,
|
|
"Inter-SemiBold": Inter_600SemiBold,
|
|
"Inter-Bold": Inter_700Bold,
|
|
});
|
|
|
|
if (!fontsLoaded) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<GestureHandlerRootView style={{ flex: 1 }}>
|
|
<AppProvider>
|
|
<Stack
|
|
screenOptions={{
|
|
headerShown: false,
|
|
}}
|
|
/>
|
|
</AppProvider>
|
|
</GestureHandlerRootView>
|
|
);
|
|
} |