Fixes
This commit is contained in:
+6
-6
@@ -225,12 +225,12 @@ module.exports = function (config) {
|
|||||||
'expo-font',
|
'expo-font',
|
||||||
{
|
{
|
||||||
fonts: [
|
fonts: [
|
||||||
'./assets/fonts/inter/Inter-Thin.otf',
|
// './assets/fonts/inter/Inter-Thin.otf',
|
||||||
'./assets/fonts/inter/Inter-ThinItalic.otf',
|
// './assets/fonts/inter/Inter-ThinItalic.otf',
|
||||||
'./assets/fonts/inter/Inter-ExtraLight.otf',
|
// './assets/fonts/inter/Inter-ExtraLight.otf',
|
||||||
'./assets/fonts/inter/Inter-ExtraLightItalic.otf',
|
// './assets/fonts/inter/Inter-ExtraLightItalic.otf',
|
||||||
'./assets/fonts/inter/Inter-Light.otf',
|
// './assets/fonts/inter/Inter-Light.otf',
|
||||||
'./assets/fonts/inter/Inter-LightItalic.otf',
|
// './assets/fonts/inter/Inter-LightItalic.otf',
|
||||||
'./assets/fonts/inter/Inter-Regular.otf',
|
'./assets/fonts/inter/Inter-Regular.otf',
|
||||||
'./assets/fonts/inter/Inter-Italic.otf',
|
'./assets/fonts/inter/Inter-Italic.otf',
|
||||||
'./assets/fonts/inter/Inter-Medium.otf',
|
'./assets/fonts/inter/Inter-Medium.otf',
|
||||||
|
|||||||
+45
-25
@@ -1,8 +1,11 @@
|
|||||||
import {useFonts as defaultUseFonts} from 'expo-font'
|
import {useFonts as defaultUseFonts} from 'expo-font'
|
||||||
|
|
||||||
|
import {isWeb} from '#/platform/detection'
|
||||||
import {IS_PROD} from '#/env'
|
import {IS_PROD} from '#/env'
|
||||||
import {Device, device} from '#/storage'
|
import {Device, device} from '#/storage'
|
||||||
|
|
||||||
|
const FAMILIES = `-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Liberation Sans", Helvetica, Arial, sans-serif`
|
||||||
|
|
||||||
const factor = 0.0625 // 1 - (15/16)
|
const factor = 0.0625 // 1 - (15/16)
|
||||||
const fontScaleMultipliers: Record<Device['fontScale'], number> = {
|
const fontScaleMultipliers: Record<Device['fontScale'], number> = {
|
||||||
'-2': 1 - factor * 3,
|
'-2': 1 - factor * 3,
|
||||||
@@ -36,7 +39,12 @@ export function setFontFamily(fontFamily: Device['fontFamily']) {
|
|||||||
* Unused fonts are commented out, but the files are there if we need them.
|
* Unused fonts are commented out, but the files are there if we need them.
|
||||||
*/
|
*/
|
||||||
export function useFonts() {
|
export function useFonts() {
|
||||||
if (IS_PROD) return [true, undefined]
|
/**
|
||||||
|
* Local native builds work fine with `expo-font` config plugin, but web does
|
||||||
|
* not. So in dev, we ensure things are loaded using the async hook. In
|
||||||
|
* production, fonts load via the config plugin on all platforms.
|
||||||
|
*/
|
||||||
|
if (IS_PROD) return [true, null]
|
||||||
return defaultUseFonts({
|
return defaultUseFonts({
|
||||||
// 'Inter-Thin': require('../../assets/fonts/inter/Inter-Thin.otf'),
|
// 'Inter-Thin': require('../../assets/fonts/inter/Inter-Thin.otf'),
|
||||||
// 'Inter-ThinItalic': require('../../assets/fonts/inter/Inter-ThinItalic.otf'),
|
// 'Inter-ThinItalic': require('../../assets/fonts/inter/Inter-ThinItalic.otf'),
|
||||||
@@ -62,31 +70,43 @@ export function useFonts() {
|
|||||||
/*
|
/*
|
||||||
* Unused fonts are commented out, but the files are there if we need them.
|
* Unused fonts are commented out, but the files are there if we need them.
|
||||||
*/
|
*/
|
||||||
export function applyFonts(style: Record<string, any>) {
|
export function applyFonts(
|
||||||
style.fontFamily =
|
style: Record<string, any>,
|
||||||
{
|
fontFamily: 'system' | 'theme',
|
||||||
// '100': 'Inter-Thin',
|
) {
|
||||||
// '200': 'Inter-ExtraLight',
|
if (fontFamily === 'theme') {
|
||||||
// '300': 'Inter-Light',
|
style.fontFamily =
|
||||||
'100': 'Inter-Regular',
|
{
|
||||||
'200': 'Inter-Regular',
|
// '100': 'Inter-Thin',
|
||||||
'300': 'Inter-Regular',
|
// '200': 'Inter-ExtraLight',
|
||||||
'400': 'Inter-Regular',
|
// '300': 'Inter-Light',
|
||||||
'500': 'Inter-Medium',
|
'100': 'Inter-Regular',
|
||||||
'600': 'Inter-SemiBold',
|
'200': 'Inter-Regular',
|
||||||
'700': 'Inter-Bold',
|
'300': 'Inter-Regular',
|
||||||
'800': 'Inter-ExtraBold',
|
'400': 'Inter-Regular',
|
||||||
'900': 'Inter-Black',
|
'500': 'Inter-Medium',
|
||||||
}[style.fontWeight as string] || 'Inter-Regular'
|
'600': 'Inter-SemiBold',
|
||||||
|
'700': 'Inter-Bold',
|
||||||
|
'800': 'Inter-ExtraBold',
|
||||||
|
'900': 'Inter-Black',
|
||||||
|
}[style.fontWeight as string] || 'Inter-Regular'
|
||||||
|
|
||||||
if (style.fontStyle === 'italic') {
|
if (style.fontStyle === 'italic') {
|
||||||
if (style.fontFamily === 'Inter-Regular') {
|
if (style.fontFamily === 'Inter-Regular') {
|
||||||
style.fontFamily = 'Inter-Italic'
|
style.fontFamily = 'Inter-Italic'
|
||||||
} else {
|
} else {
|
||||||
style.fontFamily += 'Italic'
|
style.fontFamily += 'Italic'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallback families only supported on web
|
||||||
|
if (isWeb) {
|
||||||
|
style.fontFamily += `, ${FAMILIES}`
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// fallback families only supported on web
|
||||||
|
if (isWeb) {
|
||||||
|
style.fontFamily = style.fontFamily || FAMILIES
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
style.fontFamily +=
|
|
||||||
', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Liberation Sans", Helvetica, Arial, sans-serif'
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,9 +56,7 @@ export function normalizeTextStyles(
|
|||||||
s.lineHeight = s.fontSize
|
s.lineHeight = s.fontSize
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fontFamily === 'theme') {
|
applyFonts(s, fontFamily)
|
||||||
applyFonts(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,9 +43,7 @@ export function Text({
|
|||||||
style,
|
style,
|
||||||
])
|
])
|
||||||
|
|
||||||
if (fonts.family === 'theme') {
|
applyFonts(flattened, fonts.family)
|
||||||
applyFonts(flattened)
|
|
||||||
}
|
|
||||||
|
|
||||||
// should always be defined on `typography`
|
// should always be defined on `typography`
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -73,9 +71,7 @@ export function Text({
|
|||||||
style,
|
style,
|
||||||
])
|
])
|
||||||
|
|
||||||
if (fonts.family === 'theme') {
|
applyFonts(flattened, fonts.family)
|
||||||
applyFonts(flattened)
|
|
||||||
}
|
|
||||||
|
|
||||||
// should always be defined on `typography`
|
// should always be defined on `typography`
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|||||||
Reference in New Issue
Block a user