1- import React , { useRef , useEffect , useState } from 'react' ;
1+ import React from 'react' ;
22import useScreenSize from '@site/src/hooks/useScreenSize' ;
33import useBaseUrl from '@docusaurus/useBaseUrl' ;
44
55const Logo = ( ) => {
66 const { windowWidth } = useScreenSize ( ) ;
77 const gifUrl = useBaseUrl ( '/img/logo-hero-flame.gif' ) ;
8- const canvasRef = useRef < HTMLCanvasElement > ( null ) ;
9- const [ showCanvas , setShowCanvas ] = useState ( false ) ;
10-
11- useEffect ( ( ) => {
12- if ( ! canvasRef . current ) return ;
13-
14- const canvas = canvasRef . current ;
15- const ctx = canvas . getContext ( '2d' ) ;
16- if ( ! ctx ) return ;
17-
18- const img = new Image ( ) ;
19- img . crossOrigin = 'anonymous' ;
20- img . src = gifUrl ;
21-
22- img . onload = ( ) => {
23- canvas . width = img . naturalWidth ;
24- canvas . height = img . naturalHeight ;
25-
26- // Calculate GIF duration (approximate based on typical frame rates)
27- // Adjust this timeout to match your GIF's actual duration
28- const gifDuration = 7500 ; // milliseconds - adjust as needed!
29-
30- setTimeout ( ( ) => {
31- // Draw the final frame
32- ctx . drawImage ( img , 0 , 0 ) ;
33- setShowCanvas ( true ) ;
34- } , gifDuration ) ;
35- } ;
36- } , [ gifUrl ] ) ;
378
389 if ( windowWidth <= 768 ) {
3910 return null ;
@@ -44,19 +15,7 @@ const Logo = () => {
4415 < img
4516 src = { gifUrl }
4617 alt = "React Native ExecuTorch 🔥💀"
47- style = { {
48- maxWidth : '400px' ,
49- width : '100%' ,
50- display : showCanvas ? 'none' : 'block' ,
51- } }
52- />
53- < canvas
54- ref = { canvasRef }
55- style = { {
56- maxWidth : '400px' ,
57- width : '100%' ,
58- display : showCanvas ? 'block' : 'none' ,
59- } }
18+ style = { { maxWidth : '400px' , width : '100%' } }
6019 />
6120 </ div >
6221 ) ;
0 commit comments