2017-09-05 79 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

非常感謝。它適合我。 ü保存我的一天。 –