@@ -71,9 +71,16 @@ class ApplicationLinker {
7171 / e x t e n d s \s + A p p l i c a t i o n \s + i m p l e m e n t s \s + R e a c t A p p l i c a t i o n / gi,
7272 'extends NavigationApplication'
7373 )
74+ . replace ( / : \s A p p l i c a t i o n \( \) , \s R e a c t A p p l i c a t i o n / , ': NavigationApplication()' )
7475 . replace (
76+ // Java
7577 'import com.facebook.react.ReactApplication;' ,
7678 'import com.reactnativenavigation.NavigationApplication;'
79+ )
80+ . replace (
81+ // Kotlin
82+ 'import com.facebook.react.ReactApplication' ,
83+ 'import com.reactnativenavigation.NavigationApplication'
7784 ) ;
7885 }
7986
@@ -88,13 +95,18 @@ class ApplicationLinker {
8895 }
8996
9097 _doesExtendApplication ( applicationContent ) {
91- return / \s + M a i n A p p l i c a t i o n \s + e x t e n d s \s + A p p l i c a t i o n \s + i m p l e m e n t s \s + R e a c t A p p l i c a t i o n \s + / . test (
92- applicationContent
98+ return (
99+ / \s + M a i n A p p l i c a t i o n \s + e x t e n d s \s + A p p l i c a t i o n \s + i m p l e m e n t s \s + R e a c t A p p l i c a t i o n \s + / . test (
100+ applicationContent
101+ ) || / c l a s s \s M a i n A p p l i c a t i o n \s : \s A p p l i c a t i o n \( \) , \s R e a c t A p p l i c a t i o n / . test ( applicationContent )
93102 ) ;
94103 }
95104
96105 _hasAlreadyLinkedApplication ( applicationContent ) {
97- return / \s + e x t e n d s \s + N a v i g a t i o n A p p l i c a t i o n \s + / . test ( applicationContent ) ;
106+ return (
107+ / \s + e x t e n d s \s + N a v i g a t i o n A p p l i c a t i o n \s + / . test ( applicationContent ) ||
108+ / c l a s s \s M a i n A p p l i c a t i o n \s : \s N a v i g a t i o n A p p l i c a t i o n \( \) / . test ( applicationContent )
109+ ) ;
98110 }
99111
100112 _extendNavigationHost ( applicationContent ) {
@@ -114,10 +126,17 @@ class ApplicationLinker {
114126 } else if ( this . _doesExtendDefaultReactNativeHost ( applicationContent ) ) {
115127 debugn ( ' Changing host implementation to NavigationReactNativeHost' ) ;
116128 return applicationContent
117- . replace ( 'new DefaultReactNativeHost(this)' , 'new NavigationReactNativeHost(this)' )
129+ . replace ( 'new DefaultReactNativeHost(this)' , 'new NavigationReactNativeHost(this)' ) // Java
130+ . replace ( 'DefaultReactNativeHost(this)' , 'NavigationReactNativeHost(this)' ) // Kotlin
118131 . replace (
132+ // Java
119133 'import com.facebook.react.defaults.DefaultReactNativeHost;' ,
120134 'import com.facebook.react.defaults.DefaultReactNativeHost;\nimport com.reactnativenavigation.react.NavigationReactNativeHost;'
135+ )
136+ . replace (
137+ // Kotlin
138+ / i m p o r t \s c o m \. f a c e b o o k \. r e a c t \. d e f a u l t s \. D e f a u l t R e a c t N a t i v e H o s t \n / ,
139+ 'import com.facebook.react.defaults.DefaultReactNativeHost\nimport com.reactnativenavigation.react.NavigationReactNativeHost\n'
121140 ) ;
122141 }
123142
@@ -129,27 +148,43 @@ class ApplicationLinker {
129148 }
130149
131150 _doesExtendDefaultReactNativeHost ( applicationContent ) {
132- return / \s * n e w D e f a u l t R e a c t N a t i v e H o s t \( t h i s \) \s * / . test ( applicationContent ) ;
151+ return (
152+ / \s * n e w D e f a u l t R e a c t N a t i v e H o s t \( t h i s \) \s * / . test ( applicationContent ) ||
153+ / D e f a u l t R e a c t N a t i v e H o s t \( t h i s \) / . test ( applicationContent )
154+ ) ;
133155 }
134156
135157 _hasAlreadyLinkedNavigationHost ( applicationContent ) {
136- return / \s * n e w N a v i g a t i o n R e a c t N a t i v e H o s t \( t h i s \) \s * / . test ( applicationContent ) ;
158+ return (
159+ / \s * n e w N a v i g a t i o n R e a c t N a t i v e H o s t \( t h i s \) \s * / . test ( applicationContent ) ||
160+ / N a v i g a t i o n R e a c t N a t i v e H o s t \( t h i s \) / . test ( applicationContent )
161+ ) ;
137162 }
138163
139164 _removeSOLoaderInit ( applicationContent ) {
140165 if ( this . _isSOLoaderInitCalled ( applicationContent ) ) {
141166 debugn ( ' Removing call to SOLoader.init()' ) ;
142- return applicationContent . replace (
143- / S o L o a d e r .i n i t \( \s * t h i s \s * , \s * [ / * n a t i v e e x o p a c k a g e * / ] * \s * f a l s e \s * \) ; / ,
144- ''
145- ) ;
167+ return applicationContent
168+ . replace (
169+ // Java
170+ / S o L o a d e r .i n i t \( \s * t h i s \s * , \s * [ / * n a t i v e e x o p a c k a g e * / ] * \s * f a l s e \s * \) ; / ,
171+ ''
172+ )
173+ . replace (
174+ // Kotlin
175+ / S o L o a d e r \. i n i t \( t h i s , \s f a l s e \) / ,
176+ ''
177+ ) ;
146178 }
147179 warnn ( ' SOLoader.init() is not called, skipping.' ) ;
148180 return applicationContent ;
149181 }
150182
151183 _isSOLoaderInitCalled ( applicationContent ) {
152- return / S o L o a d e r .i n i t \( t h i s , \s * [ / * n a t i v e e x o p a c k a g e * / ] * \s * f a l s e \) ; / . test ( applicationContent ) ;
184+ return (
185+ / S o L o a d e r .i n i t \( t h i s , \s * [ / * n a t i v e e x o p a c k a g e * / ] * \s * f a l s e \) ; / . test ( applicationContent ) ||
186+ / S o L o a d e r \. i n i t \( t h i s , \s f a l s e \) / . test ( applicationContent )
187+ ) ;
153188 }
154189}
155190
0 commit comments