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

How to custom font family? #22

Open
Aircity opened this issue Jul 19, 2021 · 0 comments
Open

How to custom font family? #22

Aircity opened this issue Jul 19, 2021 · 0 comments

Comments

@Aircity
Copy link

Aircity commented Jul 19, 2021

App.tsx

export default function App() {
  const isLoadingComplete = useCachedResources();

  if (!isLoadingComplete) {
    return null;
  } else {
    return <GLViewScreen />;
  }
}

useCachedResources

import { Ionicons } from '@expo/vector-icons';
import * as Font from 'expo-font';
import * as SplashScreen from 'expo-splash-screen';
import * as React from 'react';

export default function useCachedResources() {
  const [isLoadingComplete, setLoadingComplete] = React.useState(false);

  // Load any resources or data that we need prior to rendering the app
  React.useEffect(() => {
    async function loadResourcesAndDataAsync() {
      try {
        SplashScreen.preventAutoHideAsync();

        // Load fonts
        await Font.loadAsync({
          ...Ionicons.font,
          'space-mono': require('../assets/fonts/SpaceMono-Regular.ttf'),
        });
      } catch (e) {
        // We might want to provide this error information to an error reporting service
        console.warn(e);
      } finally {
        setLoadingComplete(true);
        SplashScreen.hideAsync();
      }
    }

    loadResourcesAndDataAsync();
  }, []);

  return isLoadingComplete;
}

GLViewScreen

      <GLView
          style={{ flexGrow: 1, flexShrink: 0, flexBasis: "auto" }}
          onContextCreate={async (context) => {
          const ctx = new Expo2DContext(context);
          const asset: any = Asset.fromModule(require("./assets/main.png"));
          await asset.downloadAsync();
          asset.width = 656;
          asset.height = 508;
          ctx.drawImage(asset, 0, 0, 656, 508);
          await ctx.initializeText();
          ctx.fillStyle = "blue";
          ctx.font = "72pt space-mono";
          ctx.fillText("Useless Text", 240, 180);
          ctx.flush();
        }}
      />

Throw error and display message

[Unhandled promise rejection: SyntaxError: Could not find supported font family]
@Aircity Aircity changed the title How to custom font? How to custom font family? Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant