Skip to content

Commit cfe63ac

Browse files
committed
Remove property access warning
1 parent 55426ed commit cfe63ac

File tree

1 file changed

+23
-21
lines changed
  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge

1 file changed

+23
-21
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/BaseJavaModule.kt

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import com.facebook.react.common.build.ReactBuildConfig
4848
@Nullsafe(Nullsafe.Mode.LOCAL)
4949
@StableReactNativeAPI
5050
public abstract class BaseJavaModule(
51-
private val reactApplicationContext: ReactApplicationContext? = null
51+
private val _reactApplicationContext: ReactApplicationContext? = null
5252
) : NativeModule {
5353
@DoNotStrip
5454
protected var eventEmitterCallback: CxxCallbackImpl? = null
@@ -76,8 +76,8 @@ public abstract class BaseJavaModule(
7676
* Subclasses can use this method to access {@link ReactApplicationContext} passed as a
7777
* constructor.
7878
*/
79-
protected fun getReactApplicationContext(): ReactApplicationContext =
80-
requireNotNull(reactApplicationContext) {
79+
protected val reactApplicationContext: ReactApplicationContext
80+
get() = requireNotNull(_reactApplicationContext) {
8181
"Tried to get ReactApplicationContext even though NativeModule wasn't instantiated with one"
8282
}
8383

@@ -94,26 +94,28 @@ public abstract class BaseJavaModule(
9494
* <p>Threading implications have not been analyzed fully yet, so assume this method is not
9595
* thread-safe.
9696
*/
97-
@ThreadConfined(ANY)
98-
protected fun getReactApplicationContextIfActiveOrWarn(): ReactApplicationContext? {
99-
if (reactApplicationContext != null && reactApplicationContext.hasActiveReactInstance()) {
100-
return reactApplicationContext
101-
}
10297

103-
// We want to collect data about how often this happens, but SoftExceptions will cause a crash
104-
// in debug mode, which isn't usually desirable.
105-
val reactNativeInstanceErrorMessage =
106-
"React Native Instance has already disappeared: requested by ${getName()}"
107-
if (ReactBuildConfig.DEBUG) {
108-
FLog.w(ReactConstants.TAG, reactNativeInstanceErrorMessage)
109-
} else {
110-
ReactSoftExceptionLogger.logSoftException(
111-
ReactConstants.TAG,
112-
RuntimeException(reactNativeInstanceErrorMessage)
113-
)
98+
protected val reactApplicationContextIfActiveOrWarn: ReactApplicationContext?
99+
@ThreadConfined(ANY)
100+
get() {
101+
if (_reactApplicationContext != null && _reactApplicationContext.hasActiveReactInstance()) {
102+
return _reactApplicationContext
103+
}
104+
105+
// We want to collect data about how often this happens, but SoftExceptions will cause a crash
106+
// in debug mode, which isn't usually desirable.
107+
val reactNativeInstanceErrorMessage =
108+
"React Native Instance has already disappeared: requested by ${getName()}"
109+
if (ReactBuildConfig.DEBUG) {
110+
FLog.w(ReactConstants.TAG, reactNativeInstanceErrorMessage)
111+
} else {
112+
ReactSoftExceptionLogger.logSoftException(
113+
ReactConstants.TAG,
114+
RuntimeException(reactNativeInstanceErrorMessage)
115+
)
116+
}
117+
return null
114118
}
115-
return null
116-
}
117119

118120
public companion object {
119121
public const val METHOD_TYPE_ASYNC: String = "async"

0 commit comments

Comments
 (0)