Skip to content

Commit

Permalink
Fix auto link for RN72 on Android (#7758)
Browse files Browse the repository at this point in the history
Closes #7748
  • Loading branch information
yogevbd authored Aug 1, 2023
1 parent 06ff96d commit d8c9638
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
22 changes: 17 additions & 5 deletions autolink/postlink/applicationLinker.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ class ApplicationLinker {
}

_extendNavigationHost(applicationContent) {
if (this._hasAlreadyLinkedNavigationHost(applicationContent)) {
warnn(' NavigationReactNativeHost is already used, skipping.');
return applicationContent;
}

if (this._doesExtendReactNativeHost(applicationContent)) {
debugn(' Changing host implementation to NavigationReactNativeHost');
return applicationContent
Expand All @@ -106,11 +111,14 @@ class ApplicationLinker {
'import com.facebook.react.ReactNativeHost;',
'import com.facebook.react.ReactNativeHost;\nimport com.reactnativenavigation.react.NavigationReactNativeHost;'
);
}

if (this._hasAlreadyLinkedNavigationHost(applicationContent)) {
warnn(' NavigationReactNativeHost is already used, skipping.');
return applicationContent;
} else if (this._doesExtendDefaultReactNativeHost(applicationContent)) {
debugn(' Changing host implementation to NavigationReactNativeHost');
return applicationContent
.replace('new DefaultReactNativeHost(this)', 'new NavigationReactNativeHost(this)')
.replace(
'import com.facebook.react.defaults.DefaultReactNativeHost;',
'import com.facebook.react.defaults.DefaultReactNativeHost;\nimport com.reactnativenavigation.react.NavigationReactNativeHost;'
);
}

throw new Error('There was a problem extending NavigationReactNativeHost().');
Expand All @@ -120,6 +128,10 @@ class ApplicationLinker {
return /\s*new ReactNativeHost\(this\)\s*/.test(applicationContent);
}

_doesExtendDefaultReactNativeHost(applicationContent) {
return /\s*new DefaultReactNativeHost\(this\)\s*/.test(applicationContent);
}

_hasAlreadyLinkedNavigationHost(applicationContent) {
return /\s*new NavigationReactNativeHost\(this\)\s*/.test(applicationContent);
}
Expand Down
4 changes: 2 additions & 2 deletions autolink/postlink/gradleLinker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var path = require('./path');
var fs = require('fs');
var { warnn, errorn, logn, infon, debugn } = require('./log');
var { insertString } = require('./stringUtils');
var DEFAULT_KOTLIN_VERSION = '1.5.31';
var DEFAULT_KOTLIN_VERSION = '1.7.10';
// This should be the minSdkVersion required for RNN.
var DEFAULT_MIN_SDK_VERSION = 21;

Expand Down Expand Up @@ -74,7 +74,7 @@ class GradleLinker {
return contents;
}

var match = /classpath\s*\(*["']com\.android\.tools\.build:gradle:/.exec(contents);
var match = /classpath\s*\(*["']com\.android\.tools\.build:gradle.*/.exec(contents);
if (match) {
debugn(' Adding Kotlin plugin');
return insertString(
Expand Down

0 comments on commit d8c9638

Please sign in to comment.