Ajackster / react-native-global-props

A simple javascript implementation to add custom, default props to react-native components.
MIT License
350 stars 33 forks source link

Global style removed if another style is applied #19

Closed madtofan closed 5 years ago

madtofan commented 5 years ago

I tried using this to change the font globally in my project which is built using typescript, However it seems like my text aren't inheriting the fontFamily that i specified

so in my App.tsx I initialized with loading the text and used the text inside setCustomText.

useEffect(() => {
    Font.loadAsync({
      Montserrat: require("./assets/font/Montserrat-Medium.otf")
    });
    setCustomText(styles.text);
  }, []);

const styles = StyleSheet.create({
  text: {
    fontFamily: "Montserrat"
  }
});

am I doing it wrong? Can someone advise on how I can tackle this issue?

madtofan commented 5 years ago
  const firstRender = React.useRef(true);
  useEffect(() => {
    if (firstRender.current) {
      firstRender.current = false;
      Font.loadAsync({
        Montserrat: require("./assets/font/Montserrat-Medium.otf")
      });
      const customTextProps = {
        style: {
          fontFamily: "Montserrat"
        }
      };
      setCustomText(customTextProps);
    }
  }, []);

My apologies, I wasnt following directly as shown in the example. Now it works, just that if I ever put a style on the Text, it will override this prop even though there is no fontFamily prop on the Text

madtofan commented 5 years ago

It seems like it wasnt an issue from this library. The replaced fonts are the fonts that is bold and react native cant just increase the weight of the fontFamily. I needed to manually set another font for bold.

Closing this issue