@@ -17,6 +17,13 @@ import SVGComponent from '../svg/svgChart';
1717import { dispatchEventsToZRender } from '../components/events' ;
1818import { SVGRenderer } from '../svg/SVGRenderer' ;
1919import * as echarts from 'echarts/core' ;
20+ import type { EChartsType } from 'echarts/core' ;
21+ import type {
22+ RNGestureHandlerGesture ,
23+ ChartElement ,
24+ DefaultRNGestures ,
25+ DispatchEvents ,
26+ } from '../types' ;
2027import { BarChart , LineChart , GraphChart , ScatterChart } from 'echarts/charts' ;
2128import {
2229 PanGesture ,
@@ -108,7 +115,7 @@ function getOptionTwo() {
108115 animation : false ,
109116 tooltip : { } ,
110117 animationDurationUpdate : 1500 ,
111- animationEasingUpdate : 'quinticInOut' ,
118+ animationEasingUpdate : 'quinticInOut' as any , // Temporarily cast to any for test
112119 series : [
113120 {
114121 type : 'graph' ,
@@ -244,8 +251,8 @@ function zoomElement(pan: ReactTestInstance, x: number, y: number) {
244251}
245252
246253interface ChartCall {
247- call : ( chart : any ) => void ;
248- snapshot ?: ( data : string ) => any ;
254+ call : ( chart : EChartsType ) => void ;
255+ snapshot ?: ( data : string ) => Promise < Buffer > ;
249256}
250257
251258function Chart ( {
@@ -255,15 +262,15 @@ function Chart({
255262 gesture,
256263 handleGesture = true ,
257264} : {
258- Component : React . ComponentType < any > ;
265+ Component : React . ComponentType < any > ; // Keep as any to allow both SkiaChartProps and SVGChartProps with ref
259266 calls ?: ChartCall [ ] ;
260267 useRNGH ?: boolean ;
261- gesture ?: any ;
268+ gesture ?: RNGestureHandlerGesture ;
262269 handleGesture ?: boolean ;
263270} ) {
264- const ref = useRef < any > ( null ) ;
271+ const ref = useRef < ( ChartElement & any ) | null > ( null ) ;
265272 useEffect ( ( ) => {
266- let chart : any ;
273+ let chart : EChartsType | undefined ;
267274 if ( ref . current ) {
268275 // @ts -ignore
269276 chart = echarts . init ( ref . current , 'light' , {
@@ -273,17 +280,19 @@ function Chart({
273280 } ) ;
274281 ( async ( ) => {
275282 for ( const call of calls ) {
276- call . call ( chart ) ;
277- if ( call . snapshot ) {
278- await new Promise ( ( resolve ) =>
279- setTimeout ( async ( ) => {
280- const result = call . snapshot ?.( chart . getDataURL ( ) ) ;
281- if ( result instanceof Promise ) {
282- await result ;
283- }
284- resolve ( undefined ) ;
285- } , 0 )
286- ) ;
283+ if ( chart ) {
284+ call . call ( chart ) ;
285+ if ( call . snapshot ) {
286+ await new Promise ( ( resolve ) =>
287+ setTimeout ( async ( ) => {
288+ const result = call . snapshot ?.( chart ! . getDataURL ( ) ) ;
289+ if ( result instanceof Promise ) {
290+ await result ;
291+ }
292+ resolve ( undefined ) ;
293+ } , 0 )
294+ ) ;
295+ }
287296 }
288297 }
289298 } ) ( ) ;
@@ -314,7 +323,7 @@ Components.forEach((Component) => {
314323 Component = { Component }
315324 calls = { [
316325 {
317- call : ( chart : any ) => {
326+ call : ( chart : EChartsType ) => {
318327 chart . setOption ( getOption ( 'line' ) ) ;
319328 } ,
320329 snapshot,
@@ -333,13 +342,13 @@ Components.forEach((Component) => {
333342 < Chart
334343 calls = { [
335344 {
336- call : ( chart : any ) => {
345+ call : ( chart : EChartsType ) => {
337346 act ( ( ) => chart . setOption ( getOption ( ) ) ) ;
338347 } ,
339348 snapshot,
340349 } ,
341350 {
342- call : ( chart : any ) => {
351+ call : ( chart : EChartsType ) => {
343352 const id = chart . getZr ( ) . id ;
344353 act ( ( ) =>
345354 dispatchEventsToZRender (
@@ -373,7 +382,7 @@ Components.forEach((Component) => {
373382 handleGesture = { false }
374383 calls = { [
375384 {
376- call : ( chart : any ) => {
385+ call : ( chart : EChartsType ) => {
377386 chart . setOption ( getOption ( 'scatter' ) ) ;
378387 } ,
379388 snapshot,
@@ -393,7 +402,7 @@ Components.forEach((Component) => {
393402 Component = { Component }
394403 calls = { [
395404 {
396- call : ( chart : any ) => {
405+ call : ( chart : EChartsType ) => {
397406 chart . setOption ( getOptionTwo ( ) ) ;
398407 } ,
399408 snapshot,
@@ -435,7 +444,7 @@ Components.forEach((Component) => {
435444 useRNGH
436445 calls = { [
437446 {
438- call : ( chart : any ) => {
447+ call : ( chart : EChartsType ) => {
439448 chart . setOption ( getOptionTwo ( ) ) ;
440449 } ,
441450 snapshot,
@@ -495,9 +504,12 @@ Components.forEach((Component) => {
495504 < RNGHChart
496505 Component = { Component }
497506 useRNGH
498- gesture = { ( ...args : any ) => {
499- gesture ( ...args ) ;
500- return args [ 0 ] ;
507+ gesture = { (
508+ defaultGestures : DefaultRNGestures ,
509+ dispatchEvents : DispatchEvents
510+ ) => {
511+ gesture ( defaultGestures , dispatchEvents ) ;
512+ return defaultGestures [ 0 ] ;
501513 } }
502514 />
503515 ) ;
0 commit comments