Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into feature/rnnav-crash-fixes

* 'master' of https://github.com/wix/react-native-navigation: (627 commits)
  Fix title component not being replaced via mergeOptions (wix#6066)
  Remove Shared Element Screen from Options screen (wix#6065)
  Configure scrollEdgeAppearance with opaque background (wix#6038)
  Update package.json version to 6.3.1 [ci skip]
  Always resolve dismissAllModals promise (wix#6054)
  Custom component reference id OptionsTopBarButton typing (wix#6053)
  Some work on animation config in the playground app
  Update changelog
  Update package.json version to 6.3.0 [ci skip]
  Resolve options from bottomTabs direct child in mergeChildOptions (wix#6050)
  Fix build warnings on iOS (wix#6047)
  Reject pop command when viewController not found in the hierarchy (wix#6048)
  Merge options with correct child (wix#6041)
  Removes unable to find UIManager module warning (wix#6043)
  Fix overlays touch interception on new iPads (wix#6042)
  Update Stack Overflow tag in readme
  Update changelog
  Added two icons to playground app
  Added Toast component to playground
  Update slow animations in playground
  ...

# Conflicts:
#	CHANGELOG.md
#	babel.config.js
#	docs/docs/Installing.md
#	docs/docs/events.md
#	docs/docs/showcases.md
#	docs/docs/styling.md
#	docs/docs/topBar-buttons.md
#	lib/android/app/build.gradle
#	lib/android/app/src/main/java/com/reactnativenavigation/NavigationActivity.java
#	lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java
#	lib/android/app/src/main/java/com/reactnativenavigation/parse/TitleOptions.java
#	lib/android/app/src/main/java/com/reactnativenavigation/presentation/BottomTabPresenter.java
#	lib/android/app/src/main/java/com/reactnativenavigation/presentation/BottomTabsPresenter.java
#	lib/android/app/src/main/java/com/reactnativenavigation/presentation/ComponentPresenter.java
#	lib/android/app/src/main/java/com/reactnativenavigation/presentation/Presenter.java
#	lib/android/app/src/main/java/com/reactnativenavigation/presentation/SideMenuPresenter.java
#	lib/android/app/src/main/java/com/reactnativenavigation/presentation/StackPresenter.java
#	lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java
#	lib/android/app/src/main/java/com/reactnativenavigation/react/ReactView.java
#	lib/android/app/src/main/java/com/reactnativenavigation/utils/CollectionUtils.java
#	lib/android/app/src/main/java/com/reactnativenavigation/utils/Functions.java
#	lib/android/app/src/main/java/com/reactnativenavigation/utils/ImageLoader.java
#	lib/android/app/src/main/java/com/reactnativenavigation/utils/NoOpPromise.java
#	lib/android/app/src/main/java/com/reactnativenavigation/utils/ObjectUtils.java
#	lib/android/app/src/main/java/com/reactnativenavigation/utils/ViewUtils.java
#	lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ComponentViewController.java
#	lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/IdStack.java
#	lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ParentController.java
#	lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/TitleBarButtonController.java
#	lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/TitleBarReactViewController.java
#	lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java
#	lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsController.java
#	lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/button/IconResolver.java
#	lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/navigator/Navigator.java
#	lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/navigator/RootPresenter.java
#	lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/sidemenu/SideMenuController.java
#	lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackController.java
#	lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerBuilder.java
#	lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/topbar/TopBarBackgroundViewController.java
#	lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/topbar/TopBarController.java
#	lib/android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java
#	lib/android/app/src/main/java/com/reactnativenavigation/views/Component.java
#	lib/android/app/src/main/java/com/reactnativenavigation/views/Fab.java
#	lib/android/app/src/main/java/com/reactnativenavigation/views/StackLayout.java
#	lib/android/app/src/main/java/com/reactnativenavigation/views/topbar/TopBar.java
#	lib/android/app/src/reactNative57_5/java/com/reactnativenavigation/react/NavigationReactNativeHost.java
#	lib/android/app/src/reactNative57_5/java/com/reactnativenavigation/react/SyncUiImplementation.java
#	lib/android/app/src/test/java/com/reactnativenavigation/TestUtils.java
#	lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ComponentViewControllerTest.java
#	lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsApplyingTest.java
#	lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackPresenterTest.java
#	lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopBarControllerTest.java
#	lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsControllerTest.java
#	lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/navigator/NavigatorTest.java
#	lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/navigator/RootPresenterTest.java
#	lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/sidemenu/SideMenuControllerTest.java
#	lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java
#	lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarTest.java
#	lib/ios/RNNBridgeManager.m
#	lib/ios/RNNBridgeModule.m
#	lib/ios/RNNCommandsHandler.h
#	lib/ios/RNNCommandsHandler.m
#	lib/ios/RNNControllerFactory.m
#	lib/ios/RNNLeafProtocol.h
#	lib/ios/RNNNavigationButtons.m
#	lib/ios/RNNNavigationController.m
#	lib/ios/RNNNavigationControllerPresenter.m
#	lib/ios/RNNNavigationStackManager.m
#	lib/ios/RNNRootViewController.m
#	lib/ios/RNNScreenTransition.h
#	lib/ios/RNNScreenTransition.m
#	lib/ios/RNNSideMenuChildVC.m
#	lib/ios/RNNSideMenuController.m
#	lib/ios/RNNTabBarController.m
#	lib/ios/RNNTabBarPresenter.m
#	lib/ios/RNNTransitionsOptions.h
#	lib/ios/RNNUIBarButtonItem.h
#	lib/ios/RNNUIBarButtonItem.m
#	lib/ios/RNNViewControllerPresenter.m
#	lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj
#	lib/ios/ReactNativeNavigationTests/RNNCommandsHandlerTest.m
#	lib/ios/ReactNativeNavigationTests/RNNSideMenuPresenterTest.m
#	lib/ios/ReactNativeNavigationTests/RNNTabBarPresenterTest.m
#	lib/ios/UINavigationController+RNNCommands.h
#	lib/ios/UIViewController+RNNOptions.h
#	lib/ios/UIViewController+RNNOptions.m
#	lib/src/Navigation.ts
#	lib/src/adapters/Constants.ts
#	lib/src/adapters/NativeEventsReceiver.ts
#	lib/src/adapters/TouchablePreview.tsx
#	lib/src/adapters/UniqueIdProvider.ts
#	lib/src/commands/Commands.test.ts
#	lib/src/commands/Commands.ts
#	lib/src/commands/LayoutTreeCrawler.test.ts
#	lib/src/commands/LayoutTreeCrawler.ts
#	lib/src/commands/LayoutTreeParser.test.ts
#	lib/src/commands/LayoutTreeParser.ts
#	lib/src/commands/OptionsProcessor.test.ts
#	lib/src/commands/OptionsProcessor.ts
#	lib/src/components/ComponentRegistry.test.tsx
#	lib/src/components/ComponentWrapper.test.tsx
#	lib/src/components/ComponentWrapper.tsx
#	lib/src/components/Store.test.ts
#	lib/src/components/Store.ts
#	lib/src/events/ComponentEventsObserver.test.tsx
#	lib/src/events/ComponentEventsObserver.ts
#	lib/src/events/EventsRegistry.ts
#	lib/src/interfaces/Layout.ts
#	lib/src/interfaces/Options.ts
#	metro.config.js
#	package.json
#	playground/android/app/build.gradle
#	playground/android/app/src/main/AndroidManifest.xml
#	playground/android/build.gradle
#	playground/android/gradle.properties
#	playground/android/gradle/wrapper/gradle-wrapper.properties
#	playground/ios/NavigationTests/RNNNavigationStackManagerTest.m
#	playground/ios/playground.xcodeproj/project.pbxproj
#	playground/src/app.js
#	playground/src/context/index.js
#	playground/src/screens/BackHandlerModalScreen.js
#	playground/src/screens/BackHandlerScreen.js
#	playground/src/screens/ComplexLayout.js
#	playground/src/screens/ContextScreen.js
#	playground/src/screens/CustomDialog.js
#	playground/src/screens/CustomTransitionDestination.js
#	playground/src/screens/CustomTransitionOrigin.js
#	playground/src/screens/ModalScreen.js
#	playground/src/screens/OptionsScreen.js
#	playground/src/screens/PushedScreen.js
#	playground/src/screens/SearchScreen.js
#	playground/src/screens/SideMenuScreen.js
#	playground/src/screens/TextScreen.js
#	playground/src/screens/WelcomeScreen.js
#	playground/src/screens/complexlayouts/CustomDialogWithScroll.js
#	playground/src/screens/index.js
#	playground/src/testIDs.js
#	scripts/release.js
#	scripts/test-unit.js
  • Loading branch information
Anush committed Mar 23, 2020
2 parents 73b93f5 + b0e8a82 commit aeec746
Show file tree
Hide file tree
Showing 904 changed files with 26,804 additions and 13,557 deletions.
4 changes: 4 additions & 0 deletions .github/ISSUE_TEMPLATE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

### Steps to Reproduce / Code Snippets / Screenshots

<!-- Note: When embeding code, please format it and use syntax highlighting to improve readability -->
<!-- ```js -->
<!-- [ THIS CODE BLOCK WILL USE JAVASCRIPT SYNTAX HIGHLIGHTING ] -->
<!-- ``` -->
[FILL THIS OUT]

---
Expand Down
4 changes: 2 additions & 2 deletions .github/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back.
If you believe the issue is still relevant, please test on the latest version and report back.
Thank you for your contributions.
# Comment to post when removing the stale label.
# unmarkComment: >
Expand All @@ -51,4 +51,4 @@ pulls:
for your contributions.
# issues:
# exemptLabels:
# - confirmed
# - confirmed
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.vscode/
package-lock.json
.history/

############
# Node
Expand Down
949 changes: 949 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![npm (tag)](https://img.shields.io/npm/v/react-native-navigation/snapshot.svg)](https://github.com/wix/react-native-navigation/tree/master)
[![Build Status](https://img.shields.io/jenkins/s/http/jenkins-oss.wixpress.com:8080/job/multi-react-native-navigation-master.svg)](https://jenkins-oss.wixpress.com/job/multi-react-native-navigation-master/)
[![Join us on Discord](https://img.shields.io/badge/discord-react--native--navigation-738bd7.svg?style=flat)](https://discord.gg/DhkZjq2)
[![StackExchange](https://img.shields.io/stackexchange/stackoverflow/t/react-native-navigation.svg)](https://stackoverflow.com/questions/tagged/react-native-navigation)
[![StackExchange](https://img.shields.io/stackexchange/stackoverflow/t/react-native-navigation.svg)](https://stackoverflow.com/questions/tagged/wix-react-native-navigation)

<h1 align="center">
<img src=".logo.png"/><br>
Expand All @@ -14,6 +14,7 @@ React Native Navigation provides 100% native platform navigation on both iOS and

# Quick Links
- [Documentation](https://wix.github.io/react-native-navigation/)
- [Changelog](https://github.com/wix/react-native-navigation/blob/master/CHANGELOG.md)
- [Stack Overflow](http://stackoverflow.com/questions/tagged/react-native-navigation)
- [Chat with us](https://discord.gg/DhkZjq2)
- [Contributing](/docs/docs/WorkingLocally.md)
Expand Down
2 changes: 2 additions & 0 deletions ReactNativeNavigation.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ Pod::Spec.new do |s|
s.exclude_files = "lib/ios/ReactNativeNavigationTests/**/*.*", "lib/ios/OCMock/**/*.*"

s.dependency 'React'
s.dependency 'React-RCTImage'
s.dependency 'React-RCTText'
s.frameworks = 'UIKit'
end
4 changes: 4 additions & 0 deletions autolink/postlink.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -e

echo "RNN postlink !!!!!!!!!!!!!!!!!"
50 changes: 50 additions & 0 deletions autolink/postlink/activityLinker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// @ts-check
var path = require('./path');
var fs = require("fs");
var { warnn, logn, infon, debugn } = require("./log");

class ActivityLinker {
constructor() {
this.activityPath = path.mainActivityJava;
}

link() {
logn("Linking MainActivity...");
if (this.activityPath) {
var activityContent = fs.readFileSync(this.activityPath, "utf8");
activityContent = this._extendNavigationActivity(activityContent);
activityContent = this._removeGetMainComponentName(activityContent);
fs.writeFileSync(this.activityPath, activityContent);
infon("MainActivity linked successfully!\n");
} else {
warnn(" MainActivity not found!");
}
}

_removeGetMainComponentName(contents) {
var match = /\/\*\*\s*\n([^\*]|(\*(?!\/)))*\*\/\s*@Override\s*protected\s*String\s*getMainComponentName\s*\(\)\s*{\s*return.+\s*\}/.exec(contents);
if (match) {
debugn(" Removing getMainComponentName function");
return contents.replace(/\/\*\*\s*\n([^\*]|(\*(?!\/)))*\*\/\s*@Override\s*protected\s*String\s*getMainComponentName\s*\(\)\s*{\s*return.+\s*\}/, "");
}
return contents;
}

_extendNavigationActivity(activityContent) {
if (this._doesActivityExtendReactActivity(activityContent)) {
debugn(" Extending NavigationActivity")
return activityContent
.replace(/extends\s+ReactActivity\s*/, "extends NavigationActivity ")
.replace("import com.facebook.react.ReactActivity;", "import com.reactnativenavigation.NavigationActivity;")
} else {
warnn(" MainActivity already extends NavigationActivity")
}
return activityContent;
}

_doesActivityExtendReactActivity(activityContent) {
return /public\s+class\s+MainActivity\s+extends\s+ReactActivity\s*/.test(activityContent);
}
}

module.exports = ActivityLinker;
78 changes: 78 additions & 0 deletions autolink/postlink/appDelegateLinker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// @ts-check
var path = require('./path');
var fs = require("fs");
var {warnn, logn, infon, debugn} = require("./log");

class ApplicationLinker {
constructor() {
this.appDelegatePath = path.appDelegate;
}

link() {
if (this.appDelegatePath) {
logn("Linking AppDelegate...");
var appDelegateContents = fs.readFileSync(this.appDelegatePath, "utf8");
if (this._doesBootstrapNavigation(appDelegateContents)) {
infon("AppDelegate already linked\n");
return;
}
appDelegateContents = this._removeUnneededImports(appDelegateContents);
appDelegateContents = this._importNavigation(appDelegateContents);
appDelegateContents = this._bootstrapNavigation(appDelegateContents);
appDelegateContents = this._removeApplicationLaunchContent(appDelegateContents);
fs.writeFileSync(this.appDelegatePath, appDelegateContents);
infon("AppDelegate linked successfully!\n");
}
}

_doesBootstrapNavigation(applicationContent) {
return /ReactNativeNavigation\s+bootstrap/.test(applicationContent);
}

_removeUnneededImports(applicationContent) {
const unneededImports = [/\#import\s+\<React\/RCTBridge.h>\s/, /#import\s+\<React\/RCTRootView.h>\s/];
debugn(" Removing Unneeded imports");
unneededImports.forEach(unneededImport => {
if (unneededImport.test(applicationContent)) {
applicationContent = applicationContent.replace(unneededImport, "");
}
});

return applicationContent;
}

_importNavigation(applicationContent) {
if (!this._doesImportNavigation(applicationContent)) {
debugn(" ");
return applicationContent
.replace(/#import\s+"AppDelegate.h"/, "#import \"AppDelegate.h\"\n#import <ReactNativeNavigation/ReactNativeNavigation.h>")
}
warnn(" AppDelegate already imports Navigation");
return applicationContent;
}

_removeApplicationLaunchContent(applicationContent) {
const toRemove = [/RCTRootView\s+\*rootView((.|\r|\s)*?)];\s+/, /rootView.backgroundColor((.|\r)*)];\s+/,
/self.window((.|\r)*)];\s+/, /UIViewController\s\*rootViewController((.|\r)*)];\s+/, /rootViewController\.view\s+=\s+rootView;\s+/,
/self.window.rootViewController\s+=\s+rootViewController;\s+/, /\[self.window\s+makeKeyAndVisible];\s+/
]

toRemove.forEach(element => {
if (element.test(applicationContent)) {
applicationContent = applicationContent.replace(element, "");
}
});

return applicationContent;
}

_bootstrapNavigation(applicationContent) {
return applicationContent.replace(/RCTBridge.*];/, "[ReactNativeNavigation bootstrapWithDelegate:self launchOptions:launchOptions];");
}

_doesImportNavigation(applicationContent) {
return /#import\s+\<ReactNativeNavigation\/ReactNativeNavigation.h>/.test(applicationContent);
}
}

module.exports = ApplicationLinker;
68 changes: 68 additions & 0 deletions autolink/postlink/applicationLinker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// @ts-check
var path = require('./path');
var fs = require("fs");
var { warnn, logn, infon, debugn } = require("./log");

class ApplicationLinker {
constructor() {
this.applicationPath = path.mainApplicationJava;
}

link() {
if (this.applicationPath) {
logn("Linking MainApplication...");
var applicationContents = fs.readFileSync(this.applicationPath, "utf8");
var linkers = [this._extendNavigationApplication, this._extendNavigationHost, this._removeSOLoaderInit];
applicationContents = this._extendNavigationApplication(applicationContents);
applicationContents = this._extendNavigationHost(applicationContents);
applicationContents = this._removeSOLoaderInit(applicationContents);
fs.writeFileSync(this.applicationPath, applicationContents);
infon("MainApplication linked successfully!\n");
}
}

_extendNavigationApplication(applicationContent) {
if (this._doesExtendApplication(applicationContent)) {
debugn(" Extending NavigationApplication");
return applicationContent
.replace(/extends\s+Application\s+implements\s+ReactApplication/gi, "extends NavigationApplication")
.replace("import com.facebook.react.ReactApplication;", "import com.reactnativenavigation.NavigationApplication;");
}
warnn(" MainApplication already extends NavigationApplication");
return applicationContent;
}

_doesExtendApplication(applicationContent) {
return /\s+MainApplication\s+extends\s+Application\s+implements\s+ReactApplication\s+/.test(applicationContent);
}

_extendNavigationHost(applicationContent) {
if (this._doesExtendReactNativeHost(applicationContent)) {
debugn(" Changing host implementation to NavigationReactNativeHost");
return applicationContent
.replace("new ReactNativeHost(this)", "new NavigationReactNativeHost(this)")
.replace("import com.facebook.react.ReactNativeHost;", "import com.facebook.react.ReactNativeHost;\nimport com.reactnativenavigation.react.NavigationReactNativeHost;")
}
warnn(" NavigationReactNativeHost is already used");
return applicationContent;
}

_removeSOLoaderInit(applicationContent) {
if (this._isSOLoaderInitCalled(applicationContent)) {
debugn(" Removing call to SOLoader.init()");
return applicationContent.replace(/SoLoader.init\(\s*this\s*,\s*[/* native exopackage */]*\s*false\s*\);/, "")
}
warnn(" SOLoader.init() is not called");
return applicationContent;
}

_isSOLoaderInitCalled(applicationContent) {
return /SoLoader.init\(this,\s*[/* native exopackage */]*\s*false\);/.test(applicationContent);
}

_doesExtendReactNativeHost(applicationContent) {
return /\s*new ReactNativeHost\(this\)\s*/.test(applicationContent);
}
}

module.exports = ApplicationLinker;
128 changes: 128 additions & 0 deletions autolink/postlink/gradleLinker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// @ts-check
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.3.61';
// This should be the minSdkVersion required for RNN.
var DEFAULT_MIN_SDK_VERSION = 19

class GradleLinker {
constructor() {
this.gradlePath = path.rootGradle;
}

link() {
logn('Linking root build.gradle...');
if (this.gradlePath) {
var contents = fs.readFileSync(this.gradlePath, 'utf8');
contents = this._setKotlinVersion(contents);
contents = this._setKotlinPluginDependency(contents);
contents = this._setMinSdkVersion(contents);
fs.writeFileSync(this.gradlePath, contents);
infon('Root build.gradle linked successfully!\n');
} else {
warnn(' Root build.gradle not found!');
}
}

_setKotlinPluginDependency(contents) {
if (this._isKotlinPluginDeclared(contents)) {
warnn(' Kotlin plugin already declared')
return contents;
}
var match = /classpath\s*\(*["']com\.android\.tools\.build:gradle:/.exec(contents);
if (match) {
debugn(" Adding Kotlin plugin");
return insertString(contents, match.index, `classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${DEFAULT_KOTLIN_VERSION}"\n `);
} else {
errorn(" Could not add kotlin plugin dependency")
}
return contents;
}

_setKotlinVersion(contents) {
if (this._isKotlinVersionSpecified(contents)) {
warnn(" Kotlin version already specified");
} else {
var kotlinVersion = this._getKotlinVersion(contents);
if (this._hasExtensionVariablesBlock(contents)) {
debugn(" Adding RNNKotlinVersion to extension block");
return contents.replace(/ext\s*{/, `ext {\n RNNKotlinVersion = ${kotlinVersion}`);
} else {
debugn(" Adding RNNKotlinVersion extension variable");
return contents.replace(/buildscript\s*{/, `buildscript {\n ext.RNNKotlinVersion = ${kotlinVersion}`);
}
}
return contents;
}

/**
* Check the current minSdkVersion specified and if it's lower than
* the required version, set it to the required version otherwise leave as it is.
*/
_setMinSdkVersion(contents) {
var minSdkVersion = this._getMinSdkVersion(contents)
// If user entered minSdkVersion is lower than the default, set it to default.
if (minSdkVersion < DEFAULT_MIN_SDK_VERSION) {
debugn(` Updating minSdkVersion to ${DEFAULT_MIN_SDK_VERSION}`)
return contents.replace(/minSdkVersion\s{0,}=\s{0,}\d*/, `minSdkVersion = ${DEFAULT_MIN_SDK_VERSION}`)
}

debugn(` Already specified minSdkVersion ${minSdkVersion}`)
return contents.replace(/minSdkVersion\s{0,}=\s{0,}\d*/, `minSdkVersion = ${minSdkVersion}`)
}

/**
* @param { string } contents
*/
_getKotlinVersion(contents) {
var hardCodedVersion = contents.match(/(?<=kotlin-gradle-plugin:)\$*[\d\.]{3,}/);
if (hardCodedVersion && hardCodedVersion.length > 0) {
return `"${hardCodedVersion[0]}"`;
}
var extensionVariableVersion = contents.match(/(?<=kotlin-gradle-plugin:)\$*[a-zA-Z\d\.]*/);
if (extensionVariableVersion && extensionVariableVersion.length > 0) {
return extensionVariableVersion[0].replace("$", "");
}
return `"${DEFAULT_KOTLIN_VERSION}"`;
}

/**
* Get the minSdkVersion value.
* @param { string } contents
*/
_getMinSdkVersion(contents) {
var minSdkVersion = contents.match(/minSdkVersion\s{0,}=\s{0,}(\d*)/)

if (minSdkVersion && minSdkVersion[1]) {
// It'd be something like 16 for a fresh React Native project.
return +minSdkVersion[1]
}

return DEFAULT_MIN_SDK_VERSION
}

/**
* @param {string} contents
*/
_hasExtensionVariablesBlock(contents) {
return /ext\s*{/.test(contents);
}

/**
* @param {string} contents
*/
_isKotlinVersionSpecified(contents) {
return /RNNKotlinVersion/.test(contents);
}

/**
* @param {string} contents
*/
_isKotlinPluginDeclared(contents) {
return /org.jetbrains.kotlin:kotlin-gradle-plugin:/.test(contents);
}
}

module.exports = GradleLinker;
Loading

0 comments on commit aeec746

Please sign in to comment.