How to useTheme and override the fontFamily for Text - Title
I have setup my index.js with the custom font and theme
Versions -
react-native - 0.63.2 react-native-paper - 4.0.1 react-native-vector-icons - 7.0.0
/**
* @format
*/
import * as React from 'react';
import 'react-native-gesture-handler';
import {AppRegistry} from 'react-native';
import {configureFonts, DefaultTheme, Provider as PaperProvider} from 'react-native-paper';
import App from './src/index';
import * as Color from '_styles/colors';
import {name as appName} from './app.json';
const fontConfig = {
default: {
regular: {
fontFamily: 'Roboto-Regular',
fontWeight: 'normal',
},
medium: {
fontFamily: 'Roboto-Medium',
fontWeight: 'normal',
},
light: {
fontFamily: 'Roboto-Light',
fontWeight: 'normal',
},
thin: {
fontFamily: 'Roboto-Thin',
fontWeight: 'normal',
},
black: {
fontFamily: 'Roboto-Black',
fontWeight: 'normal',
},
bold: {
fontFamily: 'Roboto-Bold',
fontWeight: 'normal',
},
},
};
const theme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
accent: Color.ACCENT,
accentSecondary: Color.ACCENT_SECONDARY,
primary: Color.PRIMARY,
primarySecondary: Color.PRIMARY_SECONDARY,
primaryTertiary: Color.PRIMARY_TERTIARY,
primaryQuaternary: Color.PRIMARY_QUATERNARY,
error: Color.ALERT,
errorSecondary: Color.ALERT_SECONDARY,
black: Color.BLACK,
grey: Color.GRAY_DARK,
greySecondary: Color.GRAY_MEDIUM,
greyTertiary: Color.GRAY_LIGHT,
white: Color.WHITE,
},
fonts: configureFonts(fontConfig),
};
export default function Main() {
return (
<PaperProvider theme={theme}>
<App />
</PaperProvider>
);
}
AppRegistry.registerComponent(appName, () => Main);
I am using Title component from the library and trying to override the family. I don't know how to use the theme for the component and to override the theme. I'm not able to understand the docs clearly,
import React from 'react';
import {Button, Image, View, StyleSheet} from 'react-native';
import {Title, useTheme, configureFonts} from 'react-native-paper';
import string from '_utils/strings';
import {Typography, Spacing, Colors} from '_styles';
function Agreement({navigation}) {
const {colors, fonts} = useTheme();
return (
<View style={styles.container}>
<Image style={styles.logo} source={require('_assets/images/image.png')} />
<View style={styles.greyContainer}>
<Title>
{string.onboarding.agreement.heading}
</Title>
<Title>
{string.onboarding.agreement.welcome}
</Title>
</View>
</View>
);
}
export default Agreement;
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
greyContainer: {
backgroundColor: Colors.GRAY_MEDIUM,
},
image: {
height: '100%',
width: '100%',
},
});
Any help would be appreciated, thanks
Couldn't find version numbers for the following packages in the issue:
react-nativereact-native-paperreact-native-vector-icons
Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.
Hello 👋, this issue has been open for more than 2 months with no activity on it. If the issue is still present in the latest version, please leave a comment within 7 days to keep it open, otherwise it will be closed automatically. If you found a solution on workaround for the issue, please comment here for others to find. If this issue is critical for you, please consider sending a pull request to fix the issue.
I was facing same error I have solved it by making import {SignIn} from './SignIn'; As (Remove Curly Braces after Import , It worked for me) import SignIn from './SignIn'; My React Version "react": "17.0.2", "react-native": "0.66.3", "native-base": "^3.2.2",