microsoft / microsoft/react-native-windows
Custom Fonts do not load like on other platforms
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 17.3k
- Forks
- 1.2k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 33
Description
Environment
react-native-cli: 2.0.1
react-native: 0.60.6
-- (empty)
-- react-native-windows@0.60.0-vnext.32
node: v10.16.3
npm: 6.9.0
yarn: 1.17.3
-
SDK Version(s):
10.0.18362.0 -
Target Device(s):
Desktop -
Visual Studio Version:
Visual Studio 2017 -
Build Configuration:
Debug
Steps to Reproduce
This is the expected way to import a font for use:
export const MY_FONT= 'MyFont-Semilight';
However, that does not work, but as discovered in past github issue threads for RNW, this solution does work:
export const MY_FONT= 'Assets/Fonts/MyFont-Semilight.tff#FontFamilyName';
This leads the multi-platform solution to be as follows, which is less than ideal given the desire for as few platform checks as possible.
export const MY_FONT= Platform.OS === 'windows' ? 'Assets/Fonts/MyFont-Semilight.tff#FontFamilyName' : 'MyFont-Semilight';
I might have missed something, but I have yet to find some way to load fonts like for other platforms. Any help in making this possible is greatly appreciated.
Expected Behavior
The font does load.
Actual Behavior
The font doesn't load. Workaround shown above.
Additional context
https://github.com/microsoft/react-native-windows/issues/652
https://github.com/microsoft/react-native-windows/issues/1254
Adam Gorman(adamgor)
Austin Beaulieu(aubeauli)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the custom-font behavior described for react-native-windows@0.60.0-vnext.32, then review the related discussions in issues #652 and #1254. Trace the Windows font-loading entry point and compare it with other platforms; done means the font loads using its family name without a Windows-specific asset path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react-native
- Domain
- desktop, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100