Skip to content

feat(Android): Implemented RNN link to work with kotlin instead of java and new versions of RNN #8044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions autolink/fixtures/rn68/MainActivity.java.template

This file was deleted.

48 changes: 0 additions & 48 deletions autolink/fixtures/rn69/MainActivity.java.template

This file was deleted.

35 changes: 0 additions & 35 deletions autolink/fixtures/rn71/MainActivity.java.template

This file was deleted.

22 changes: 22 additions & 0 deletions autolink/fixtures/rn77/MainActivity.kt.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.app

import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
import com.facebook.react.defaults.DefaultReactActivityDelegate

class MainActivity : ReactActivity() {

/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
override fun getMainComponentName(): String = "rn770"

/**
* Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
* which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
*/
override fun createReactActivityDelegate(): ReactActivityDelegate =
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
}
44 changes: 44 additions & 0 deletions autolink/fixtures/rn77/MainApplication.kt.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.app

import android.app.Application
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactHost
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.react.soloader.OpenSourceMergedSoMapping
import com.facebook.soloader.SoLoader

class MainApplication : Application(), ReactApplication {

override val reactNativeHost: ReactNativeHost =
object : DefaultReactNativeHost(this) {
override fun getPackages(): List<ReactPackage> =
PackageList(this).packages.apply {
// Packages that cannot be autolinked yet can be added manually here, for example:
// add(MyReactNativePackage())
}

override fun getJSMainModuleName(): String = "index"

override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG

override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
}

override val reactHost: ReactHost
get() = getDefaultReactHost(applicationContext, reactNativeHost)

override fun onCreate() {
super.onCreate()
SoLoader.init(this, OpenSourceMergedSoMapping)
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
load()
}
}
}
21 changes: 21 additions & 0 deletions autolink/fixtures/rn77/build.gradle.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
buildscript {
ext {
buildToolsVersion = "35.0.0"
minSdkVersion = 24
compileSdkVersion = 35
targetSdkVersion = 35
ndkVersion = "27.1.12297006"
kotlinVersion = "2.0.21"
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
}
}

apply plugin: "com.facebook.react.rootproject"
24 changes: 24 additions & 0 deletions autolink/postlink/__helpers__/fixtures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const prepareFixtureDuplicate = ({ rnVersion, userFixtureFileName, patchedFixtureFileName }) => {
const fs = require('node:fs');
const path = require('node:path');
const os = require('node:os');

const userFixtureRelPath = _getRelativeFixturePath(rnVersion, userFixtureFileName);

const userFixturePath = path.resolve(userFixtureRelPath);
const patchedFixturePath = path.resolve(os.tmpdir(), patchedFixtureFileName);
fs.copyFileSync(userFixturePath, patchedFixturePath);

return patchedFixturePath;
};

const _getRelativeFixturePath = (rnVersion, fixtureFileName) => {
const path = require('node:path');
return path.join('autolink', 'fixtures', `rn${rnVersion}`, fixtureFileName);
};

module.exports = {
prepareFixtureDuplicate,
prepareFixtureDuplicate77: ({ userFixtureFileName, patchedFixtureFileName }) =>
prepareFixtureDuplicate({ rnVersion: '77', userFixtureFileName, patchedFixtureFileName }),
};
11 changes: 11 additions & 0 deletions autolink/postlink/__mocks__/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
log: console.log,
logn: console.log,
warn: console.log,
warnn: console.log,
info: console.log,
infon: console.log,
debug: console.log,
debugn: console.log,
errorn: console.log,
};
82 changes: 7 additions & 75 deletions autolink/postlink/__snapshots__/activityLinker.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,82 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`activityLinker should work for RN 0.68 1`] = `
"package com.app;
exports[`activityLinker should work for RN 0.77 1`] = `
"package com.app

import com.reactnativenavigation.NavigationActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.reactnativenavigation.NavigationActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
import com.facebook.react.defaults.DefaultReactActivityDelegate

public class MainActivity extends NavigationActivity {





public static class MainActivityDelegate extends ReactActivityDelegate {
public MainActivityDelegate(NavigationActivity activity, String mainComponentName) {
super(activity, mainComponentName);
}

@Override
protected ReactRootView createRootView() {
ReactRootView reactRootView = new ReactRootView(getContext());
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED);
return reactRootView;
}
}
}
"
`;

exports[`activityLinker should work for RN 0.69 1`] = `
"package com.app;

import com.reactnativenavigation.NavigationActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;

public class MainActivity extends NavigationActivity {





public static class MainActivityDelegate extends ReactActivityDelegate {
public MainActivityDelegate(NavigationActivity activity, String mainComponentName) {
super(activity, mainComponentName);
}

@Override
protected ReactRootView createRootView() {
ReactRootView reactRootView = new ReactRootView(getContext());
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED);
return reactRootView;
}

@Override
protected boolean isConcurrentRootEnabled() {
// If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18).
// More on this on https://reactjs.org/blog/2022/03/29/react-v18.html
return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
}
}
}
"
`;


exports[`activityLinker should work for RN 0.71 1`] = `
"package com.app;

import com.reactnativenavigation.NavigationActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
import com.facebook.react.defaults.DefaultReactActivityDelegate;

public class MainActivity extends NavigationActivity {
class MainActivity : NavigationActivity() {



Expand Down
47 changes: 47 additions & 0 deletions autolink/postlink/__snapshots__/applicationLinker.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`applicationLinker should work for RN 0.77 1`] = `
"package com.app

import android.app.Application
import com.facebook.react.PackageList
import com.reactnativenavigation.NavigationApplication
import com.facebook.react.ReactHost
import com.facebook.react.ReactNativeHost
import com.reactnativenavigation.react.NavigationReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.react.soloader.OpenSourceMergedSoMapping
import com.facebook.soloader.SoLoader

class MainApplication : NavigationApplication() {

override val reactNativeHost: ReactNativeHost =
object : DefaultNavigationReactNativeHost(this) {
override fun getPackages(): List<ReactPackage> =
PackageList(this).packages.apply {
// Packages that cannot be autolinked yet can be added manually here, for example:
// add(MyReactNativePackage())
}

override fun getJSMainModuleName(): String = "index"

override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG

override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
}

override val reactHost: ReactHost
get() = getDefaultReactHost(applicationContext, reactNativeHost)

override fun onCreate() {
super.onCreate()


}
}
"
`;
Loading