2017-09-05 81 views
0

即时新闻中反应原生!我在我的项目中使用了shoutem/ui。 修改默认的fontFamily时出现问题。这里是我的代码,请检查然后帮我解决这个问题。 非常感谢这么多人。Shoutem更改默认字体家庭不起作用

const theme = _.merge(getTheme(), { 
 
    defaultFont: { 
 
     fontFamily: 'Rubik-Italic', 
 
     }, 
 
    'shoutem.ui.NavigationBar': { 
 
     '.clear': { 
 
      container: { 
 
       backgroundColor: params.primaryColor, 
 
       borderBottomColor: 'transparent', 
 
       position: 'relative', 
 
      }, 
 
      'shoutem.ui.Title': { 
 
       color: 'white', 
 
       fontSize: 16, 
 
      }, 
 
     }, 
 
     '.normal': { 
 
      container: { 
 
       position: 'relative' 
 
      }, 
 
      'shoutem.ui.Button': { 
 
       'shoutem.ui.Icon': { 
 
        color: params.colorTextAlpha, 
 
       }, 
 
       'shoutem.ui.Text': { 
 
        color: params.colorTextAlpha, 
 
       }, 
 
      }, 
 
      'shoutem.ui.Title': { 
 
       color: params.colorText, 
 
      }, 
 
     } 
 
    }, 
 
    'shoutem.ui.Row': { 
 
     '.fix': { 
 
      paddingHorizontal: 10, 
 
      paddingVertical: 10, 
 
     } 
 
    } 
 
});

+0

说明问题,只是说你有问题不真的帮助我们帮助你。 –

+0

我做了上面的代码,但我的应用程序中的所有组件仍然无法使用此字体。 我已经使用将它们连接到我的项目中的所有组件 –

回答

0

你想要做什么是覆盖的主题变量。

导入默认主题变量和getTheme功能:

import { 
    getTheme, 
    defaultThemeVariables, 
} from '@shoutem/ui'; 

然后定义自定义变量:

const myThemeVariables = { 
...defaultThemeVariables, 
    title: { fontFamily: 'MyFont' }, 
}; 

,然后定义自定义主题,使用这些变量:

const myTheme = getTheme(myThemeVariables); 

没有更多​​设置可以覆盖,所以哟你不得不特别遗憾。

此外,你必须导入StyleProvider:

import { StyleProvider } from '@shoutem/theme'; 

并用它来控制你的组件的风格:

render() { 
    return (
     <StyleProvider style={myTheme}> 
     // your components here 
     </StyleProvider> 
    ); 
    } 
} 
+0

非常感谢。它适合我。 ü保存我的一天。 –