@@ -625,42 +625,41 @@ function codePushify(options = {}) {
625625 sharedCodePushOptions . setUpdateChecker ( options . updateChecker ) ;
626626 sharedCodePushOptions . setFallbackToAppCenter ( options . fallbackToAppCenter ) ;
627627
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+
630635 componentDidMount ( ) {
631636 if ( options . checkFrequency === CodePush . CheckFrequency . MANUAL ) {
632637 CodePush . notifyAppReady ( ) ;
633638 } else {
634- let rootComponentInstance = this . refs . rootComponent ;
639+ const rootComponentInstance = this . rootComponentRef . current ;
635640
636641 let syncStatusCallback ;
637642 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 ) ;
642644 }
643645
644646 let downloadProgressCallback ;
645647 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 ) ;
650649 }
651650
652651 let handleBinaryVersionMismatchCallback ;
653652 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 ) ;
658654 }
659655
660656 CodePush . sync ( options , syncStatusCallback , downloadProgressCallback , handleBinaryVersionMismatchCallback ) ;
657+
661658 if ( options . checkFrequency === CodePush . CheckFrequency . ON_APP_RESUME ) {
662659 ReactNative . AppState . addEventListener ( "change" , ( newState ) => {
663- newState === "active" && CodePush . sync ( options , syncStatusCallback , downloadProgressCallback ) ;
660+ if ( newState === "active" ) {
661+ CodePush . sync ( options , syncStatusCallback , downloadProgressCallback ) ;
662+ }
664663 } ) ;
665664 }
666665 }
@@ -669,17 +668,17 @@ function codePushify(options = {}) {
669668 render ( ) {
670669 const props = { ...this . props } ;
671670
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 ;
676675 }
677676
678677 return < RootComponent { ...props } />
679678 }
680679 }
681680
682- return hoistStatics ( extended , RootComponent ) ;
681+ return hoistStatics ( CodePushComponent , RootComponent ) ;
683682 }
684683
685684 if ( typeof options === "function" ) {
0 commit comments