Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android fonts issue #2239

Open
1 of 6 tasks
teckbeng-payboy opened this issue Jun 17, 2024 · 4 comments
Open
1 of 6 tasks

Android fonts issue #2239

teckbeng-payboy opened this issue Jun 17, 2024 · 4 comments
Labels
bug Something isn't working v1 gluestack-ui v1

Comments

@teckbeng-payboy
Copy link

teckbeng-payboy commented Jun 17, 2024

Description

Font only get reflected on ios but not android

CodeSandbox/Snack link

Steps to reproduce

I exported the components from gluestack

import {GluestackUIProvider, SafeAreaView, Text} from './components';
import {useFonts} from 'expo-font';
import {Montserrat_400Regular} from '@expo-google-fonts/montserrat';
import {Licorice_400Regular} from '@expo-google-fonts/licorice';

export default function App() {
  const [fontsLoaded] = useFonts({
    Montserrat_400Regular,
    Licorice_400Regular,
  });

  return (
    <GluestackUIProvider>
      <SafeAreaView justifyContent="center" alignItems="center" flex={1}>
        <Text fontFamily="$heading">Hello World!</Text>
        <Text fontFamily="$body">Hello World!</Text>
      </SafeAreaView>
    </GluestackUIProvider>
  );
}

In the gluestack-ui.config.ts file, i changed below line to

fonts: { heading: 'licorice', body: 'licorice', mono: 'montserrat', },

Attached below is my package.json

 "dependencies": {
    "@expo-google-fonts/hind": "^0.2.3",
    "@expo-google-fonts/kolker-brush": "^0.2.3",
    "@expo-google-fonts/licorice": "^0.2.3",
    "@expo-google-fonts/montserrat": "^0.2.3",
    "@gluestack-style/react": "^1.0.56",
    "@gluestack-ui/config": "latest",
    "@gluestack-ui/themed": "^1.1.30",
    "expo": "^51.0.0",
    "expo-font": "~12.0.7",
    "react": "18.2.0",
    "react-native": "0.74.2",
    "react-native-svg": "13.4.0"
  },

gluestack-ui Version

1.1.30

Platform

  • Expo
  • React Native CLI
  • Next
  • Web
  • Android
  • iOS

Other Platform

No response

Additional Information

Screenshot 2024-06-17 at 11 49 32 AM
@teckbeng-payboy teckbeng-payboy added the bug Something isn't working label Jun 17, 2024
@jordmccord
Copy link

You need to use the FontResolever (see end of https://gluestack.io/ui/docs/guides/advanced/fonts) or use something like expo-xml-font https://github.com/Armster15/expo-xml-font

@teckbeng-payboy
Copy link
Author

do you have any idea where can i find the example for FontResolver?

@doranakan
Copy link

do you have any idea where can i find the example for FontResolver?

just found something in the gluestack.io/style docs

in my case I have the following scenario:

  //in my home _layout:
  const [fontLoaded] = useFonts({
    Grenze_700Bold,
    NotoSerif_400Regular,
    NotoSerif_700Bold
  })

so in the gluestack createConfig I'm passing to the FontResolver mapFonts field a function that transform this ugly input i'm getting from the callback

 {"fontFamily": "Grenze", "fontWeight": "700"}
 {"fontFamily": "NotoSerif", "fontStyle": "normal", "fontWeight": "400"}
 {"fontFamily": "NotoSerif", "fontStyle": "normal", "fontWeight": "bold"}

into

'Grenze_700Bold'
'NotoSerif_400Regular'
'NotoSerif_700Bold'

by doing this I solved the issue with Android, on iOS it was working without this thing

@doranakan
Copy link

actually after applying some changes I realised there are still some issues with custom fonts and android, for example if I apply a custom fontFamily via prop to a Heading, all other Heading components start using the same font even if they are no customized

@Viraj-10 Viraj-10 added the v1 gluestack-ui v1 label Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v1 gluestack-ui v1
Projects
Status: Backlog
Development

No branches or pull requests

4 participants