@@ -27,18 +27,31 @@ interface LogoProps {
2727 className ?: string ;
2828}
2929
30- export default class InteractiveLogo extends React . Component < LogoProps > {
30+ interface LogoState {
31+ player : RufflePlayer | null ;
32+ }
33+
34+ export default class InteractiveLogo extends React . Component < LogoProps , LogoState > {
3135 private readonly container : React . RefObject < HTMLDivElement > ;
3236 private player : RufflePlayer | null = null ;
3337
3438 constructor ( props : LogoProps ) {
3539 super ( props ) ;
3640
3741 this . container = React . createRef ( ) ;
42+ this . state = {
43+ player : null ,
44+ } ;
45+ }
46+
47+ private removeRufflePlayer ( ) {
48+ this . player ?. remove ( ) ;
49+ this . player = null ;
50+ this . setState ( { player : null } ) ;
3851 }
3952
4053 private load ( ) {
41- if ( this . player ) {
54+ if ( this . state . player ) {
4255 // Already loaded.
4356 return ;
4457 }
@@ -47,6 +60,7 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
4760
4861 if ( this . player ) {
4962 this . container . current ! . appendChild ( this . player ) ;
63+
5064 this . player . load ( {
5165 url : "/logo-anim.swf" ,
5266 autoplay : "on" ,
@@ -55,14 +69,12 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
5569 contextMenu : "off" ,
5670 splashScreen : false ,
5771 preferredRenderer : "canvas" ,
58- } ) . then ( ( ) => {
59- this ?. container ?. current ?. querySelector ( "img" ) ?. classList ?. toggle ( classes . hidden ) ;
6072 } ) . catch ( ( ) => {
61- this . player ?. remove ( ) ;
62- this . player = null ;
73+ this . removeRufflePlayer ( ) ;
6374 } ) ;
6475 this . player . style . width = "100%" ;
6576 this . player . style . height = "100%" ;
77+ this . setState ( { player : this . player } ) ;
6678 }
6779 }
6880
@@ -71,8 +83,7 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
7183 }
7284
7385 componentWillUnmount ( ) {
74- this . player ?. remove ( ) ;
75- this . player = null ;
86+ this . removeRufflePlayer ( ) ;
7687 }
7788
7889 render ( ) {
@@ -83,7 +94,7 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
8394 onReady = { ( ) => this . load ( ) }
8495 />
8596 < div ref = { this . container } className = { this . props . className } >
86- < Image src = "/logo.svg" alt = "Ruffle Logo" className = { classes . staticLogo } width = "340" height = "110" />
97+ < Image src = "/logo.svg" alt = "Ruffle Logo" className = { this . state . player ? classes . hidden : classes . staticLogo } width = "340" height = "110" />
8798 </ div >
8899 </ >
89100 ) ;
0 commit comments