diff --git a/android/app/src/debug/java/chat/rocket/reactnative/MainDebugApplication.java b/android/app/src/debug/java/chat/rocket/reactnative/MainDebugApplication.java deleted file mode 100644 index e6abf3b05..000000000 --- a/android/app/src/debug/java/chat/rocket/reactnative/MainDebugApplication.java +++ /dev/null @@ -1,25 +0,0 @@ -package chat.rocket.reactnative; - -import android.content.Context; - -import com.facebook.react.ReactInstanceManager; - -public class MainDebugApplication extends MainApplication { - - @Override - public void onCreate() { - super.onCreate(); - 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) { - ReactNativeFlipper.initializeFlipper(context, reactInstanceManager); - } -} diff --git a/android/app/src/debug/java/chat/rocket/reactnative/ReactNativeFlipper.java b/android/app/src/debug/java/chat/rocket/reactnative/ReactNativeFlipper.java index 6d30e2d25..0773092c2 100644 --- a/android/app/src/debug/java/chat/rocket/reactnative/ReactNativeFlipper.java +++ b/android/app/src/debug/java/chat/rocket/reactnative/ReactNativeFlipper.java @@ -23,6 +23,8 @@ import com.facebook.react.ReactInstanceManager; import com.facebook.react.bridge.ReactContext; import com.facebook.react.modules.network.NetworkingModule; import com.facebook.react.modules.network.CustomClientBuilder; +import tech.bam.rnperformance.flipper.RNPerfMonitorPlugin; + import okhttp3.OkHttpClient; public class ReactNativeFlipper { public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { @@ -33,6 +35,8 @@ public class ReactNativeFlipper { client.addPlugin(new DatabasesFlipperPlugin(context)); client.addPlugin(new SharedPreferencesFlipperPlugin(context)); client.addPlugin(CrashReporterPlugin.getInstance()); + client.addPlugin(new RNPerfMonitorPlugin(reactInstanceManager)); + NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin(); NetworkingModule.setCustomClientBuilder( new CustomClientBuilder() { diff --git a/android/app/src/main/java/chat/rocket/reactnative/MainApplication.java b/android/app/src/main/java/chat/rocket/reactnative/MainApplication.java index 871e6e86d..b94159e09 100644 --- a/android/app/src/main/java/chat/rocket/reactnative/MainApplication.java +++ b/android/app/src/main/java/chat/rocket/reactnative/MainApplication.java @@ -9,13 +9,16 @@ import com.facebook.react.ReactApplication; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.react.config.ReactFeatureFlags; +import com.facebook.react.ReactInstanceManager; import com.facebook.soloader.SoLoader; import com.reactnativecommunity.viewpager.RNCViewPagerPackage; import com.facebook.react.bridge.JSIModulePackage; import com.swmansion.reanimated.ReanimatedJSIModulePackage; +import android.content.Context; import android.content.res.Configuration; import expo.modules.ApplicationLifecycleDispatcher; import expo.modules.ReactNativeHostWrapper; +import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import java.util.List; @@ -76,6 +79,7 @@ public class MainApplication extends Application implements ReactApplication { // If you opted-in for the New Architecture, we enable the TurboModule system ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; SoLoader.init(this, /* native exopackage */ false); + initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); ApplicationLifecycleDispatcher.onApplicationCreate(this); } @@ -84,4 +88,35 @@ public class MainApplication extends Application implements ReactApplication { 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("chat.rocket.reactnative.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(); + } + } + } } diff --git a/android/gradle.properties b/android/gradle.properties index 59600f62e..29d16769c 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -23,7 +23,7 @@ android.useAndroidX=true android.enableJetifier=true # Version of flipper SDK to use with React Native -FLIPPER_VERSION=0.125.0 +FLIPPER_VERSION=0.175.0 # Use this property to specify which architecture you want to build. # You can also override it from the CLI using diff --git a/index.js b/index.js index e73a837d9..87d65aed2 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,16 @@ import 'react-native-gesture-handler'; import 'react-native-console-time-polyfill'; import { AppRegistry } from 'react-native'; +import { connectToDevTools } from 'react-devtools-core'; import { name as appName, share as shareName } from './app.json'; if (__DEV__) { require('./app/ReactotronConfig'); + connectToDevTools({ + host: 'localhost', + port: 8097 + }); } else { console.log = () => {}; console.time = () => {}; diff --git a/package.json b/package.json index 4d7a4c1e0..ff23dbfa1 100644 --- a/package.json +++ b/package.json @@ -206,7 +206,9 @@ "otp.js": "1.2.0", "patch-package": "6.4.7", "prettier": "^2.3.2", + "react-devtools-core": "^4.27.0", "react-dom": "17.0.1", + "react-native-flipper-performance-plugin": "^0.3.1", "react-test-renderer": "17.0.2", "reactotron-redux": "3.1.3", "reactotron-redux-saga": "4.2.3", diff --git a/yarn.lock b/yarn.lock index d77429ed0..21bfe81eb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16973,6 +16973,14 @@ react-devtools-core@^4.23.0: shell-quote "^1.6.1" ws "^7" +react-devtools-core@^4.27.0: + version "4.27.0" + resolved "https://registry.yarnpkg.com/react-devtools-core/-/react-devtools-core-4.27.0.tgz#b57eb69df273c88daa3dc1577177ea9bbdd0a67d" + integrity sha512-9dfVBf/9yquz5deUUCi9kA/JA4+2MTUxfKRv6IqizR0B26/28CxJedXb0kXtPD/cRKce8ecU1KhfJiDzUkOOaQ== + dependencies: + shell-quote "^1.6.1" + ws "^7" + react-docgen-typescript@^2.0.0: version "2.2.2" resolved "https://registry.yarnpkg.com/react-docgen-typescript/-/react-docgen-typescript-2.2.2.tgz#4611055e569edc071204aadb20e1c93e1ab1659c" @@ -17154,6 +17162,11 @@ react-native-file-viewer@^2.1.4: resolved "https://registry.yarnpkg.com/react-native-file-viewer/-/react-native-file-viewer-2.1.5.tgz#cd4544f573108e79002b5c7e1ebfce4371885250" integrity sha512-MGC6sx9jsqHdefhVQ6o0akdsPGpkXgiIbpygb2Sg4g4bh7v6K1cardLV1NwGB9A6u1yICOSDT/MOC//9Ez6EUg== +react-native-flipper-performance-plugin@^0.3.1: + version "0.3.1" + resolved "https://registry.yarnpkg.com/react-native-flipper-performance-plugin/-/react-native-flipper-performance-plugin-0.3.1.tgz#969aea65eb6e6504ee29caab7bf546c75322f817" + integrity sha512-NDf5VCTqYPUUihvmW5A/scJbjHWZpAxC9FE1kfgFCPsHENjH9EVJxk+7XlLN608dEtHOtZdcWY0HZZT8XLjr6Q== + react-native-flipper@^0.164.0: version "0.164.0" resolved "https://registry.yarnpkg.com/react-native-flipper/-/react-native-flipper-0.164.0.tgz#64f6269a86a13a72e30f53ba9f5281d2073a7697"