@@ -6,6 +6,7 @@ var { warnn, logn, infon, debugn, errorn } = require('./log');
66class AppDelegateLinker {
77 constructor ( ) {
88 this . appDelegatePath = path . appDelegate ;
9+ this . appDelegateHeaderPath = path . appDelegateHeader ;
910 this . removeUnneededImportsSuccess = false ;
1011 this . removeApplicationLaunchContentSuccess = false ;
1112 }
@@ -22,6 +23,12 @@ class AppDelegateLinker {
2223
2324 var appDelegateContents = fs . readFileSync ( this . appDelegatePath , 'utf8' ) ;
2425
26+ if ( this . appDelegateHeaderPath ) {
27+ var appDelegateHeaderContents = fs . readFileSync ( this . appDelegateHeaderPath , 'utf8' ) ;
28+ appDelegateHeaderContents = this . _extendRNNAppDelegate ( appDelegateHeaderContents ) ;
29+ fs . writeFileSync ( this . appDelegateHeaderPath , appDelegateHeaderContents ) ;
30+ }
31+
2532 try {
2633 appDelegateContents = this . _removeUnneededImports ( appDelegateContents ) ;
2734 this . removeUnneededImportsSuccess = true ;
@@ -33,8 +40,6 @@ class AppDelegateLinker {
3340
3441 appDelegateContents = this . _bootstrapNavigation ( appDelegateContents ) ;
3542
36- appDelegateContents = this . _extraModulesForBridge ( appDelegateContents ) ;
37-
3843 try {
3944 appDelegateContents = this . _removeApplicationLaunchContent ( appDelegateContents ) ;
4045 this . removeApplicationLaunchContentSuccess = true ;
@@ -81,6 +86,18 @@ class AppDelegateLinker {
8186 return content ;
8287 }
8388
89+ _extendRNNAppDelegate ( content ) {
90+ return content
91+ . replace (
92+ / # i m p o r t * .< R C T A p p D e l e g a t e .h > / ,
93+ '#import "RNNAppDelegate.h"'
94+ )
95+ . replace (
96+ / : * .R C T A p p D e l e g a t e / ,
97+ ': RNNAppDelegate'
98+ )
99+ }
100+
84101 _importNavigation ( content ) {
85102 if ( ! this . _doesImportNavigation ( content ) ) {
86103 debugn ( ' Importing ReactNativeNavigation.h' ) ;
@@ -105,52 +122,18 @@ class AppDelegateLinker {
105122 . replace (
106123 / R C T B r i d g e .* ] ; / ,
107124 'RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];\n' +
108- '[ReactNativeNavigation bootstrapWithBridge:bridge];'
109- )
110- . replace (
111- / r e t u r n \[ s u p e r a p p l i c a t i o n : a p p l i c a t i o n d i d F i n i s h L a u n c h i n g W i t h O p t i o n s : l a u n c h O p t i o n s \] ; / ,
112- 'return YES;'
125+ '[ReactNativeNavigation bootstrapWithBridge:bridge];'
113126 )
114127 . replace (
115- / s e l f .m o d u l e N a m e .* ; / ,
116- 'RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];\n' +
117- ' [ReactNativeNavigation bootstrapWithBridge:bridge];'
128+ / s e l f .m o d u l e N a m e .* ; ( .| \n ) * @ { } ; \n ? / ,
129+ ''
118130 ) ;
119131 }
120132
121133 _doesBootstrapNavigation ( content ) {
122134 return / R e a c t N a t i v e N a v i g a t i o n \s + b o o t s t r a p / . test ( content ) ;
123135 }
124136
125- _extraModulesForBridge ( content ) {
126- if ( this . _doesImplementsRNNExtraModulesForBridge ( content ) ) {
127- warnn ( ' extraModulesForBridge already present.' ) ;
128- return content ;
129- } else if ( this . _doesImplementsExtraModulesForBridge ( content ) ) {
130- throw new Error (
131- 'extraModulesForBridge implemented for a different module and needs manual linking. Check the manual installation docs to verify that everything is properly setup:\n https://wix.github.io/react-native-navigation/docs/installing#native-installation'
132- ) ;
133- }
134-
135- debugn ( ' Implementing extraModulesForBridge' ) ;
136- return content . replace (
137- / - .* \( N S U R L .* \* \) s o u r c e U R L F o r B r i d g e : \( R C T B r i d g e .* \* \) b r i d g e / ,
138- '- (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge {\n\
139- return [ReactNativeNavigation extraModulesForBridge:bridge];\n\
140- }\n\
141- \n\
142- - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge'
143- ) ;
144- }
145-
146- _doesImplementsExtraModulesForBridge ( content ) {
147- return / - .* \( N S A r r a y .* \* \) e x t r a M o d u l e s F o r B r i d g e : \( R C T B r i d g e .* \* \) b r i d g e / . test ( content ) ;
148- }
149-
150- _doesImplementsRNNExtraModulesForBridge ( content ) {
151- return / R e a c t N a t i v e N a v i g a t i o n \s + e x t r a M o d u l e s F o r B r i d g e / . test ( content ) ;
152- }
153-
154137 _removeApplicationLaunchContent ( content ) {
155138 debugn ( ' Removing Application launch content' ) ;
156139
0 commit comments