-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Kotlin autolinker for React Native 0.63.x+
Issue: #7821
- Loading branch information
Showing
12 changed files
with
533 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.app; | ||
|
||
import com.facebook.react.ReactActivity; | ||
import com.facebook.react.ReactActivityDelegate; | ||
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; | ||
import com.facebook.react.defaults.DefaultReactActivityDelegate; | ||
|
||
public class MainActivity extends ReactActivity { | ||
|
||
/** | ||
* Returns the name of the main component registered from JavaScript. This is used to schedule | ||
* rendering of the component. | ||
*/ | ||
@Override | ||
protected String getMainComponentName() { | ||
return "App"; | ||
} | ||
|
||
/** | ||
* Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link | ||
* DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React | ||
* (aka React 18) with two boolean flags. | ||
*/ | ||
@Override | ||
protected ReactActivityDelegate createReactActivityDelegate() { | ||
return new DefaultReactActivityDelegate( | ||
this, | ||
getMainComponentName(), | ||
// If you opted-in for the New Architecture, we enable the Fabric Renderer. | ||
DefaultNewArchitectureEntryPoint.getFabricEnabled()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.app; | ||
|
||
import android.app.Application; | ||
import com.facebook.react.PackageList; | ||
import com.facebook.react.ReactApplication; | ||
import com.facebook.react.ReactNativeHost; | ||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; | ||
import com.facebook.react.defaults.DefaultReactNativeHost; | ||
import com.facebook.soloader.SoLoader; | ||
import java.util.List; | ||
|
||
public class MainApplication extends Application implements ReactApplication { | ||
|
||
private final ReactNativeHost mReactNativeHost = | ||
new DefaultReactNativeHost(this) { | ||
@Override | ||
public boolean getUseDeveloperSupport() { | ||
return BuildConfig.DEBUG; | ||
} | ||
|
||
@Override | ||
protected List<ReactPackage> getPackages() { | ||
@SuppressWarnings("UnnecessaryLocalVariable") | ||
List<ReactPackage> packages = new PackageList(this).getPackages(); | ||
// Packages that cannot be autolinked yet can be added manually here, for example: | ||
// packages.add(new MyReactNativePackage()); | ||
return packages; | ||
} | ||
|
||
@Override | ||
protected String getJSMainModuleName() { | ||
return "index"; | ||
} | ||
|
||
@Override | ||
protected boolean isNewArchEnabled() { | ||
return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; | ||
} | ||
|
||
@Override | ||
protected Boolean isHermesEnabled() { | ||
return BuildConfig.IS_HERMES_ENABLED; | ||
} | ||
}; | ||
|
||
@Override | ||
public ReactNativeHost getReactNativeHost() { | ||
return mReactNativeHost; | ||
} | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
SoLoader.init(this, /* native exopackage */ false); | ||
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { | ||
// If you opted-in for the New Architecture, we load the native entry point for this app. | ||
DefaultNewArchitectureEntryPoint.load(); | ||
} | ||
ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "App" | ||
|
||
/** | ||
* 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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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.flipper.ReactNativeFlipper | ||
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(this.applicationContext, reactNativeHost) | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
SoLoader.init(this, false) | ||
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { | ||
// If you opted-in for the New Architecture, we load the native entry point for this app. | ||
load() | ||
} | ||
ReactNativeFlipper.initializeFlipper(this, reactNativeHost.reactInstanceManager) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
autolink/postlink/__snapshots__/applicationLinker.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`applicationLinker should work for RN 0.72 1`] = ` | ||
"package com.app; | ||
import android.app.Application; | ||
import com.facebook.react.PackageList; | ||
import com.reactnativenavigation.NavigationApplication; | ||
import com.facebook.react.ReactNativeHost; | ||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; | ||
import com.facebook.react.defaults.DefaultReactNativeHost; | ||
import com.reactnativenavigation.react.NavigationReactNativeHost; | ||
import com.facebook.soloader.SoLoader; | ||
import java.util.List; | ||
public class MainApplication extends NavigationApplication { | ||
private final ReactNativeHost mReactNativeHost = | ||
new NavigationReactNativeHost(this) { | ||
@Override | ||
public boolean getUseDeveloperSupport() { | ||
return BuildConfig.DEBUG; | ||
} | ||
@Override | ||
protected List<ReactPackage> getPackages() { | ||
@SuppressWarnings(\\"UnnecessaryLocalVariable\\") | ||
List<ReactPackage> packages = new PackageList(this).getPackages(); | ||
// Packages that cannot be autolinked yet can be added manually here, for example: | ||
// packages.add(new MyReactNativePackage()); | ||
return packages; | ||
} | ||
@Override | ||
protected String getJSMainModuleName() { | ||
return \\"index\\"; | ||
} | ||
@Override | ||
protected boolean isNewArchEnabled() { | ||
return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; | ||
} | ||
@Override | ||
protected Boolean isHermesEnabled() { | ||
return BuildConfig.IS_HERMES_ENABLED; | ||
} | ||
}; | ||
@Override | ||
public ReactNativeHost getReactNativeHost() { | ||
return mReactNativeHost; | ||
} | ||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { | ||
// If you opted-in for the New Architecture, we load the native entry point for this app. | ||
DefaultNewArchitectureEntryPoint.load(); | ||
} | ||
ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); | ||
} | ||
} | ||
" | ||
`; | ||
exports[`applicationLinker should work for RN 0.73 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.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.reactnativenavigation.react.NavigationReactNativeHost | ||
import com.facebook.react.flipper.ReactNativeFlipper | ||
import com.facebook.soloader.SoLoader | ||
class MainApplication : NavigationApplication() { | ||
override val reactNativeHost: ReactNativeHost = | ||
object : NavigationReactNativeHost(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(this.applicationContext, reactNativeHost) | ||
override fun onCreate() { | ||
super.onCreate() | ||
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { | ||
// If you opted-in for the New Architecture, we load the native entry point for this app. | ||
load() | ||
} | ||
ReactNativeFlipper.initializeFlipper(this, reactNativeHost.reactInstanceManager) | ||
} | ||
} | ||
" | ||
`; |
Oops, something went wrong.