web-ridge / react-native-paper-dates

Smooth and fast cross platform Material Design date and time picker for React Native Paper
https://www.reactnativepaperdates.com
MIT License
654 stars 170 forks source link

theme.fonts is undefined #185

Closed magicvirus closed 1 year ago

magicvirus commented 2 years ago

I'm getting theme.fonts is undefined when using the DatePickerModal. Can one please help not sure why is complaining about theme.fonts.

I even setup fonts config in react paper and still not working.

RichardLindhout commented 2 years ago

Can you share the exact error, did you use the ThemeProvider of react-native-paper?

sumitagarwal31 commented 2 years ago

I am even getting the same error , please open the issue

RichardLindhout commented 2 years ago

Are you using the beta version of react-native-paper?

sumitagarwal31 commented 2 years ago

I am using "react-native-paper-dates": "0.8.7"

RichardLindhout commented 2 years ago

Dit you wrap the Provider of react-native-paper in your app.js / app.tsx?

RichardLindhout commented 2 years ago

See #usage https://callstack.github.io/react-native-paper/getting-started.html#usage

sumitagarwal31 commented 2 years ago
Screenshot 2022-08-29 at 3 02 13 PM

I have attached the screenshot , please have a look

sumitagarwal31 commented 2 years ago
image

@RichardLindhout Please check the screenshot where I am getting the issue. Thanks!

kukuhpro commented 2 years ago

using "react-native-paper-dates": "^0.9.0" got the same issue and same error message

waiting for update on this issue. Thanks

sumitagarwal31 commented 1 year ago

@RichardLindhout can you please help with the issue

BryanTacuri commented 1 year ago

got the same issue and same error message

fdelacruzsoto commented 1 year ago

react native paper 5 does not have the font type for the themes by default.

This is the workaround I used:

I declared a global type for the theme and added the fonts there

// eslint-disable-next-line @typescript-eslint/no-unused-vars
import {
  Font,
  MD3Colors,
  MD3Theme,
} from 'react-native-paper/lib/typescript/types';

declare global {
  namespace ReactNativePaper {
    interface Fonts {
      regular: Font;
      medium: Font;
      light: Font;
      thin: Font;
    }
    interface Colors extends MD3Colors {
      accent: string;
      danger: string;
      backgroundPrimary: string;
      background: string;
    }
    interface Theme extends MD3Theme {
      colors: Colors;
      fonts: Fonts;
    }
  }
}

Since I'm extending the theme I do something like this:

import {
  DarkTheme as NavigationDarkTheme,
  DefaultTheme as NavigationDefaultTheme,
} from '@react-navigation/native';

import {
  configureFonts,
  MD3Colors,
  MD3DarkTheme as PaperDarkTheme,
  MD3LightTheme as PaperDefaultTheme,
} from 'react-native-paper';

export const CombinedDefaultTheme = {
  ...PaperDefaultTheme,
  ...NavigationDefaultTheme,
  colors: {
    ...NavigationDefaultTheme.colors,
    ...PaperDefaultTheme.colors,
    primary: '#193C34',
    secondary: '#32AD38',
    tertiary: '#45FF00',
    accent: '#FFFF00',
    danger: '#dc2626',
    backgroundPrimary: '#5BBD60',
    background: '#FFF',
  },
  fonts: configureFonts(),
};

export const CombinedDarkTheme = {
  ...PaperDarkTheme,
  ...NavigationDarkTheme,
  colors: {
    ...NavigationDarkTheme.colors,
    ...PaperDarkTheme.colors,
    primary: '#193C34',
    secondary: '#32AD38',
    tertiary: '#45FF00',
    accent: '#FFFF00',
    danger: '#dc2626',
    backgroundPrimary: '#5BBD60',
    background: MD3Colors.neutralVariant30,
  },
  fonts: configureFonts(),
};

This is going to fix the issue

iM-GeeKy commented 1 year ago

Closed by https://github.com/web-ridge/react-native-paper-dates/pull/206