Do not use reflection to load Flipper on RN Tester

Summary:
I'm applying the same fix I applied to the Template.
This allows us to load Flipper without using reflection on RN Tester.

Changelog:
[Internal] [Changed] - Do not use reflection to load Flipper on RN Tester

Reviewed By: cipolleschi

Differential Revision: D38745404

fbshipit-source-id: c17fbd74df31441467e448f21c35171a7f2532ff
This commit is contained in:
Nicola Corti 2022-08-16 10:04:47 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 9a2eb9089f
Коммит 4dce39d2c4
2 изменённых файлов: 22 добавлений и 35 удалений

Просмотреть файл

@ -8,11 +8,9 @@
package com.facebook.react.uiapp;
import android.app.Application;
import android.content.Context;
import androidx.annotation.NonNull;
import com.facebook.fbreact.specs.SampleTurboModule;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.TurboReactPackage;
@ -27,7 +25,6 @@ import com.facebook.react.uiapp.component.MyNativeViewManager;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.views.text.ReactFontManager;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@ -126,42 +123,11 @@ public class RNTesterApplication extends Application implements ReactApplication
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
SoLoader.loadLibrary(BuildConfig.DYNAMIC_LIBRARY_NAME);
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
}
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
/**
* 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(
final Context context, final 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
*/
final Class<?> aClass = Class.forName("com.facebook.react.uiapp.ReactNativeFlipper");
aClass
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
.invoke(null, context, reactInstanceManager);
} catch (final ClassNotFoundException e) {
e.printStackTrace();
} catch (final NoSuchMethodException e) {
e.printStackTrace();
} catch (final IllegalAccessException e) {
e.printStackTrace();
} catch (final InvocationTargetException e) {
e.printStackTrace();
}
}
}
};

Просмотреть файл

@ -0,0 +1,21 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.uiapp;
import android.content.Context;
import com.facebook.react.ReactInstanceManager;
/**
* Class responsible of loading Flipper inside your React Native application. This is the release
* flavor of it so it's empty as we don't want to load Flipper.
*/
public class ReactNativeFlipper {
public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
// Do nothing as we don't want to initialize Flipper on Release.
}
}