Convert interfaces inside devsupport/interfaces to Kotlin (#44055)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44055

## Changelog:
[Internal] -

Was looking into how devsupport is exactly implemented on different platforms (in the context of doing it for a new platform) and figured I may just well convert this to Koltin in the process (helped to understand inner working details as well).

Reviewed By: christophpurrer

Differential Revision: D56052137

fbshipit-source-id: 25280a57f46bec95dc1437ea6eb2eef08332797f
This commit is contained in:
Ruslan Shestopalyuk
2024-04-12 09:40:31 -07:00
committed by Facebook GitHub Bot
parent a666718879
commit b15d438498
12 changed files with 113 additions and 120 deletions
@@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.devsupport.interfaces;
package com.facebook.react.devsupport.interfaces
public interface BundleLoadCallback {
void onSuccess();
public fun interface BundleLoadCallback {
public fun onSuccess()
}
@@ -5,14 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.devsupport.interfaces;
import androidx.annotation.Nullable;
package com.facebook.react.devsupport.interfaces
public interface DevBundleDownloadListener {
void onSuccess();
public fun onSuccess()
void onProgress(@Nullable String status, @Nullable Integer done, @Nullable Integer total);
public fun onProgress(status: String?, done: Int?, total: Int?)
void onFailure(Exception cause);
public fun onFailure(cause: Exception?)
}
@@ -5,17 +5,13 @@
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.devsupport.interfaces;
import androidx.annotation.Nullable;
package com.facebook.react.devsupport.interfaces
/** Interface to display loading messages on top of the screen. */
public interface DevLoadingViewManager {
public fun showMessage(message: String)
void showMessage(final String message);
public fun updateProgress(status: String?, done: Int?, total: Int?)
void updateProgress(
final @Nullable String status, final @Nullable Integer done, final @Nullable Integer total);
void hide();
public fun hide()
}
@@ -1,22 +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.devsupport.interfaces;
/**
* Callback class for custom options that may appear in {@link DevSupportManager} developer options
* menu. In case when option registered for this handler is selected from the menu, the instance
* method {@link #onOptionSelected} will be triggered.
*/
public interface DevOptionHandler {
/**
* Triggered in case when user select custom developer option from the developers options menu
* displayed with {@link DevSupportManager}.
*/
void onOptionSelected();
}
@@ -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.devsupport.interfaces
/**
* Callback class for custom options that may appear in [DevSupportManager] developer options menu.
* In case when option registered for this handler is selected from the menu, the instance method
* [.onOptionSelected] will be triggered.
*/
public fun interface DevOptionHandler {
/**
* Triggered in case when user select custom developer option from the developers options menu
* displayed with [DevSupportManager].
*/
public fun onOptionSelected()
}
@@ -5,13 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.devsupport.interfaces;
package com.facebook.react.devsupport.interfaces
/** Callback class for loading split JS bundles from Metro in development. */
public interface DevSplitBundleCallback {
/** Called when the split JS bundle has been downloaded and evaluated. */
void onSuccess();
public fun onSuccess()
/** Called when the split JS bundle failed to load. */
void onError(String url, Throwable cause);
public fun onError(url: String?, cause: Throwable?)
}
@@ -1,20 +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.devsupport.interfaces;
import android.util.Pair;
/** Interface that lets parts of the app process the errors before showing the redbox */
public interface ErrorCustomizer {
/**
* The function that need to be registered using {@link DevSupportManager}.registerErrorCustomizer
* and is called before passing the error to the RedBox.
*/
Pair<String, StackFrame[]> customizeErrorInfo(Pair<String, StackFrame[]> errorInfo);
}
@@ -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.devsupport.interfaces
import android.util.Pair
/** Interface that lets parts of the app process the errors before showing the redbox */
public fun interface ErrorCustomizer {
/**
* The function that need to be registered using [DevSupportManager].registerErrorCustomizer and
* is called before passing the error to the RedBox.
*/
public fun customizeErrorInfo(
errorInfo: Pair<String, Array<StackFrame>>
): Pair<String, Array<StackFrame>>
}
@@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.devsupport.interfaces;
package com.facebook.react.devsupport.interfaces
public interface PackagerStatusCallback {
void onPackagerStatusFetched(boolean packagerIsRunning);
public fun interface PackagerStatusCallback {
public fun onPackagerStatusFetched(packagerIsRunning: Boolean)
}
@@ -1,40 +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.devsupport.interfaces;
import android.content.Context;
import android.text.SpannedString;
import androidx.annotation.Nullable;
/**
* Interface used by {@link BridgeDevSupportManager} to allow interception on any redboxes during
* development and handling the information from the redbox. The implementation should be passed by
* setRedBoxHandler in ReactInstanceManager.
*/
public interface RedBoxHandler {
/** Callback interface for {@link #reportRedbox}. */
interface ReportCompletedListener {
void onReportSuccess(SpannedString spannedString);
void onReportError(SpannedString spannedString);
}
/** Handle the information from the redbox. */
void handleRedbox(@Nullable String title, StackFrame[] stack, ErrorType errorType);
/** Whether the report feature is enabled. */
boolean isReportEnabled();
/** Report the information from the redbox and set up a callback listener. */
void reportRedbox(
Context context,
String title,
StackFrame[] stack,
String sourceUrl,
ReportCompletedListener reportCompletedListener);
}
@@ -0,0 +1,40 @@
/*
* 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.devsupport.interfaces
import android.content.Context
import android.text.SpannedString
/**
* Interface used by [BridgeDevSupportManager] to allow interception on any redboxes during
* development and handling the information from the redbox. The implementation should be passed by
* setRedBoxHandler in ReactInstanceManager.
*/
public interface RedBoxHandler {
/** Callback interface for [.reportRedbox]. */
public interface ReportCompletedListener {
public fun onReportSuccess(spannedString: SpannedString?)
public fun onReportError(spannedString: SpannedString?)
}
/** Handle the information from the redbox. */
public fun handleRedbox(title: String?, stack: Array<StackFrame>, errorType: ErrorType)
/** Whether the report feature is enabled. */
public fun isReportEnabled(): Boolean
/** Report the information from the redbox and set up a callback listener. */
public fun reportRedbox(
context: Context,
title: String,
stack: Array<StackFrame>,
sourceUrl: String,
reportCompletedListener: ReportCompletedListener
)
}
@@ -5,40 +5,40 @@
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.devsupport.interfaces;
package com.facebook.react.devsupport.interfaces
import org.json.JSONObject;
import org.json.JSONObject
/** Represents a generic entry in a stack trace, be it originally from JS or Java. */
public interface StackFrame {
/**
* Get the file this stack frame points to.
*
* <p>JS traces return the full path to the file here, while Java traces only return the file name
* JS traces return the full path to the file here, while Java traces only return the file name
* (the path is not known).
*/
public String getFile();
public val file: String?
/** Get the name of the method this frame points to. */
public String getMethod();
public val method: String?
/** Get the line number this frame points to in the file returned by {@link #getFile()}. */
public int getLine();
/** Get the line number this frame points to in the file returned by [.getFile]. */
public val line: Int
/** Get the column this frame points to in the file returned by {@link #getFile()}. */
public int getColumn();
/** Get the column this frame points to in the file returned by [.getFile]. */
public val column: Int
/**
* Get just the name of the file this frame points to.
*
* <p>For JS traces this is different from {@link #getFile()} in that it only returns the file
* name, not the full path. For Java traces there is no difference.
* For JS traces this is different from [.getFile] in that it only returns the file name, not the
* full path. For Java traces there is no difference.
*/
public String getFileName();
public val fileName: String?
/** Whether this frame is collapsed. */
public boolean isCollapsed();
public val isCollapsed: Boolean
/** Convert the stack frame to a JSON representation. */
public JSONObject toJSON();
public fun toJSON(): JSONObject?
}