@@ -169,7 +169,7 @@ const ChartUPlot = forwardRef<any, UPlotProps>(
169169 return ;
170170 }
171171
172- webref ? .injectJavaScript ( `
172+ webref . current . injectJavaScript ( `
173173 if (window._chart) {
174174 window._chart.setSize(${ JSON . stringify ( containerWidth ) } , ${ JSON . stringify ( containerHeight ) } );
175175 } else {
@@ -191,8 +191,14 @@ const ChartUPlot = forwardRef<any, UPlotProps>(
191191 uplotInstance . current = new uPlot ( opts , data , webref ) ;
192192 } else {
193193 // inject background color before chart setup if provided
194+ if ( ! webref ) {
195+ console . error ( 'WebView reference is not set' ) ;
196+ return ;
197+ }
194198
195- webref ?. injectJavaScript ( getCreateChartString ( data , opts , bgColor ) ) ;
199+ webref . current . injectJavaScript (
200+ getCreateChartString ( data , opts , bgColor ) ,
201+ ) ;
196202 }
197203 initialized . current = true ;
198204 } ,
@@ -208,7 +214,7 @@ const ChartUPlot = forwardRef<any, UPlotProps>(
208214 return ;
209215 }
210216
211- webref ? .injectJavaScript ( `
217+ webref . current . injectJavaScript ( `
212218 if (window._chart) {
213219 console.debug('Setting new data for uPlot chart');
214220 window._data = ${ JSON . stringify ( newData ) } ;
@@ -237,7 +243,7 @@ const ChartUPlot = forwardRef<any, UPlotProps>(
237243 return ;
238244 }
239245
240- webref ? .injectJavaScript ( `
246+ webref . current . injectJavaScript ( `
241247 var item = ${ JSON . stringify ( item ) } ;
242248
243249 if (!window._data) {
@@ -271,7 +277,7 @@ const ChartUPlot = forwardRef<any, UPlotProps>(
271277 return ;
272278 }
273279
274- webref ? .injectJavaScript ( `
280+ webref . current . injectJavaScript ( `
275281 if (window._chart) {
276282 window._chart.setScale(${ JSON . stringify ( axis ) } , ${ JSON . stringify ( options ) } );true;
277283 } else {
@@ -287,7 +293,12 @@ const ChartUPlot = forwardRef<any, UPlotProps>(
287293 if ( isWeb ) {
288294 uplotInstance . current ?. setSize ( width , height ) ;
289295 } else {
290- webref ?. injectJavaScript ( `
296+ if ( ! webref ) {
297+ console . error ( 'WebView reference is not set' ) ;
298+ return ;
299+ }
300+
301+ webref . current . injectJavaScript ( `
291302 if (!window._chart) {
292303 window._chart.setSize(${ JSON . stringify ( width ) } , ${ JSON . stringify ( height ) } );true;
293304 } else {
@@ -303,7 +314,12 @@ const ChartUPlot = forwardRef<any, UPlotProps>(
303314 if ( isWeb ) {
304315 uplotInstance . current ?. destroy ( ) ;
305316 } else {
306- webref ?. injectJavaScript ( `
317+ if ( ! webref ) {
318+ console . error ( 'WebView reference is not set' ) ;
319+ return ;
320+ }
321+
322+ webref . current . injectJavaScript ( `
307323 if (window._chart) {
308324 window._chart.destroy();true;
309325 } else {
@@ -323,6 +339,8 @@ const ChartUPlot = forwardRef<any, UPlotProps>(
323339 destroy,
324340 } ) ) ;
325341
342+ console . log ( 'webref:' , webref ) ;
343+
326344 if ( Platform . OS === 'web' ) {
327345 return (
328346 < View
@@ -355,7 +373,10 @@ const ChartUPlot = forwardRef<any, UPlotProps>(
355373 createChart ( optionsFinal , data , bgColor ) ;
356374 } }
357375 ref = { ( r ) => {
358- webref = r ;
376+ if ( r ) {
377+ console . log ( '!!WebView ref:' , r ) ;
378+ webref . current = r ;
379+ }
359380 } }
360381 javaScriptEnabled = { true }
361382 injectedJavaScript = { `${ injectedJavaScript } ; true;` }
0 commit comments