Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fonts property on DefaulTheme @react-navigation/native version ^7 #4540

Open
ccontreras-ilissolutions opened this issue Nov 7, 2024 · 2 comments
Labels

Comments

@ccontreras-ilissolutions

Current behaviour

This adaptation doesnt work

import {
  DarkTheme as NavigationDarkTheme,
  DefaultTheme as NavigationDefaultTheme,
} from '@react-navigation/native';
import {adaptNavigationTheme} from 'react-native-paper';
import {NavigationTheme} from 'react-native-paper/lib/typescript/types';

const {LightTheme, DarkTheme} = adaptNavigationTheme({
  reactNavigationLight: NavigationDefaultTheme,
  reactNavigationDark: NavigationDarkTheme,
});

interface IThemeState {
  isDark: boolean;
  theme: NavigationTheme;
  toggleLightTheme: () => void;
  toggleDarkTheme: () => void;
}

its because actually the New Interface DefaultTheme/LightTheme from react-navigation/native use a propertie font that NavigationTheme from react native papers doesnt have

Interface DefaultTheme from react-navigation/native

import type { Theme } from '../types';
import type { fonts } from '../fonts';


const DefaultTheme: Theme = {
  dark: false,
  colors: {
    primary: 'rgb(0, 122, 255)',
    background: 'rgb(242, 242, 242)',
    card: 'rgb(255, 255, 255)',
    text: 'rgb(28, 28, 30)',
    border: 'rgb(216, 216, 216)',
    notification: 'rgb(255, 59, 48)',
  },
 font,
};
export default DefaultTheme;

type NavigationTheme from react-native-paper/lib/typescript/types

export type NavigationTheme = {
  dark: boolean;
  colors: {
    primary: string;
    background: string;
    card: string;
    text: string;
    border: string;
    notification: string;
  };
};

Expected behaviour

How to reproduce?

Preview

What have you tried so far?

Your Environment

software version
ios x
android x
react-native 0.76.1
react-native-paper x.x.x
node x.x.x
npm or yarn x.x.x
expo sdk x.x.x
@anfo000
Copy link

anfo000 commented Nov 13, 2024

Hi @ccontreras-ilissolutions

One workaround is spreading the navigation theme fonts. Something like this

import {
  DarkTheme as DarkNavigationTheme,
  DefaultTheme as LightNavigationTheme,
  ThemeProvider,
} from '@react-navigation/native';

const { LightTheme, DarkTheme } = adaptNavigationTheme({
    reactNavigationLight: LightNavigationTheme,
    reactNavigationDark: DarkNavigationTheme,
    materialLight: MD3LightTheme,
    materialDark: MD3DarkTheme,
  });


<PaperProvider theme={paperTheme}>
        <ThemeProvider
          value={
            colorScheme === 'dark'
              ? { ...DarkTheme, fonts: { ...DarkNavigationTheme.fonts } }
              : { ...LightTheme, fonts: { ...LightNavigationTheme.fonts } }
          }>
              <Slot />
        </ThemeProvider>
</PaperProvider>

@AndreiOrmanji
Copy link

My workaround:

import { useThemeContext } from '@/components/ThemeProvider';
import {
  DarkTheme as NavigationDarkTheme,
  DefaultTheme as NavigationDefaultTheme,
  ThemeProvider as NavigationThemeProvider,
} from '@react-navigation/native';
import {
  adaptNavigationTheme,
  MD3DarkTheme,
  MD3LightTheme,
  Provider,
  ProviderProps,
} from 'react-native-paper';

export function PaperProvider({ children, ...otherProps }: ProviderProps) {
  const { isThemeDark, theme } = useThemeContext();

  const { LightTheme, DarkTheme } = adaptNavigationTheme({
    reactNavigationLight: NavigationDefaultTheme,
    reactNavigationDark: NavigationDarkTheme,
    materialDark: MD3DarkTheme,
    materialLight: MD3LightTheme,
  });
  const paperTheme = isThemeDark
    ? {
        ...MD3DarkTheme,
        ...DarkTheme,
        colors: {
          ...MD3DarkTheme.colors,
          ...DarkTheme.colors,
          ...theme.dark,
        },
        fonts: {
          ...MD3DarkTheme.fonts,
          ...NavigationDarkTheme.fonts,
          ...theme.dark,
        },
      }
    : {
        ...MD3LightTheme,
        ...LightTheme,
        colors: {
          ...MD3LightTheme.colors,
          ...LightTheme.colors,
          ...theme.light,
        },
        fonts: {
          ...MD3LightTheme.fonts,
          ...NavigationDefaultTheme.fonts,
          ...theme.light,
        },
      };

  return (
    <Provider theme={paperTheme} {...otherProps}>
      <NavigationThemeProvider value={paperTheme}>
        {children}
      </NavigationThemeProvider>
    </Provider>
  );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants