-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(fixtures): add Java and Kotlin fixtures for Android app entrypo…
…ints Co-Authored-By: Bill Spooner <[email protected]>
- Loading branch information
1 parent
4eb10b7
commit 8916bc8
Showing
5 changed files
with
222 additions
and
1 deletion.
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,15 @@ | ||
package com.reactnativeglobalkeyevent; | ||
|
||
import com.facebook.react.ReactActivity; | ||
|
||
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 "ReactNativeGlobalKeyEvent"; | ||
} | ||
} |
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,61 @@ | ||
package com.reactnativeglobalkeyevent | ||
|
||
import android.os.Build | ||
import android.os.Bundle | ||
|
||
import com.facebook.react.ReactActivity | ||
import com.facebook.react.ReactActivityDelegate | ||
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled | ||
import com.facebook.react.defaults.DefaultReactActivityDelegate | ||
|
||
import expo.modules.ReactActivityDelegateWrapper | ||
|
||
class MainActivity : ReactActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
// Set the theme to AppTheme BEFORE onCreate to support | ||
// coloring the background, status bar, and navigation bar. | ||
// This is required for expo-splash-screen. | ||
setTheme(R.style.AppTheme); | ||
super.onCreate(null) | ||
} | ||
|
||
/** | ||
* Returns the name of the main component registered from JavaScript. This is used to schedule | ||
* rendering of the component. | ||
*/ | ||
override fun getMainComponentName(): String = "main" | ||
|
||
/** | ||
* 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 { | ||
return ReactActivityDelegateWrapper( | ||
this, | ||
BuildConfig.IS_NEW_ARCHITECTURE_ENABLED, | ||
object : DefaultReactActivityDelegate( | ||
this, | ||
mainComponentName, | ||
fabricEnabled | ||
){}) | ||
} | ||
|
||
/** | ||
* Align the back button behavior with Android S | ||
* where moving root activities to background instead of finishing activities. | ||
* @see <a href="https://developer.android.com/reference/android/app/Activity#onBackPressed()">onBackPressed</a> | ||
*/ | ||
override fun invokeDefaultOnBackPressed() { | ||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) { | ||
if (!moveTaskToBack(false)) { | ||
// For non-root activities, use the default implementation to finish them. | ||
super.invokeDefaultOnBackPressed() | ||
} | ||
return | ||
} | ||
|
||
// Use the default back button implementation on Android S | ||
// because it's doing more than [Activity.moveTaskToBack] in fact. | ||
super.invokeDefaultOnBackPressed() | ||
} | ||
} |
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,80 @@ | ||
package com.reactnativeglobalkeyevent; | ||
|
||
import android.app.Application; | ||
import android.content.Context; | ||
import com.facebook.react.PackageList; | ||
import com.facebook.react.ReactApplication; | ||
import com.facebook.react.ReactInstanceManager; | ||
import com.facebook.react.ReactNativeHost; | ||
import com.facebook.react.ReactPackage; | ||
import com.facebook.soloader.SoLoader; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.List; | ||
|
||
public class MainApplication extends Application implements ReactApplication { | ||
|
||
private final ReactNativeHost mReactNativeHost = | ||
new ReactNativeHost(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 | ||
public ReactNativeHost getReactNativeHost() { | ||
return mReactNativeHost; | ||
} | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
SoLoader.init(this, /* native exopackage */ false); | ||
initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); | ||
} | ||
|
||
/** | ||
* Loads Flipper in React Native templates. Call this in the onCreate method with something like | ||
* initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); | ||
* | ||
* @param context | ||
* @param reactInstanceManager | ||
*/ | ||
private static void initializeFlipper( | ||
Context context, ReactInstanceManager reactInstanceManager) { | ||
if (BuildConfig.DEBUG) { | ||
try { | ||
/* | ||
We use reflection here to pick up the class that initializes Flipper, | ||
since Flipper library is not available in release mode | ||
*/ | ||
Class<?> aClass = Class.forName("com.reactnativeglobalkeyevent.ReactNativeFlipper"); | ||
aClass | ||
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class) | ||
.invoke(null, context, reactInstanceManager); | ||
} catch (ClassNotFoundException e) { | ||
e.printStackTrace(); | ||
} catch (NoSuchMethodException e) { | ||
e.printStackTrace(); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} catch (InvocationTargetException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} |
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,55 @@ | ||
package com.reactnativeglobalkeyevent | ||
|
||
import android.app.Application | ||
import android.content.res.Configuration | ||
|
||
import com.facebook.react.PackageList | ||
import com.facebook.react.ReactApplication | ||
import com.facebook.react.ReactNativeHost | ||
import com.facebook.react.ReactPackage | ||
import com.facebook.react.ReactHost | ||
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load | ||
import com.facebook.react.defaults.DefaultReactNativeHost | ||
import com.facebook.soloader.SoLoader | ||
|
||
import expo.modules.ApplicationLifecycleDispatcher | ||
import expo.modules.ReactNativeHostWrapper | ||
|
||
class MainApplication : Application(), ReactApplication { | ||
|
||
override val reactNativeHost: ReactNativeHost = ReactNativeHostWrapper( | ||
this, | ||
object : DefaultReactNativeHost(this) { | ||
override fun getPackages(): List<ReactPackage> { | ||
// Packages that cannot be autolinked yet can be added manually here, for example: | ||
// packages.add(new MyReactNativePackage()); | ||
return PackageList(this).packages | ||
} | ||
|
||
override fun getJSMainModuleName(): String = ".expo/.virtual-metro-entry" | ||
|
||
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() = ReactNativeHostWrapper.createReactHost(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() | ||
} | ||
ApplicationLifecycleDispatcher.onApplicationCreate(this) | ||
} | ||
|
||
override fun onConfigurationChanged(newConfig: Configuration) { | ||
super.onConfigurationChanged(newConfig) | ||
ApplicationLifecycleDispatcher.onConfigurationChanged(this, newConfig) | ||
} | ||
} |
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