@@ -48,7 +48,7 @@ import com.facebook.react.common.build.ReactBuildConfig
48
48
@Nullsafe(Nullsafe .Mode .LOCAL )
49
49
@StableReactNativeAPI
50
50
public abstract class BaseJavaModule (
51
- private val reactApplicationContext : ReactApplicationContext ? = null
51
+ private val _reactApplicationContext : ReactApplicationContext ? = null
52
52
) : NativeModule {
53
53
@DoNotStrip
54
54
protected var eventEmitterCallback: CxxCallbackImpl ? = null
@@ -76,8 +76,8 @@ public abstract class BaseJavaModule(
76
76
* Subclasses can use this method to access {@link ReactApplicationContext} passed as a
77
77
* constructor.
78
78
*/
79
- protected fun getReactApplicationContext () : ReactApplicationContext =
80
- requireNotNull(reactApplicationContext ) {
79
+ protected val reactApplicationContext : ReactApplicationContext
80
+ get() = requireNotNull(_reactApplicationContext ) {
81
81
" Tried to get ReactApplicationContext even though NativeModule wasn't instantiated with one"
82
82
}
83
83
@@ -94,26 +94,28 @@ public abstract class BaseJavaModule(
94
94
* <p>Threading implications have not been analyzed fully yet, so assume this method is not
95
95
* thread-safe.
96
96
*/
97
- @ThreadConfined(ANY )
98
- protected fun getReactApplicationContextIfActiveOrWarn (): ReactApplicationContext ? {
99
- if (reactApplicationContext != null && reactApplicationContext.hasActiveReactInstance()) {
100
- return reactApplicationContext
101
- }
102
97
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
114
118
}
115
- return null
116
- }
117
119
118
120
public companion object {
119
121
public const val METHOD_TYPE_ASYNC : String = " async"
0 commit comments