@@ -625,42 +625,41 @@ function codePushify(options = {}) {
625
625
sharedCodePushOptions . setUpdateChecker ( options . updateChecker ) ;
626
626
sharedCodePushOptions . setFallbackToAppCenter ( options . fallbackToAppCenter ) ;
627
627
628
- var decorator = ( RootComponent ) => {
629
- const extended = class CodePushComponent extends React . Component {
628
+ const decorator = ( RootComponent ) => {
629
+ class CodePushComponent extends React . Component {
630
+ constructor ( props ) {
631
+ super ( props ) ;
632
+ this . rootComponentRef = React . createRef ( ) ;
633
+ }
634
+
630
635
componentDidMount ( ) {
631
636
if ( options . checkFrequency === CodePush . CheckFrequency . MANUAL ) {
632
637
CodePush . notifyAppReady ( ) ;
633
638
} else {
634
- let rootComponentInstance = this . refs . rootComponent ;
639
+ const rootComponentInstance = this . rootComponentRef . current ;
635
640
636
641
let syncStatusCallback ;
637
642
if ( rootComponentInstance && rootComponentInstance . codePushStatusDidChange ) {
638
- syncStatusCallback = rootComponentInstance . codePushStatusDidChange ;
639
- if ( rootComponentInstance instanceof React . Component ) {
640
- syncStatusCallback = syncStatusCallback . bind ( rootComponentInstance ) ;
641
- }
643
+ syncStatusCallback = rootComponentInstance . codePushStatusDidChange . bind ( rootComponentInstance ) ;
642
644
}
643
645
644
646
let downloadProgressCallback ;
645
647
if ( rootComponentInstance && rootComponentInstance . codePushDownloadDidProgress ) {
646
- downloadProgressCallback = rootComponentInstance . codePushDownloadDidProgress ;
647
- if ( rootComponentInstance instanceof React . Component ) {
648
- downloadProgressCallback = downloadProgressCallback . bind ( rootComponentInstance ) ;
649
- }
648
+ downloadProgressCallback = rootComponentInstance . codePushDownloadDidProgress . bind ( rootComponentInstance ) ;
650
649
}
651
650
652
651
let handleBinaryVersionMismatchCallback ;
653
652
if ( rootComponentInstance && rootComponentInstance . codePushOnBinaryVersionMismatch ) {
654
- handleBinaryVersionMismatchCallback = rootComponentInstance . codePushOnBinaryVersionMismatch ;
655
- if ( rootComponentInstance instanceof React . Component ) {
656
- handleBinaryVersionMismatchCallback = handleBinaryVersionMismatchCallback . bind ( rootComponentInstance ) ;
657
- }
653
+ handleBinaryVersionMismatchCallback = rootComponentInstance . codePushOnBinaryVersionMismatch . bind ( rootComponentInstance ) ;
658
654
}
659
655
660
656
CodePush . sync ( options , syncStatusCallback , downloadProgressCallback , handleBinaryVersionMismatchCallback ) ;
657
+
661
658
if ( options . checkFrequency === CodePush . CheckFrequency . ON_APP_RESUME ) {
662
659
ReactNative . AppState . addEventListener ( "change" , ( newState ) => {
663
- newState === "active" && CodePush . sync ( options , syncStatusCallback , downloadProgressCallback ) ;
660
+ if ( newState === "active" ) {
661
+ CodePush . sync ( options , syncStatusCallback , downloadProgressCallback ) ;
662
+ }
664
663
} ) ;
665
664
}
666
665
}
@@ -669,17 +668,17 @@ function codePushify(options = {}) {
669
668
render ( ) {
670
669
const props = { ...this . props } ;
671
670
672
- // we can set ref property on class components only (not stateless)
673
- // check it by render method
674
- if ( RootComponent . prototype . render ) {
675
- props . ref = "rootComponent" ;
671
+ // We can set ref property on class components only (not stateless)
672
+ // Check it by render method
673
+ if ( RootComponent . prototype && RootComponent . prototype . render ) {
674
+ props . ref = this . rootComponentRef ;
676
675
}
677
676
678
677
return < RootComponent { ...props } />
679
678
}
680
679
}
681
680
682
- return hoistStatics ( extended , RootComponent ) ;
681
+ return hoistStatics ( CodePushComponent , RootComponent ) ;
683
682
}
684
683
685
684
if ( typeof options === "function" ) {
0 commit comments