feat: 添加字体类
This commit is contained in:
parent
7b9f523cc1
commit
d0c66baf45
10
app.json
10
app.json
@ -46,7 +46,15 @@
|
|||||||
"plugins": [
|
"plugins": [
|
||||||
"expo-router",
|
"expo-router",
|
||||||
"expo-secure-store",
|
"expo-secure-store",
|
||||||
[
|
[
|
||||||
|
"expo-font",
|
||||||
|
{
|
||||||
|
"fonts": [
|
||||||
|
"./assets/font/english.otf"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
"expo-background-task",
|
"expo-background-task",
|
||||||
{
|
{
|
||||||
"minimumInterval": 15
|
"minimumInterval": 15
|
||||||
|
|||||||
@ -9,13 +9,16 @@ import { prefetchChats } from '@/lib/prefetch';
|
|||||||
import { fetchApi } from '@/lib/server-api-util';
|
import { fetchApi } from '@/lib/server-api-util';
|
||||||
import { webSocketManager, WebSocketStatus } from '@/lib/websocket-util';
|
import { webSocketManager, WebSocketStatus } from '@/lib/websocket-util';
|
||||||
import { TransitionPresets } from '@react-navigation/bottom-tabs';
|
import { TransitionPresets } from '@react-navigation/bottom-tabs';
|
||||||
|
import { useFonts } from 'expo-font';
|
||||||
import * as Notifications from 'expo-notifications';
|
import * as Notifications from 'expo-notifications';
|
||||||
import { Tabs } from 'expo-router';
|
import { Tabs } from 'expo-router';
|
||||||
import * as SecureStore from 'expo-secure-store';
|
import * as SecureStore from 'expo-secure-store';
|
||||||
|
import * as SplashScreen from 'expo-splash-screen';
|
||||||
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Platform } from 'react-native';
|
import { Platform } from 'react-native';
|
||||||
|
|
||||||
|
SplashScreen.preventAutoHideAsync();
|
||||||
interface PollingData {
|
interface PollingData {
|
||||||
title: string;
|
title: string;
|
||||||
id: string;
|
id: string;
|
||||||
@ -55,6 +58,17 @@ export default function TabLayout() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 加载字体
|
||||||
|
const [loaded, error] = useFonts({
|
||||||
|
english: require('@/assets/font/english.otf'),
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (loaded || error) {
|
||||||
|
SplashScreen.hideAsync();
|
||||||
|
}
|
||||||
|
}, [loaded, error]);
|
||||||
|
|
||||||
// 监听通知点击事件
|
// 监听通知点击事件
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const notificationListener = Notifications.addNotificationResponseReceivedListener(response => {
|
const notificationListener = Notifications.addNotificationResponseReceivedListener(response => {
|
||||||
|
|||||||
@ -460,6 +460,7 @@ const styles = StyleSheet.create({
|
|||||||
container: {
|
container: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
backgroundColor: '#FFB645',
|
backgroundColor: '#FFB645',
|
||||||
|
fontFamily: 'english'
|
||||||
},
|
},
|
||||||
loadingContainer: {
|
loadingContainer: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
|
|||||||
BIN
assets/font/english.otf
Normal file
BIN
assets/font/english.otf
Normal file
Binary file not shown.
@ -1,11 +1,14 @@
|
|||||||
import { StyleSheet, Text, type TextProps } from 'react-native';
|
import { StyleProp, StyleSheet, Text, TextStyle, type TextProps } from 'react-native';
|
||||||
|
|
||||||
|
import { Fonts } from '@/constants/Fonts';
|
||||||
import { useThemeColor } from '@/hooks/useThemeColor';
|
import { useThemeColor } from '@/hooks/useThemeColor';
|
||||||
|
|
||||||
export type ThemedTextProps = TextProps & {
|
export type ThemedTextProps = TextProps & {
|
||||||
lightColor?: string;
|
lightColor?: string;
|
||||||
darkColor?: string;
|
darkColor?: string;
|
||||||
type?: 'default' | 'title' | 'defaultSemiBold' | 'subtitle' | 'link';
|
type?: 'default' | 'title' | 'defaultSemiBold' | 'subtitle' | 'link';
|
||||||
|
weight?: 'regular' | 'medium' | 'semiBold' | 'bold';
|
||||||
|
size?: 'xs' | 'sm' | 'base' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl';
|
||||||
};
|
};
|
||||||
|
|
||||||
export function ThemedText({
|
export function ThemedText({
|
||||||
@ -13,14 +16,26 @@ export function ThemedText({
|
|||||||
lightColor,
|
lightColor,
|
||||||
darkColor,
|
darkColor,
|
||||||
type = 'default',
|
type = 'default',
|
||||||
|
weight = 'regular',
|
||||||
|
size,
|
||||||
...rest
|
...rest
|
||||||
}: ThemedTextProps) {
|
}: ThemedTextProps) {
|
||||||
const color = useThemeColor({ light: lightColor, dark: darkColor }, 'text');
|
const color = useThemeColor({ light: lightColor, dark: darkColor }, 'text');
|
||||||
|
|
||||||
|
const baseStyle: StyleProp<TextStyle> = {
|
||||||
|
fontFamily: Fonts.primary,
|
||||||
|
color,
|
||||||
|
fontWeight: Fonts[weight as keyof typeof Fonts] as TextStyle['fontWeight'],
|
||||||
|
};
|
||||||
|
|
||||||
|
if (size) {
|
||||||
|
baseStyle.fontSize = Fonts[size as keyof typeof Fonts];
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Text
|
<Text
|
||||||
style={[
|
style={[
|
||||||
{ color },
|
baseStyle,
|
||||||
type === 'default' ? styles.default : undefined,
|
type === 'default' ? styles.default : undefined,
|
||||||
type === 'title' ? styles.title : undefined,
|
type === 'title' ? styles.title : undefined,
|
||||||
type === 'defaultSemiBold' ? styles.defaultSemiBold : undefined,
|
type === 'defaultSemiBold' ? styles.defaultSemiBold : undefined,
|
||||||
@ -35,26 +50,28 @@ export function ThemedText({
|
|||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
default: {
|
default: {
|
||||||
fontSize: 16,
|
fontSize: Fonts.base,
|
||||||
lineHeight: 24,
|
lineHeight: 24,
|
||||||
},
|
},
|
||||||
defaultSemiBold: {
|
defaultSemiBold: {
|
||||||
fontSize: 16,
|
fontSize: Fonts.base,
|
||||||
lineHeight: 24,
|
lineHeight: 24,
|
||||||
fontWeight: '600',
|
fontWeight: '600',
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
fontSize: 32,
|
fontSize: Fonts['2xl'],
|
||||||
fontWeight: 'bold',
|
fontWeight: '700',
|
||||||
lineHeight: 32,
|
lineHeight: 32,
|
||||||
},
|
},
|
||||||
subtitle: {
|
subtitle: {
|
||||||
fontSize: 20,
|
fontSize: Fonts.lg,
|
||||||
fontWeight: 'bold',
|
fontWeight: '600',
|
||||||
|
lineHeight: 28,
|
||||||
},
|
},
|
||||||
link: {
|
link: {
|
||||||
lineHeight: 30,
|
fontSize: Fonts.sm,
|
||||||
fontSize: 16,
|
lineHeight: 20,
|
||||||
color: '#0a7ea4',
|
color: '#0a7ea4',
|
||||||
|
textDecorationLine: 'underline',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
24
constants/Fonts.ts
Normal file
24
constants/Fonts.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
export const Fonts = {
|
||||||
|
// Font family
|
||||||
|
primary: 'english',
|
||||||
|
|
||||||
|
// Font weights
|
||||||
|
regular: '400',
|
||||||
|
medium: '500',
|
||||||
|
semiBold: '600',
|
||||||
|
bold: '700',
|
||||||
|
|
||||||
|
// Font sizes
|
||||||
|
xs: 12,
|
||||||
|
sm: 14,
|
||||||
|
base: 16,
|
||||||
|
lg: 18,
|
||||||
|
xl: 20,
|
||||||
|
'2xl': 24,
|
||||||
|
'3xl': 30,
|
||||||
|
'4xl': 36,
|
||||||
|
'5xl': 48,
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type FontWeight = keyof Omit<typeof Fonts, 'primary' | 'xs' | 'sm' | 'base' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl'>;
|
||||||
|
export type FontSize = 'xs' | 'sm' | 'base' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl';
|
||||||
Loading…
x
Reference in New Issue
Block a user