反应本机纸张组件未提取正确的字体

问题描述

我的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",light: {
    fontFamily: "Poppins_300Light",thin: {
    fontFamily: "Poppins_200ExtraLight",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}
      />

解决方法

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>
    );
  }

react-native-cli: 2.0.1 反应原生:0.63.4