mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Migrate Promise interface to Kotlin (#44587)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44587 # Changelog: [Internal] - As in the title, moving towards migrating all the interfaces in react.bridge. Reviewed By: tdn120 Differential Revision: D57433401 fbshipit-source-id: 35581d27d6d093edb1cc59b245e6468758825f68
This commit is contained in:
committed by
Facebook GitHub Bot
parent
491c3e9d76
commit
de73e44569
+18
-28
@@ -5,10 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.bridge;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
package com.facebook.react.bridge
|
||||
|
||||
/*
|
||||
* Interface that represents a JavaScript Promise which can be passed to the native module as a
|
||||
@@ -18,13 +15,12 @@ import androidx.annotation.Nullable;
|
||||
* will be marked as "promise" and will return a promise when invoked from JavaScript.
|
||||
*/
|
||||
public interface Promise {
|
||||
|
||||
/**
|
||||
* Successfully resolve the Promise with an optional value.
|
||||
*
|
||||
* @param value Object
|
||||
*/
|
||||
void resolve(@Nullable Object value);
|
||||
public fun resolve(value: Any?)
|
||||
|
||||
/**
|
||||
* Report an error without an exception using a custom code and error message.
|
||||
@@ -32,7 +28,7 @@ public interface Promise {
|
||||
* @param code String
|
||||
* @param message String
|
||||
*/
|
||||
void reject(String code, String message);
|
||||
public fun reject(code: String, message: String?)
|
||||
|
||||
/**
|
||||
* Report an exception with a custom code.
|
||||
@@ -40,7 +36,7 @@ public interface Promise {
|
||||
* @param code String
|
||||
* @param throwable Throwable
|
||||
*/
|
||||
void reject(String code, Throwable throwable);
|
||||
public fun reject(code: String, throwable: Throwable?)
|
||||
|
||||
/**
|
||||
* Report an exception with a custom code and error message.
|
||||
@@ -49,7 +45,7 @@ public interface Promise {
|
||||
* @param message String
|
||||
* @param throwable Throwable
|
||||
*/
|
||||
void reject(String code, String message, Throwable throwable);
|
||||
public fun reject(code: String, message: String?, throwable: Throwable?)
|
||||
|
||||
/**
|
||||
* Report an exception, with default error code. Useful in catch-all scenarios where it's unclear
|
||||
@@ -57,12 +53,11 @@ public interface Promise {
|
||||
*
|
||||
* @param throwable Throwable
|
||||
*/
|
||||
void reject(Throwable throwable);
|
||||
public fun reject(throwable: Throwable)
|
||||
|
||||
/* ---------------------------
|
||||
* With userInfo WritableMap
|
||||
* --------------------------- */
|
||||
|
||||
/**
|
||||
* Report an exception, with default error code, with userInfo. Useful in catch-all scenarios
|
||||
* where it's unclear why the error occurred.
|
||||
@@ -70,7 +65,7 @@ public interface Promise {
|
||||
* @param throwable Throwable
|
||||
* @param userInfo WritableMap
|
||||
*/
|
||||
void reject(Throwable throwable, WritableMap userInfo);
|
||||
public fun reject(throwable: Throwable, userInfo: WritableMap)
|
||||
|
||||
/**
|
||||
* Reject with a code and userInfo WritableMap.
|
||||
@@ -78,7 +73,7 @@ public interface Promise {
|
||||
* @param code String
|
||||
* @param userInfo WritableMap
|
||||
*/
|
||||
void reject(String code, @NonNull WritableMap userInfo);
|
||||
public fun reject(code: String, userInfo: WritableMap)
|
||||
|
||||
/**
|
||||
* Report an exception with a custom code and userInfo.
|
||||
@@ -87,7 +82,7 @@ public interface Promise {
|
||||
* @param throwable Throwable
|
||||
* @param userInfo WritableMap
|
||||
*/
|
||||
void reject(String code, Throwable throwable, WritableMap userInfo);
|
||||
public fun reject(code: String, throwable: Throwable?, userInfo: WritableMap)
|
||||
|
||||
/**
|
||||
* Report an error with a custom code, error message and userInfo, an error not caused by an
|
||||
@@ -97,7 +92,7 @@ public interface Promise {
|
||||
* @param message String
|
||||
* @param userInfo WritableMap
|
||||
*/
|
||||
void reject(String code, String message, @NonNull WritableMap userInfo);
|
||||
public fun reject(code: String, message: String?, userInfo: WritableMap)
|
||||
|
||||
/**
|
||||
* Report an exception with a custom code, error message and userInfo.
|
||||
@@ -107,18 +102,13 @@ public interface Promise {
|
||||
* @param throwable Throwable
|
||||
* @param userInfo WritableMap
|
||||
*/
|
||||
void reject(String code, String message, Throwable throwable, WritableMap userInfo);
|
||||
public fun reject(code: String?, message: String?, throwable: Throwable?, userInfo: WritableMap?)
|
||||
|
||||
/* ------------
|
||||
* Deprecated
|
||||
* ------------ */
|
||||
|
||||
/**
|
||||
* Report an error which wasn't caused by an exception.
|
||||
*
|
||||
* @deprecated Prefer passing a module-specific error code to JS. Using this method will pass the
|
||||
* error code "EUNSPECIFIED".
|
||||
*/
|
||||
@Deprecated
|
||||
void reject(String message);
|
||||
/** Report an error which wasn't caused by an exception. */
|
||||
@Deprecated(
|
||||
message =
|
||||
"""Prefer passing a module-specific error code to JS. Using this method will pass the
|
||||
error code EUNSPECIFIED""",
|
||||
replaceWith = ReplaceWith("reject(code, message)"))
|
||||
public fun reject(message: String)
|
||||
}
|
||||
+9
-9
@@ -108,35 +108,35 @@ class ShareModuleTest {
|
||||
this.value = value
|
||||
}
|
||||
|
||||
override fun reject(code: String?, message: String?) {
|
||||
override fun reject(code: String, message: String?) {
|
||||
reject(code, message, null, null)
|
||||
}
|
||||
|
||||
override fun reject(code: String?, throwable: Throwable?) {
|
||||
override fun reject(code: String, throwable: Throwable?) {
|
||||
reject(code, null, throwable, null)
|
||||
}
|
||||
|
||||
override fun reject(code: String?, message: String?, throwable: Throwable?) {
|
||||
override fun reject(code: String, message: String?, throwable: Throwable?) {
|
||||
reject(code, message, throwable, null)
|
||||
}
|
||||
|
||||
override fun reject(throwable: Throwable?) {
|
||||
override fun reject(throwable: Throwable) {
|
||||
reject(null, null, throwable, null)
|
||||
}
|
||||
|
||||
override fun reject(throwable: Throwable?, userInfo: WritableMap?) {
|
||||
override fun reject(throwable: Throwable, userInfo: WritableMap) {
|
||||
reject(null, null, throwable, userInfo)
|
||||
}
|
||||
|
||||
override fun reject(code: String?, userInfo: WritableMap) {
|
||||
override fun reject(code: String, userInfo: WritableMap) {
|
||||
reject(code, null, null, userInfo)
|
||||
}
|
||||
|
||||
override fun reject(code: String?, throwable: Throwable?, userInfo: WritableMap?) {
|
||||
override fun reject(code: String, throwable: Throwable?, userInfo: WritableMap) {
|
||||
reject(code, null, throwable, userInfo)
|
||||
}
|
||||
|
||||
override fun reject(code: String?, message: String?, userInfo: WritableMap) {
|
||||
override fun reject(code: String, message: String?, userInfo: WritableMap) {
|
||||
reject(code, message, null, userInfo)
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ class ShareModuleTest {
|
||||
}
|
||||
|
||||
@Deprecated("Method deprecated")
|
||||
override fun reject(message: String?) {
|
||||
override fun reject(message: String) {
|
||||
reject(null, message, null, null)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user