diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/Promise.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/Promise.kt similarity index 69% rename from packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/Promise.java rename to packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/Promise.kt index 1d7a8da303e0e5..8425fe70d6748c 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/Promise.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/Promise.kt @@ -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 @@ * 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); - - /* ------------ - * 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); + public fun reject(code: String?, message: String?, throwable: Throwable?, userInfo: WritableMap?) + + /** 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) } diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/share/ShareModuleTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/share/ShareModuleTest.kt index 5ca2e9c406e9d2..2db672510312e7 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/share/ShareModuleTest.kt +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/share/ShareModuleTest.kt @@ -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) } }