Skip to content

Commit 50220c8

Browse files
committed
Implemented RNN link to work with kotlin instead of java
1 parent ad65cf9 commit 50220c8

16 files changed

+346
-339
lines changed

autolink/fixtures/rn68/MainActivity.java.template

Lines changed: 0 additions & 40 deletions
This file was deleted.

autolink/fixtures/rn69/MainActivity.java.template

Lines changed: 0 additions & 48 deletions
This file was deleted.

autolink/fixtures/rn71/MainActivity.java.template

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.app
2+
3+
import com.facebook.react.ReactActivity
4+
import com.facebook.react.ReactActivityDelegate
5+
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
6+
import com.facebook.react.defaults.DefaultReactActivityDelegate
7+
8+
class MainActivity : ReactActivity() {
9+
10+
/**
11+
* Returns the name of the main component registered from JavaScript. This is used to schedule
12+
* rendering of the component.
13+
*/
14+
override fun getMainComponentName(): String = "rn790"
15+
16+
/**
17+
* Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
18+
* which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
19+
*/
20+
override fun createReactActivityDelegate(): ReactActivityDelegate =
21+
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
22+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.app
2+
3+
import android.app.Application
4+
import com.facebook.react.PackageList
5+
import com.facebook.react.ReactApplication
6+
import com.facebook.react.ReactHost
7+
import com.facebook.react.ReactNativeHost
8+
import com.facebook.react.ReactPackage
9+
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
10+
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
11+
import com.facebook.react.defaults.DefaultReactNativeHost
12+
import com.facebook.react.soloader.OpenSourceMergedSoMapping
13+
import com.facebook.soloader.SoLoader
14+
15+
class MainApplication : Application(), ReactApplication {
16+
17+
override val reactNativeHost: ReactNativeHost =
18+
object : DefaultReactNativeHost(this) {
19+
override fun getPackages(): List<ReactPackage> =
20+
PackageList(this).packages.apply {
21+
// Packages that cannot be autolinked yet can be added manually here, for example:
22+
// add(MyReactNativePackage())
23+
}
24+
25+
override fun getJSMainModuleName(): String = "index"
26+
27+
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
28+
29+
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
30+
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
31+
}
32+
33+
override val reactHost: ReactHost
34+
get() = getDefaultReactHost(applicationContext, reactNativeHost)
35+
36+
override fun onCreate() {
37+
super.onCreate()
38+
SoLoader.init(this, OpenSourceMergedSoMapping)
39+
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
40+
// If you opted-in for the New Architecture, we load the native entry point for this app.
41+
load()
42+
}
43+
}
44+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
buildscript {
2+
ext {
3+
buildToolsVersion = "35.0.0"
4+
minSdkVersion = 24
5+
compileSdkVersion = 35
6+
targetSdkVersion = 35
7+
ndkVersion = "27.1.12297006"
8+
kotlinVersion = "2.0.21"
9+
}
10+
repositories {
11+
google()
12+
mavenCentral()
13+
}
14+
dependencies {
15+
classpath("com.android.tools.build:gradle")
16+
classpath("com.facebook.react:react-native-gradle-plugin")
17+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
18+
}
19+
}
20+
21+
apply plugin: "com.facebook.react.rootproject"

autolink/postlink/__snapshots__/activityLinker.test.js.snap

Lines changed: 7 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,14 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`activityLinker should work for RN 0.68 1`] = `
4-
"package com.app;
3+
exports[`activityLinker should work for RN 0.77 1`] = `
4+
"package com.app
55
6-
import com.reactnativenavigation.NavigationActivity;
7-
import com.facebook.react.ReactActivityDelegate;
8-
import com.facebook.react.ReactRootView;
6+
import com.reactnativenavigation.NavigationActivity
7+
import com.facebook.react.ReactActivityDelegate
8+
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
9+
import com.facebook.react.defaults.DefaultReactActivityDelegate
910
10-
public class MainActivity extends NavigationActivity {
11-
12-
13-
14-
15-
16-
public static class MainActivityDelegate extends ReactActivityDelegate {
17-
public MainActivityDelegate(NavigationActivity activity, String mainComponentName) {
18-
super(activity, mainComponentName);
19-
}
20-
21-
@Override
22-
protected ReactRootView createRootView() {
23-
ReactRootView reactRootView = new ReactRootView(getContext());
24-
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
25-
reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED);
26-
return reactRootView;
27-
}
28-
}
29-
}
30-
"
31-
`;
32-
33-
exports[`activityLinker should work for RN 0.69 1`] = `
34-
"package com.app;
35-
36-
import com.reactnativenavigation.NavigationActivity;
37-
import com.facebook.react.ReactActivityDelegate;
38-
import com.facebook.react.ReactRootView;
39-
40-
public class MainActivity extends NavigationActivity {
41-
42-
43-
44-
45-
46-
public static class MainActivityDelegate extends ReactActivityDelegate {
47-
public MainActivityDelegate(NavigationActivity activity, String mainComponentName) {
48-
super(activity, mainComponentName);
49-
}
50-
51-
@Override
52-
protected ReactRootView createRootView() {
53-
ReactRootView reactRootView = new ReactRootView(getContext());
54-
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
55-
reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED);
56-
return reactRootView;
57-
}
58-
59-
@Override
60-
protected boolean isConcurrentRootEnabled() {
61-
// If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18).
62-
// More on this on https://reactjs.org/blog/2022/03/29/react-v18.html
63-
return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
64-
}
65-
}
66-
}
67-
"
68-
`;
69-
70-
71-
exports[`activityLinker should work for RN 0.71 1`] = `
72-
"package com.app;
73-
74-
import com.reactnativenavigation.NavigationActivity;
75-
import com.facebook.react.ReactActivityDelegate;
76-
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
77-
import com.facebook.react.defaults.DefaultReactActivityDelegate;
78-
79-
public class MainActivity extends NavigationActivity {
11+
class MainActivity : NavigationActivity() {
8012
8113
8214
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`applicationLinker should work for RN 0.77 1`] = `
4+
"package com.app
5+
6+
import android.app.Application
7+
import com.facebook.react.PackageList
8+
import com.reactnativenavigation.NavigationApplication
9+
import com.facebook.react.ReactHost
10+
import com.facebook.react.ReactNativeHost
11+
import com.reactnativenavigation.react.NavigationReactNativeHost
12+
import com.facebook.react.ReactPackage
13+
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
14+
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
15+
import com.facebook.react.defaults.DefaultReactNativeHost
16+
import com.facebook.react.soloader.OpenSourceMergedSoMapping
17+
import com.facebook.soloader.SoLoader
18+
19+
class MainApplication : NavigationApplication() {
20+
21+
override val reactNativeHost: ReactNativeHost =
22+
object : DefaultNavigationReactNativeHost(this) {
23+
override fun getPackages(): List<ReactPackage> =
24+
PackageList(this).packages.apply {
25+
// Packages that cannot be autolinked yet can be added manually here, for example:
26+
// add(MyReactNativePackage())
27+
}
28+
29+
override fun getJSMainModuleName(): String = "index"
30+
31+
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
32+
33+
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
34+
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
35+
}
36+
37+
override val reactHost: ReactHost
38+
get() = getDefaultReactHost(applicationContext, reactNativeHost)
39+
40+
override fun onCreate() {
41+
super.onCreate()
42+
43+
44+
}
45+
}
46+
"
47+
`;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`gradleLinker should work for RN 0.77 1`] = `
4+
"buildscript {
5+
ext {
6+
RNNKotlinVersion = "2.0.21"
7+
buildToolsVersion = "35.0.0"
8+
minSdkVersion = 24
9+
compileSdkVersion = 35
10+
targetSdkVersion = 35
11+
ndkVersion = "27.1.12297006"
12+
kotlinVersion = "2.0.21"
13+
}
14+
repositories {
15+
google()
16+
mavenCentral()
17+
}
18+
dependencies {
19+
classpath("com.android.tools.build:gradle")
20+
classpath("com.facebook.react:react-native-gradle-plugin")
21+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
22+
}
23+
}
24+
25+
apply plugin: "com.facebook.react.rootproject"
26+
"
27+
`;

0 commit comments

Comments
 (0)