mirror of https://github.com/tooot-app/app
113 lines
3.7 KiB
Java
113 lines
3.7 KiB
Java
package com.xmflsct.app.tooot;
|
|
|
|
import android.app.Application;
|
|
import android.content.Context;
|
|
import android.content.res.Configuration;
|
|
import androidx.annotation.NonNull;
|
|
|
|
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.react.shell.MainReactPackage;
|
|
import com.facebook.soloader.SoLoader;
|
|
import com.xmflsct.app.tooot.generated.BasePackageList;
|
|
|
|
import expo.modules.ApplicationLifecycleDispatcher;
|
|
import expo.modules.ReactNativeHostWrapper;
|
|
import expo.modules.permissions.PermissionsPackage;
|
|
import expo.modules.filesystem.FileSystemPackage;
|
|
import expo.modules.updates.UpdatesController;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.util.List;
|
|
|
|
import com.facebook.react.bridge.JSIModulePackage; // <- react-native-reanimated-v2
|
|
import com.swmansion.reanimated.ReanimatedJSIModulePackage; // <- react-native-reanimated-v2
|
|
|
|
public class MainApplication extends Application implements ReactApplication {
|
|
private final ReactModuleRegistryProvider mModuleRegistryProvider = new ReactModuleRegistryProvider(
|
|
new BasePackageList().getPackageList()
|
|
);
|
|
|
|
private final ReactNativeHost mReactNativeHost = new ReactNativeHostWrapper(
|
|
this,
|
|
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 // <- react-native-reanimated-v2
|
|
protected JSIModulePackage getJSIModulePackage() {
|
|
return new ReanimatedJSIModulePackage();
|
|
}
|
|
};
|
|
|
|
@Override
|
|
public ReactNativeHost getReactNativeHost() {
|
|
return mReactNativeHost;
|
|
}
|
|
|
|
@Override
|
|
public void onCreate() {
|
|
super.onCreate();
|
|
SoLoader.init(this, /* native exopackage */ false);
|
|
|
|
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
|
|
ApplicationLifecycleDispatcher.onApplicationCreate(this);
|
|
}
|
|
|
|
@Override
|
|
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
|
super.onConfigurationChanged(newConfig);
|
|
ApplicationLifecycleDispatcher.onConfigurationChanged(this, newConfig);
|
|
}
|
|
|
|
/**
|
|
* 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.xmflsct.app.tooot.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();
|
|
}
|
|
}
|
|
}
|
|
}
|