Home > other >  Expo react native custom button text not working
Expo react native custom button text not working

Time:01-13

This is how I load fonts:

const [IsReady, SetIsReady] = useState(false);

const LoadFonts = async () => {
 await useFonts();
};

if (!IsReady) {
 return (
  <AppLoading
    startAsync={LoadFonts}
    onFinish={() => SetIsReady(true)}
    one rror={() => {}}
  />
 );
}

It's working, but I have a button:

    export const StartButton = ({
    style = {},
    textStyle = {},
    size = 125,
    ...props
    }) => {

    return (
     <TouchableOpacity
      style={[styles(size).radius, style]}
      onPress={props.onPress}
      >
       <Text style={[styles(size).text, textStyle]}>{props.title}</Text>
     </TouchableOpacity>
    );
    };

    const styles = (size) =>
     StyleSheet.create({
     radius: {
      borderRadius: size / 2,
      width: size,
      height: size,
      alignItems: "center",
      justifyContent: "center",
      borderColor: "#FFFFFF",
      borderWidth: 1,
      fontFamily: "nevrada",
      backgroundColor: "#252250AA ",
     },
     text: { color: "#FFFFFF", fontSize: size / 5 },
     });

App.js component

<StartButton size={100} title="START" fontFamily="Heavitas" />`

Here is my useFonts.js file:

import * as Font from "expo-font";

    export default useFonts = async () =>
    await Font.loadAsync({
    Heavitas: require("./../assets/fonts/Heavitas.ttf"),
    nevrada: require("./../assets/fonts/nevrada.ttf"),
    gazebo: require("./../assets/fonts/gazebo.otf"),
});

The custom font doesn't work on the button. Everywhere else it is.

Various loading technics none did work for the button.

CodePudding user response:

SOLVED It needed to set fontFamily in component. Thanks anyway.

  • Related