Skip to content

Commit

Permalink
Convert interfaces inside devsupport/interfaces to Kotlin (facebook#4…
Browse files Browse the repository at this point in the history
…4055)

Summary:
Pull Request resolved: facebook#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).

Differential Revision: D56052137
  • Loading branch information
rshest authored and facebook-github-bot committed Apr 12, 2024
1 parent 05ef779 commit 48fb694
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

void updateProgress(
final @Nullable String status, final @Nullable Integer done, final @Nullable Integer total);
public fun updateProgress(status: String?, done: Int?, total: Int?)

void hide();
public fun hide()
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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?
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}

0 comments on commit 48fb694

Please sign in to comment.