@@ -71,9 +71,16 @@ class ApplicationLinker {
71
71
/ 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,
72
72
'extends NavigationApplication'
73
73
)
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()' )
74
75
. replace (
76
+ // Java
75
77
'import com.facebook.react.ReactApplication;' ,
76
78
'import com.reactnativenavigation.NavigationApplication;'
79
+ )
80
+ . replace (
81
+ // Kotlin
82
+ 'import com.facebook.react.ReactApplication' ,
83
+ 'import com.reactnativenavigation.NavigationApplication'
77
84
) ;
78
85
}
79
86
@@ -88,13 +95,18 @@ class ApplicationLinker {
88
95
}
89
96
90
97
_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 )
93
102
) ;
94
103
}
95
104
96
105
_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
+ ) ;
98
110
}
99
111
100
112
_extendNavigationHost ( applicationContent ) {
@@ -114,10 +126,17 @@ class ApplicationLinker {
114
126
} else if ( this . _doesExtendDefaultReactNativeHost ( applicationContent ) ) {
115
127
debugn ( ' Changing host implementation to NavigationReactNativeHost' ) ;
116
128
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
118
131
. replace (
132
+ // Java
119
133
'import com.facebook.react.defaults.DefaultReactNativeHost;' ,
120
134
'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'
121
140
) ;
122
141
}
123
142
@@ -129,27 +148,43 @@ class ApplicationLinker {
129
148
}
130
149
131
150
_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
+ ) ;
133
155
}
134
156
135
157
_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
+ ) ;
137
162
}
138
163
139
164
_removeSOLoaderInit ( applicationContent ) {
140
165
if ( this . _isSOLoaderInitCalled ( applicationContent ) ) {
141
166
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
+ ) ;
146
178
}
147
179
warnn ( ' SOLoader.init() is not called, skipping.' ) ;
148
180
return applicationContent ;
149
181
}
150
182
151
183
_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
+ ) ;
153
188
}
154
189
}
155
190
0 commit comments