react-native
react-native copied to clipboard
[kotlinify] Kotlinify BaseJavaModule
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
yarn test-android
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
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 Oh, I forgot to do this. I'll make it until next wednesday. Thanks for reminding it.
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.