mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
refactor: rewrite Inspector from Java to Kotlin (#50947)
Summary: Rewrite of the Inspector class from Java to Kotlin in scope of https://github.com/facebook/react-native/issues/50513 ## Changelog: [ANDROID] [CHANGED] - Migrated Inspector to Kotlin Pull Request resolved: https://github.com/facebook/react-native/pull/50947 Test Plan: Tested using RNTester app, on both old and new arch, and tested by navigating to multiple pages Reviewed By: cortinico Differential Revision: D73767386 Pulled By: javache fbshipit-source-id: e0098568aa0ed9863503e206a88d3b171c8f9966
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0e963aaa54
commit
93efaeb241
@@ -737,20 +737,26 @@ public abstract class com/facebook/react/bridge/GuardedRunnable : java/lang/Runn
|
||||
public abstract fun runGuarded ()V
|
||||
}
|
||||
|
||||
public class com/facebook/react/bridge/Inspector {
|
||||
public static fun connect (ILcom/facebook/react/bridge/Inspector$RemoteConnection;)Lcom/facebook/react/bridge/Inspector$LocalConnection;
|
||||
public static fun getPages ()Ljava/util/List;
|
||||
public final class com/facebook/react/bridge/Inspector {
|
||||
public static final field Companion Lcom/facebook/react/bridge/Inspector$Companion;
|
||||
public static final fun connect (ILcom/facebook/react/bridge/Inspector$RemoteConnection;)Lcom/facebook/react/bridge/Inspector$LocalConnection;
|
||||
public static final fun getPages ()Ljava/util/List;
|
||||
}
|
||||
|
||||
public class com/facebook/react/bridge/Inspector$LocalConnection {
|
||||
public fun disconnect ()V
|
||||
public fun sendMessage (Ljava/lang/String;)V
|
||||
public final class com/facebook/react/bridge/Inspector$Companion {
|
||||
public final fun connect (ILcom/facebook/react/bridge/Inspector$RemoteConnection;)Lcom/facebook/react/bridge/Inspector$LocalConnection;
|
||||
public final fun getPages ()Ljava/util/List;
|
||||
}
|
||||
|
||||
public class com/facebook/react/bridge/Inspector$Page {
|
||||
public fun getId ()I
|
||||
public fun getTitle ()Ljava/lang/String;
|
||||
public fun getVM ()Ljava/lang/String;
|
||||
public final class com/facebook/react/bridge/Inspector$LocalConnection {
|
||||
public final fun disconnect ()V
|
||||
public final fun sendMessage (Ljava/lang/String;)V
|
||||
}
|
||||
|
||||
public final class com/facebook/react/bridge/Inspector$Page {
|
||||
public final fun getId ()I
|
||||
public final fun getTitle ()Ljava/lang/String;
|
||||
public final fun getVM ()Ljava/lang/String;
|
||||
public fun toString ()Ljava/lang/String;
|
||||
}
|
||||
|
||||
|
||||
-112
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* 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.bridge;
|
||||
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.infer.annotation.Nullsafe;
|
||||
import com.facebook.jni.HybridData;
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
import com.facebook.react.common.ReactConstants;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Nullsafe(Nullsafe.Mode.LOCAL)
|
||||
@DoNotStrip
|
||||
public class Inspector {
|
||||
static {
|
||||
BridgeSoLoader.staticInit();
|
||||
}
|
||||
|
||||
private final HybridData mHybridData;
|
||||
|
||||
public static List<Page> getPages() {
|
||||
try {
|
||||
return Arrays.asList(instance().getPagesNative());
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
FLog.e(ReactConstants.TAG, "Inspector doesn't work in open source yet", e);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
public static LocalConnection connect(int pageId, RemoteConnection remote) {
|
||||
try {
|
||||
final LocalConnection local = instance().connectNative(pageId, remote);
|
||||
if (local == null) {
|
||||
throw new IllegalStateException("Can't open failed connection");
|
||||
}
|
||||
return local;
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
FLog.e(ReactConstants.TAG, "Inspector doesn't work in open source yet", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static native Inspector instance();
|
||||
|
||||
private native Page[] getPagesNative();
|
||||
|
||||
private native LocalConnection connectNative(int pageId, RemoteConnection remote);
|
||||
|
||||
private Inspector(HybridData hybridData) {
|
||||
mHybridData = hybridData;
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
public static class Page {
|
||||
private final int mId;
|
||||
private final String mTitle;
|
||||
private final String mVM;
|
||||
|
||||
public int getId() {
|
||||
return mId;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return mTitle;
|
||||
}
|
||||
|
||||
public String getVM() {
|
||||
return mVM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Page{" + "mId=" + mId + ", mTitle='" + mTitle + '\'' + '}';
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
private Page(int id, String title, String vm) {
|
||||
mId = id;
|
||||
mTitle = title;
|
||||
mVM = vm;
|
||||
}
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
public interface RemoteConnection {
|
||||
@DoNotStrip
|
||||
void onMessage(String message);
|
||||
|
||||
@DoNotStrip
|
||||
void onDisconnect();
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
public static class LocalConnection {
|
||||
private final HybridData mHybridData;
|
||||
|
||||
public native void sendMessage(String message);
|
||||
|
||||
public native void disconnect();
|
||||
|
||||
private LocalConnection(HybridData hybridData) {
|
||||
mHybridData = hybridData;
|
||||
}
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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.bridge
|
||||
|
||||
import com.facebook.common.logging.FLog
|
||||
import com.facebook.jni.HybridData
|
||||
import com.facebook.proguard.annotations.DoNotStrip
|
||||
import com.facebook.react.common.ReactConstants
|
||||
|
||||
@DoNotStrip
|
||||
public class Inspector
|
||||
private constructor(@Suppress("NoHungarianNotation") private val mHybridData: HybridData) {
|
||||
|
||||
private external fun getPagesNative(): Array<Page>
|
||||
|
||||
private external fun connectNative(pageId: Int, remote: RemoteConnection): LocalConnection?
|
||||
|
||||
@DoNotStrip
|
||||
public class Page
|
||||
private constructor(private val id: Int, private val title: String, private val vm: String) {
|
||||
public fun getId(): Int = id
|
||||
|
||||
public fun getTitle(): String = title
|
||||
|
||||
public fun getVM(): String = vm
|
||||
|
||||
override fun toString(): String = "Page{id=$id, title='$title'}"
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
public interface RemoteConnection {
|
||||
@DoNotStrip public fun onMessage(message: String)
|
||||
|
||||
@DoNotStrip public fun onDisconnect()
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
public class LocalConnection
|
||||
private constructor(@Suppress("NoHungarianNotation") private val mHybridData: HybridData) {
|
||||
public external fun sendMessage(message: String)
|
||||
|
||||
public external fun disconnect()
|
||||
}
|
||||
|
||||
public companion object {
|
||||
init {
|
||||
BridgeSoLoader.staticInit()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
public fun getPages(): List<Page> {
|
||||
return try {
|
||||
instance().getPagesNative().toList()
|
||||
} catch (e: UnsatisfiedLinkError) {
|
||||
FLog.e(ReactConstants.TAG, "Inspector doesn't work in open source yet", e)
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
public fun connect(pageId: Int, remote: RemoteConnection): LocalConnection {
|
||||
return try {
|
||||
instance().connectNative(pageId, remote)
|
||||
?: throw IllegalStateException("Can't open failed connection")
|
||||
} catch (e: UnsatisfiedLinkError) {
|
||||
FLog.e(ReactConstants.TAG, "Inspector doesn't work in open source yet", e)
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic private external fun instance(): Inspector
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user