Skip to content

Commit

Permalink
feat: add fontFamily set
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiqingchen committed Oct 10, 2024
1 parent c154ebe commit c2dc6c5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
12 changes: 9 additions & 3 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { useEffect, useRef } from 'react';
import { StyleSheet, View, Dimensions } from 'react-native';
import { StyleSheet, View, Dimensions, Platform } from 'react-native';
import { gestureHandlerRootHOC } from 'react-native-gesture-handler';
import {
SVGRenderer,
Expand Down Expand Up @@ -69,11 +69,14 @@ function SvgComponent({ option }: any) {

return <SvgChart ref={svgRef} useRNGH />;
}

const fontFamily = Platform.select({
ios: 'PingFang SC',
android: 'sans-serif',
});
const option = {
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
data: ['周一', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
},
yAxis: {
type: 'value',
Expand All @@ -91,6 +94,9 @@ const option = {
type: 'line',
},
],
textStyle: {
fontFamily,
},
};
function App() {
return (
Expand Down
8 changes: 0 additions & 8 deletions src/skia/skiaChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,13 @@ import React, {
import { Canvas, useCanvasRef } from '@shopify/react-native-skia';
import { View } from 'react-native';

import {
setPlatformAPI,
// DEFAULT_FONT_FAMILY as zrenderFontFamily,
} from 'zrender/lib/core/platform';
// import { DEFAULT_FONT_FAMILY } from './utils/font';
import { measureText } from '../utils/platform';
import { GestureHandler } from '../components/GestureHandler';
import { dispatchEventsToZRender } from '../components/events';
import type { ChartElement, DispatchEvents, SkiaChartProps } from '../types';

export { SkiaRender } from './SkiaRender';
export * from '../types';

setPlatformAPI({ measureText });

function SkiaComponent(
props: SkiaChartProps,
ref: ForwardedRef<(ChartElement & any) | null>
Expand Down
8 changes: 0 additions & 8 deletions src/svg/svgChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,6 @@ function SvgEle(props: SVGVEleProps) {
const key = parts[0]?.trim();
let value = parts[1]?.trim();
if (key) {
// echart里默认字体sans-serif,ios无法识别
if (
Platform.OS === 'ios' &&
key === 'font-family' &&
value === 'sans-serif'
) {
value = 'Helvetica Neue';
}
attrs[toCamelCase(key)] = value;
}
});
Expand Down

0 comments on commit c2dc6c5

Please sign in to comment.