Skip to content

Commit c2dc6c5

Browse files
committed
feat: add fontFamily set
1 parent c154ebe commit c2dc6c5

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

example/src/App.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { useEffect, useRef } from 'react';
3-
import { StyleSheet, View, Dimensions } from 'react-native';
3+
import { StyleSheet, View, Dimensions, Platform } from 'react-native';
44
import { gestureHandlerRootHOC } from 'react-native-gesture-handler';
55
import {
66
SVGRenderer,
@@ -69,11 +69,14 @@ function SvgComponent({ option }: any) {
6969

7070
return <SvgChart ref={svgRef} useRNGH />;
7171
}
72-
72+
const fontFamily = Platform.select({
73+
ios: 'PingFang SC',
74+
android: 'sans-serif',
75+
});
7376
const option = {
7477
xAxis: {
7578
type: 'category',
76-
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
79+
data: ['周一', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
7780
},
7881
yAxis: {
7982
type: 'value',
@@ -91,6 +94,9 @@ const option = {
9194
type: 'line',
9295
},
9396
],
97+
textStyle: {
98+
fontFamily,
99+
},
94100
};
95101
function App() {
96102
return (

src/skia/skiaChart.tsx

-8
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,13 @@ import React, {
1212
import { Canvas, useCanvasRef } from '@shopify/react-native-skia';
1313
import { View } from 'react-native';
1414

15-
import {
16-
setPlatformAPI,
17-
// DEFAULT_FONT_FAMILY as zrenderFontFamily,
18-
} from 'zrender/lib/core/platform';
19-
// import { DEFAULT_FONT_FAMILY } from './utils/font';
20-
import { measureText } from '../utils/platform';
2115
import { GestureHandler } from '../components/GestureHandler';
2216
import { dispatchEventsToZRender } from '../components/events';
2317
import type { ChartElement, DispatchEvents, SkiaChartProps } from '../types';
2418

2519
export { SkiaRender } from './SkiaRender';
2620
export * from '../types';
2721

28-
setPlatformAPI({ measureText });
29-
3022
function SkiaComponent(
3123
props: SkiaChartProps,
3224
ref: ForwardedRef<(ChartElement & any) | null>

src/svg/svgChart.tsx

-8
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,6 @@ function SvgEle(props: SVGVEleProps) {
149149
const key = parts[0]?.trim();
150150
let value = parts[1]?.trim();
151151
if (key) {
152-
// echart里默认字体sans-serif,ios无法识别
153-
if (
154-
Platform.OS === 'ios' &&
155-
key === 'font-family' &&
156-
value === 'sans-serif'
157-
) {
158-
value = 'Helvetica Neue';
159-
}
160152
attrs[toCamelCase(key)] = value;
161153
}
162154
});

0 commit comments

Comments
 (0)