-
Notifications
You must be signed in to change notification settings - Fork 24.7k
[kotlinify] Kotlinify BaseJavaModule #51207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[kotlinify] Kotlinify BaseJavaModule #51207
Conversation
eeb882e
to
bac454f
Compare
bac454f
to
50b5f1e
Compare
fea09af
to
3193c7b
Compare
It should be fixed on other commit |
9f59aee
to
1df590a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for migrating this file!
Could you please remove any change that is not related to the migration of the file itself? It will make it easier for us to review and analyse whether the migration has potential breaking changes in the ecosystem.
@@ -32,15 +32,15 @@ internal class ToastModule(reactContext: ReactApplicationContext) : | |||
override fun show(message: String?, durationDouble: Double) { | |||
val duration = durationDouble.toInt() | |||
UiThreadUtil.runOnUiThread { | |||
Toast.makeText(getReactApplicationContext(), message, duration).show() | |||
Toast.makeText(reactApplicationContext, message, duration).show() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these changes related to the migration? If not, let's please take them out – preferably you could send them over in a separate PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I apply your code review! Thanks for review it.
4a40e10
to
86ac511
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the other comments! I have some concerns about the breaking changes this might introduce.
I have an example of a file that maintains backwards compatibility, perhaps we can try something like that in this case: InteropEvent.kt
@@ -17,6 +17,7 @@ import com.facebook.react.bridge.UiThreadUtil | |||
import com.facebook.react.module.annotations.ReactModule | |||
|
|||
/** Module that exposes the user's preferred color scheme. */ | |||
@Suppress("SYNTHETIC_PROPERTY_WITHOUT_JAVA_ORIGIN") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need these suppressions?
@@ -41,19 +41,19 @@ public NativeSampleTurboModuleSpec(ReactApplicationContext reactContext) { | |||
} | |||
|
|||
protected final void emitOnPress() { | |||
mEventEmitterCallback.invoke("onPress"); | |||
getEventEmitterCallback().invoke("onPress"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally when we have to do these changes after a migration, it indicates it is a breaking change. I've checked and this specific property is used in other open source packages: See
Could you try to find a way to maintain backwards compatibility? we might have to expose a getter separately, but leaving the property with the same name so it can also be accessed like the change you did here
@@ -109,7 +109,7 @@ internal class JavaModuleWrapper( | |||
val baseJavaModule = module | |||
|
|||
Systrace.beginSection(TRACE_TAG_REACT, "module.getConstants") | |||
val map = baseJavaModule.constants | |||
val map = baseJavaModule.getConstants() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar here, we would need to find a way to maintain the access to the constants
backwards compatible
@DoNotStrip | ||
protected void setEventEmitterCallback(CxxCallbackImpl eventEmitterCallback) { | ||
mEventEmitterCallback = eventEmitterCallback; | ||
public companion object { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: let's try to leave the original reference from where the strings where taken from
public companion object { | |
public companion object { | |
// taken from Libraries/Utilities/MessageQueue.js |
- revoke property access - Remove warning as marking with an annotation
86ac511
to
e390cdc
Compare
Summary:
Issues from #50513
Migrate
BaseJavaModule.java
from Java to KotlinDiscussion
I think it's also possible to call
getReactApplicationContext
as a property getter ofreactApplicationContext
rather than as a function call, and I believe that writing it this way preserves the unique syntax of Kotlin. What do you think?If it sounds, I'll make other PR to use property getter of non-nullable
ReactApplicationContext
AS-IS
TO-BE
Changelog:
[ANDROID] [CHANGED] Migrate
BaseJavaModule
from Java to KotlinTest Plan:
yarn android
yarn test-android