@@ -54,16 +54,20 @@ class ActivityLinker {
5454 }
5555
5656 _removeGetMainComponentName ( contents ) {
57- var match = / \/ \* \* \s * \n ( [ ^ \* ] | ( \* (? ! \/ ) ) ) * \* \/ \s * @ O v e r r i d e \s * p r o t e c t e d \s * S t r i n g \s * g e t M a i n C o m p o n e n t N a m e \s * \( \) \s * { \s * r e t u r n .+ \s * \} / . exec (
58- contents
59- ) ;
60- if ( match ) {
61- debugn ( ' Removing getMainComponentName function' ) ;
62- return contents . replace (
63- / \/ \* \* \s * \n ( [ ^ \* ] | ( \* (? ! \/ ) ) ) * \* \/ \s * @ O v e r r i d e \s * p r o t e c t e d \s * S t r i n g \s * g e t M a i n C o m p o n e n t N a m e \s * \( \) \s * { \s * r e t u r n .+ \s * \} / ,
64- ''
65- ) ;
57+ var javaRegex = / \/ \* \* \s * \n ( [ ^ \* ] | ( \* (? ! \/ ) ) ) * \* \/ \s * @ O v e r r i d e \s * p r o t e c t e d \s * S t r i n g \s * g e t M a i n C o m p o n e n t N a m e \s * \( \) \s * { \s * r e t u r n .+ \s * \} / ;
58+ var javaMatch = javaRegex . exec ( contents ) ;
59+ if ( javaMatch ) {
60+ debugn ( ' [Java] Removing getMainComponentName function' ) ;
61+ return contents . replace ( javaRegex , '' ) ;
62+ }
63+
64+ var kotlinRegex = / \/ \* \* \s * \n ( [ ^ \* ] | ( \* (? ! \/ ) ) ) * \* \/ \s * o v e r r i d e \s f u n \s g e t M a i n C o m p o n e n t N a m e \( \) : \s S t r i n g \s = \s .+ / ;
65+ var kotlinMatch = kotlinRegex . exec ( contents ) ;
66+ if ( kotlinMatch ) {
67+ debugn ( ' [Kotlin] Removing getMainComponentName function' ) ;
68+ return contents . replace ( kotlinRegex , '' ) ;
6669 }
70+
6771 warnn ( ' getMainComponentName function was not found.' ) ;
6872 return contents ;
6973 }
@@ -78,6 +82,7 @@ class ActivityLinker {
7882 debugn ( ' Extending NavigationActivity' ) ;
7983 return activityContent
8084 . replace ( / e x t e n d s \s + R e a c t A c t i v i t y \s * / , 'extends NavigationActivity ' )
85+ . replace ( / R e a c t A c t i v i t y \( \) / , 'NavigationActivity()' )
8186 . replace (
8287 / p u b l i c \s + M a i n A c t i v i t y D e l e g a t e \s * \( \s * R e a c t A c t i v i t y \s + a c t i v i t y , \s * S t r i n g \s + m a i n C o m p o n e n t N a m e \s * \) / ,
8388 'public MainActivityDelegate(NavigationActivity activity, String mainComponentName)'
@@ -94,30 +99,34 @@ class ActivityLinker {
9499 }
95100
96101 _doesActivityExtendReactActivity ( activityContent ) {
97- return / p u b l i c \s + c l a s s \s + M a i n A c t i v i t y \s + e x t e n d s \s + R e a c t A c t i v i t y \s * / . test ( activityContent ) ;
102+ return (
103+ / p u b l i c \s + c l a s s \s + M a i n A c t i v i t y \s + e x t e n d s \s + R e a c t A c t i v i t y \s * / . test ( activityContent ) ||
104+ / c l a s s \s M a i n A c t i v i t y \s ? : \s ? R e a c t A c t i v i t y \( \) / . test ( activityContent )
105+ ) ;
98106 }
99107
100108 _hasAlreadyExtendNavigationActivity ( activityContent ) {
101- return / p u b l i c \s + c l a s s \s + M a i n A c t i v i t y \s + e x t e n d s \s + N a v i g a t i o n A c t i v i t y \s * / . test ( activityContent ) ;
109+ return (
110+ / p u b l i c \s + c l a s s \s + M a i n A c t i v i t y \s + e x t e n d s \s + N a v i g a t i o n A c t i v i t y \s * / . test ( activityContent ) ||
111+ / c l a s s \s M a i n A c t i v i t y \s : \s N a v i g a t i o n A c t i v i t y \( \) \s \{ / . test ( activityContent )
112+ ) ;
102113 }
103114
104115 _removeCreateReactActivityDelegate ( activityContent ) {
105- if ( this . _hasCreateReactActivityDelegate ( activityContent ) ) {
106- debugn ( ' Removing createReactActivityDelegate function' ) ;
107- return activityContent . replace (
108- / \/ \* \* \s * \n ( [ ^ \* ] | ( \* (? ! \/ ) ) ) * \* \/ \s * @ O v e r r i d e \s * p r o t e c t e d \s * R e a c t A c t i v i t y D e l e g a t e \s * c r e a t e R e a c t A c t i v i t y D e l e g a t e \s * \( \) \s * { \s * r e t u r n ( ( .| \r | \s ) * ?) } / ,
109- ''
110- ) ;
111- } else {
112- warnn ( ' createReactActivityDelegate is already not defined in MainActivity' ) ;
113- return activityContent ;
116+ var javaRegex = / \/ \* \* \s * \n ( [ ^ \* ] | ( \* (? ! \/ ) ) ) * \* \/ \s * @ O v e r r i d e \s * p r o t e c t e d \s * R e a c t A c t i v i t y D e l e g a t e \s * c r e a t e R e a c t A c t i v i t y D e l e g a t e \s * \( \) \s * { \s * r e t u r n ( ( .| \r | \s ) * ?) } / ;
117+ if ( javaRegex . test ( activityContent ) ) {
118+ debugn ( ' [Java] Removing createReactActivityDelegate function' ) ;
119+ return activityContent . replace ( javaRegex , '' ) ;
114120 }
115- }
116121
117- _hasCreateReactActivityDelegate ( activityContent ) {
118- return / \/ \* \* \s * \n ( [ ^ \* ] | ( \* (? ! \/ ) ) ) * \* \/ \s * @ O v e r r i d e \s * p r o t e c t e d \s * R e a c t A c t i v i t y D e l e g a t e \s * c r e a t e R e a c t A c t i v i t y D e l e g a t e \s * \( \) \s * { \s * r e t u r n ( ( .| \r | \s ) * ?) } / . test (
119- activityContent
120- ) ;
122+ var kotlinRegex = / \/ \* \* \s * \n ( [ ^ \* ] | ( \* (? ! \/ ) ) ) * \* \/ \s * o v e r r i d e \s f u n \s c r e a t e R e a c t A c t i v i t y D e l e g a t e \( \) : \s R e a c t A c t i v i t y D e l e g a t e \s = \s + D e f a u l t R e a c t A c t i v i t y D e l e g a t e \( t h i s , \s m a i n C o m p o n e n t N a m e , \s f a b r i c E n a b l e d \) / ;
123+ if ( kotlinRegex . test ( activityContent ) ) {
124+ debugn ( ' [Kotlin] Removing createReactActivityDelegate function' ) ;
125+ return activityContent . replace ( kotlinRegex , '' ) ;
126+ }
127+
128+ warnn ( ' createReactActivityDelegate is already not defined in MainActivity' ) ;
129+ return activityContent ;
121130 }
122131}
123132
0 commit comments