@@ -531,42 +531,41 @@ function codePushify(options = {}) {
531
531
) ;
532
532
}
533
533
534
- var decorator = ( RootComponent ) => {
535
- const extended = class CodePushComponent extends React . Component {
534
+ const decorator = ( RootComponent ) => {
535
+ class CodePushComponent extends React . Component {
536
+ constructor ( props ) {
537
+ super ( props ) ;
538
+ this . rootComponentRef = React . createRef ( ) ;
539
+ }
540
+
536
541
componentDidMount ( ) {
537
542
if ( options . checkFrequency === CodePush . CheckFrequency . MANUAL ) {
538
543
CodePush . notifyAppReady ( ) ;
539
544
} else {
540
- let rootComponentInstance = this . refs . rootComponent ;
545
+ const rootComponentInstance = this . rootComponentRef . current ;
541
546
542
547
let syncStatusCallback ;
543
548
if ( rootComponentInstance && rootComponentInstance . codePushStatusDidChange ) {
544
- syncStatusCallback = rootComponentInstance . codePushStatusDidChange ;
545
- if ( rootComponentInstance instanceof React . Component ) {
546
- syncStatusCallback = syncStatusCallback . bind ( rootComponentInstance ) ;
547
- }
549
+ syncStatusCallback = rootComponentInstance . codePushStatusDidChange . bind ( rootComponentInstance ) ;
548
550
}
549
551
550
552
let downloadProgressCallback ;
551
553
if ( rootComponentInstance && rootComponentInstance . codePushDownloadDidProgress ) {
552
- downloadProgressCallback = rootComponentInstance . codePushDownloadDidProgress ;
553
- if ( rootComponentInstance instanceof React . Component ) {
554
- downloadProgressCallback = downloadProgressCallback . bind ( rootComponentInstance ) ;
555
- }
554
+ downloadProgressCallback = rootComponentInstance . codePushDownloadDidProgress . bind ( rootComponentInstance ) ;
556
555
}
557
556
558
557
let handleBinaryVersionMismatchCallback ;
559
558
if ( rootComponentInstance && rootComponentInstance . codePushOnBinaryVersionMismatch ) {
560
- handleBinaryVersionMismatchCallback = rootComponentInstance . codePushOnBinaryVersionMismatch ;
561
- if ( rootComponentInstance instanceof React . Component ) {
562
- handleBinaryVersionMismatchCallback = handleBinaryVersionMismatchCallback . bind ( rootComponentInstance ) ;
563
- }
559
+ handleBinaryVersionMismatchCallback = rootComponentInstance . codePushOnBinaryVersionMismatch . bind ( rootComponentInstance ) ;
564
560
}
565
561
566
562
CodePush . sync ( options , syncStatusCallback , downloadProgressCallback , handleBinaryVersionMismatchCallback ) ;
563
+
567
564
if ( options . checkFrequency === CodePush . CheckFrequency . ON_APP_RESUME ) {
568
565
ReactNative . AppState . addEventListener ( "change" , ( newState ) => {
569
- newState === "active" && CodePush . sync ( options , syncStatusCallback , downloadProgressCallback ) ;
566
+ if ( newState === "active" ) {
567
+ CodePush . sync ( options , syncStatusCallback , downloadProgressCallback ) ;
568
+ }
570
569
} ) ;
571
570
}
572
571
}
@@ -575,17 +574,17 @@ function codePushify(options = {}) {
575
574
render ( ) {
576
575
const props = { ...this . props } ;
577
576
578
- // we can set ref property on class components only (not stateless)
579
- // check it by render method
580
- if ( RootComponent . prototype . render ) {
581
- props . ref = "rootComponent" ;
577
+ // We can set ref property on class components only (not stateless)
578
+ // Check it by render method
579
+ if ( RootComponent . prototype && RootComponent . prototype . render ) {
580
+ props . ref = this . rootComponentRef ;
582
581
}
583
582
584
583
return < RootComponent { ...props } />
585
584
}
586
585
}
587
586
588
- return hoistStatics ( extended , RootComponent ) ;
587
+ return hoistStatics ( CodePushComponent , RootComponent ) ;
589
588
}
590
589
591
590
if ( typeof options === "function" ) {
0 commit comments