首页 > 解决方案 > 反应原生纸张组件没有拉出正确的字体

问题描述

我的react-native-paper组件textInput不会拉出我设置的字体。

          <View style={styles.inputCon}>
            <TextInput
              multiline={true}
              label="Ime aktivnosti"
              mode="outlined"
              value={ime}
              onChangeText={(value) => {
                setIme(value);
              }}
            />
          </View>

我遵循了有关如何更改 RN Paper 组件的字体的官方文档https://callstack.github.io/react-native-paper/fonts.html

const fontConfig = {
  default: {
    regular:{
    fontFamily: "Poppins_400Regular",
    fontWeight:'normal'
  },
  medium: {
    fontFamily: "Poppins_500Medium",
    fontWeight:'normal'
  },
  light: {
    fontFamily: "Poppins_300Light",
    fontWeight:'normal'
  },
  thin: {
    fontFamily: "Poppins_200ExtraLight",
    fontWeight:'normal'
  },
  bold: {
    fontFamily: "Poppins_700Bold",
    fontWeight:'normal'
  }
  },
};

const theme = {
  ...DefaultTheme,
  fonts: configureFonts(fontConfig),
};

另一个组件,也来自react native paper正确拉字体

      <Searchbar
        placeholder="Type here..."
        onChangeText={text => this.searchItems(text)}
        value={this.state.value}
      />

标签: reactjsreact-nativereact-native-paper

解决方案


import { configureFonts, DefaultTheme, Provider as PaperProvider } from 'react-native-paper';

const theme = {
  ...DefaultTheme,
  fontFamily: {...DefaultTheme.fonts.regular.fontFamily = 'fontName'} 
};

export default class App extends Component {
  
  render() {
    const RootStack = createStackNavigator();
    return (
      <PaperProvider theme={theme}>
        <SafeAreaProvider>
        </SafeAreaProvider>
      </PaperProvider>
    );
  }

反应原生 cli:2.0.1 反应原生:0.63.4


推荐阅读