如何使用 CSSProperties 中的 fontWeight 或 fontVariant 来访问 React Native 中的字体变体?

How do I use the fontWeight or fontVariant in CSSProperties to access a font variant in React Native?

我正在尝试在 React Native 应用程序中使用此 google 字体 (https://fonts.google.com/specimen/Ruda) 中可用的变体。我可以很好地加载标准字体,但它是一种在同一 ttf 中包含所有变体的字体,我不知道如何让它工作。

点这里: https://snack.expo.dev/@ftoldghost/variable-font-test

我试过弄乱 fontWeight 但它要么什么都不做,要么在覆盖 fontFamily 并恢复为默认字体时使其(例如)变为粗体。

我也尝试过使用 fontVariant,但我想不出不会引发错误的语法。一些错误类似于 IDE 或 java.lang.String cannot be cast to abi42_0_0.com.facebook.react.bridge.ReadableArray 中的 Type '"Semi-Bold"[]' is not assignable to type 'FontVariant[]'.。那就是尝试设置它(正如我所看到的那样推荐:

fontVariant: ['Semi-Bold']

像这样使用自包含 ttf 变体的正确方法是什么?

如果您使用 google 字体,您将无法使用 fontWeight 您可以简单地从 google 下载所有字体变体并将它们用作

fontFamily:'Ruda-Bold'fontFamily:'Ruda-SemiBold'