react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[kotlinify] Kotlinify BaseJavaModule

Open l2hyunwoo opened this issue 6 months ago • 1 comments

Summary:

Issues from #50513

Migrate BaseJavaModule.java from Java to Kotlin

Discussion

I think it's also possible to call getReactApplicationContext as a property getter of reactApplicationContext 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

@Nullsafe(Nullsafe.Mode.LOCAL)
@StableReactNativeAPI
public abstract class BaseJavaModule(
  private val reactApplicationContext: ReactApplicationContext? = null
) : NativeModule {
  // ....
  protected fun getReactApplicationContext(): ReactApplicationContext =
    requireNotNull(reactApplicationContext) {
      "Tried to get ReactApplicationContext even though NativeModule wasn't instantiated with one"
    }
}

TO-BE

@Nullsafe(Nullsafe.Mode.LOCAL)
@StableReactNativeAPI
public abstract class BaseJavaModule(
  private val _reactApplicationContext: ReactApplicationContext? = null
) : NativeModule {
  protected val reactApplicationContext: ReactApplicationContext
    get() = requireNotNull(reactApplicationContext) {
      "Tried to get ReactApplicationContext even though NativeModule wasn't instantiated with one"
    }
}

Changelog:

[ANDROID] [CHANGED] Migrate BaseJavaModule from Java to Kotlin

Test Plan:

yarn android
yarn test-android

yarn android

스크린샷 2025-05-10 오전 12 22 39

yarn test-android

스크린샷 2025-05-10 오전 12 24 42

l2hyunwoo avatar May 09 '25 02:05 l2hyunwoo

w: file:///__w/react-native/react-native/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.kt:242:35 This synthetic property is based on the getter function 'fun getReactApplicationContextIfActiveOrWarn(): ReactApplicationContext?' from Kotlin. In the future, synthetic properties will be available only if the base getter function came from Java. Consider replacing this property access with a 'getReactApplicationContextIfActiveOrWarn()' function call. w: file:///__w/react-native/react-native/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.kt:249:5 This synthetic property is based on the getter function 'fun getReactApplicationContext(): ReactApplicationContext' from Kotlin. In the future, synthetic properties will be available only if the base getter function came from Java. Consider replacing this property access with a 'getReactApplicationContext()' function call. w: file:///__w/react-native/react-native/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.kt:362:39 This synthetic property is based on the getter function 'fun getReactApplicationContextIfActiveOrWarn(): ReactApplicationContext?' from Kotlin. In the future, synthetic properties will be available only if the base getter function came from Java. Consider replacing this property access with a 'getReactApplicationContextIfActiveOrWarn()' function call. w: file:///__w/react-native/react-native/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.kt:445:35 This synthetic property is based on the getter function 'fun getReactApplicationContextIfActiveOrWarn(): ReactApplicationContext?' from Kotlin. In the future, synthetic properties will be available only if the base getter function came from Java. Consider replacing this property access with a 'getReactApplicationContextIfActiveOrWarn()' function call.

It should be fixed on other commit

l2hyunwoo avatar May 09 '25 14:05 l2hyunwoo

Hi @l2hyunwoo, thanks for all the work here! Following up on this, is there any help you need to make it to the finish line?

mateoguzmana avatar Jun 07 '25 08:06 mateoguzmana

@mateoguzmana Oh, I forgot to do this. I'll make it until next wednesday. Thanks for reminding it.

l2hyunwoo avatar Jun 07 '25 23:06 l2hyunwoo

There aren't any particular issues at the moment, but if I encounter any problems while working on this, I will leave a comment on this PR.

l2hyunwoo avatar Jun 07 '25 23:06 l2hyunwoo