react-native-paper icon indicating copy to clipboard operation
react-native-paper copied to clipboard

Failed prop type: Invalid prop `fontFamily` of type `object` supplied to `Text`, expected `string`.

Open StanleyGY opened this issue 7 years ago • 5 comments

Environment

This bug is found on the IPhone 7 device.

Description

I noticed that for the theme, we need to provide the fonts in the following format:

...
ios: {
    regular: {
      fontFamily: 'System',
      fontWeight: '400' as '400',
    },
    medium: {
      fontFamily: 'System',
      fontWeight: '500' as '500',
    },
    light: {
      fontFamily: 'System',
      fontWeight: '300' as '300',
    },
    thin: {
      fontFamily: 'System',
      fontWeight: '100' as '100',
    },
  },
....

Then I took a peek at the code for those typography components. Let's take the Text component as an example:

return (
      <NativeText
        {...rest}
        ref={(c) => {
          this._root = c;
        }}
        style={[
          {
            fontFamily: theme.fonts.regular,
            color: theme.colors.text,
            textAlign: 'left',
            writingDirection,
          },
          style,
        ]}
      />
    );

Here theme.fonts.regular is an object obviously, which cannot be assigned to the key fontFamily. After I changed it to ...theme.fonts.regular, everything works as expected. This bug also appears in the other components under Typography.

Reproducible Demo

StanleyGY avatar Oct 31 '19 09:10 StanleyGY

Are you using the latest version or 2.x?

satya164 avatar Oct 31 '19 09:10 satya164

I'm experiencing the same issue with the latest version (3)

Oshianor avatar Nov 01 '19 07:11 Oshianor

Me too. Face this error after upgrade to version 3. Error with the same code that I use in version 2. (I didn't use components that affected by breaking changes)
No any fontFamily noticed in Migration guide.

gluons avatar Nov 11 '19 06:11 gluons

Try theme.fonts.ios.regular

enqqi avatar Nov 18 '19 01:11 enqqi

I've added section regarding fonts to the migration guide.

Trancever avatar Nov 18 '19 09:11 Trancever