Skip to content

Commit a42b030

Browse files
chore: replace deprecated apis with modern
1 parent 9f410b0 commit a42b030

41 files changed

Lines changed: 278 additions & 786 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/CI_DOCUMENTATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ All workflows use standardized tooling versions to ensure consistency:
2020
| ---------------- | --------- | ----------------------------- |
2121
| **Node.js** | `24` | `.nvmrc` |
2222
| **Yarn** | `4.12.0` | `package.json#packageManager` |
23-
| **React Native** | `0.83.4` | `package.json` |
23+
| **React Native** | `0.84.1` | `package.json` |
2424
| **React** | `19.2.14` | `package.json` |
2525
| **TypeScript** | `5.9.3` | `package.json` |
2626

MendixNative.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Pod::Spec.new do |s|
1414
s.source = { :git => "https://github.com/mendix/mendix-native.git", :tag => "#{s.version}" }
1515

1616
s.source_files = "ios/**/*.{h,m,mm,cpp,swift}"
17-
s.public_header_files = "ios/**/*.h"
18-
s.private_header_files = "ios/**/*.h"
17+
s.public_header_files = "ios/Modules/Helper/ReactHostHelper.h"
18+
s.private_header_files = "ios/TurboModules/**/*.h"
1919

2020
s.dependency "SSZipArchive"
2121
s.dependency "RNCAsyncStorage"

android/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ android {
3636
}
3737

3838
buildFeatures {
39-
dataBinding true
40-
viewBinding true
4139
buildConfig true
4240
}
4341

@@ -88,7 +86,7 @@ dependencies {
8886
kapt 'com.github.bumptech.glide:compiler:4.12.0'
8987

9088

91-
api "com.facebook.react:react-android:0.83.4"
89+
api "com.facebook.react:react-android:0.84.1"
9290
api project(':op-engineering_op-sqlite')
9391
api project(':react-native-async-storage_async-storage')
9492
api project(':react-native-gesture-handler')

android/src/main/java/com/mendix/mendixnative/MendixInitializer.kt

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ package com.mendix.mendixnative
33
import android.app.Activity
44
import android.view.MotionEvent
55
import com.facebook.react.ReactHost
6-
import com.facebook.react.ReactInstanceEventListener
7-
import com.facebook.react.ReactNativeHost
8-
import com.facebook.react.bridge.ReactContext
96
import com.facebook.react.common.ShakeDetector
107
import com.facebook.react.devsupport.DevSupportManagerBase
118
import com.facebook.react.devsupport.attachMendixSupportManagerShakeDetector
@@ -20,25 +17,16 @@ import com.mendix.mendixnative.react.MxConfiguration
2017
import com.mendix.mendixnative.react.clearCachedReactNativeDevBundle
2118
import com.mendix.mendixnative.react.clearData
2219
import com.mendix.mendixnative.react.closeSqlDatabaseConnection
23-
import com.mendix.mendixnative.react.toggleElementInspector
24-
import com.mendix.mendixnative.react.NativeReloadHandler
2520

2621
class MendixInitializer(
2722
private val context: Activity,
2823
private val reactHost: ReactHost,
29-
private val reactNativeHost: ReactNativeHost,
3024
private val hasRNDeveloperSupport: Boolean = false,
31-
) : ReactInstanceEventListener {
25+
) {
3226
private var shakeDetector: ShakeDetector? = null
3327
private var devMenuTouchEventHandler: DevMenuTouchEventHandler? = null
3428

35-
fun onCreate(
36-
mendixApp: MendixApp,
37-
devAppMenuHandler: DevAppMenuHandler = object : DevAppMenuHandler {
38-
override fun showDevAppMenu() {}
39-
},
40-
clearData: Boolean,
41-
) {
29+
fun onCreate(mendixApp: MendixApp, clearData: Boolean) {
4230
// Assign mendix xas id interceptor to okhttp
4331
CookieEncryption.init(this.context)
4432
if (CookieEncryption.isCookieEncryptionEnabled()) {
@@ -54,33 +42,9 @@ class MendixInitializer(
5442
MxConfiguration.warningsFilter = mendixApp.warningsFilter
5543

5644
// This is here to make sure that a clean host instance is initialised.
57-
restartReactInstanceManager()
45+
reactHost.invalidate()
5846
if (clearData) clearData(context.application)
5947
if (hasRNDeveloperSupport) setupDeveloperApp(runtimeUrl, mendixApp)
60-
if (mendixApp.attachCustomDeveloperMenu) attachCustomDeveloperMenu(devAppMenuHandler)
61-
}
62-
63-
private fun restartReactInstanceManager() {
64-
if (reactNativeHost.hasInstance()) reactNativeHost.clear()
65-
// Pre-initialize reactInstanceManager to be available for other methods
66-
if (reactNativeHost.hasInstance()) reactNativeHost.reactInstanceManager
67-
}
68-
69-
private fun attachCustomDeveloperMenu(devAppMenuHandler: DevAppMenuHandler) {
70-
devMenuTouchEventHandler =
71-
DevMenuTouchEventHandler(object : DevMenuTouchEventHandler.DevMenuTouchListener {
72-
override fun onTap() {
73-
reactNativeHost.reactApplicationContext()?.let {
74-
NativeReloadHandler(it).reload()
75-
}
76-
}
77-
78-
override fun onLongPress() {
79-
devAppMenuHandler.showDevAppMenu()
80-
}
81-
})
82-
83-
attachShakeDetector(devAppMenuHandler)
8448
}
8549

8650
fun onDestroy() {
@@ -89,29 +53,18 @@ class MendixInitializer(
8953

9054
if (hasRNDeveloperSupport) {
9155
AppPreferences(context.applicationContext).setElementInspector(false)
92-
reactHost.removeReactInstanceEventListener(this)
9356
}
94-
95-
// We need to clear the host to allow for reinitialization of the Native Modules
96-
// Especially for when switching between apps
97-
reactNativeHost.clear()
57+
reactHost.invalidate()
9858

9959
// We need to close all databases separately to avoid hitting a read only state exception
10060
// Databases need to close after we are done closing the react native host to avoid db locks
101-
closeSqlDatabaseConnection(reactNativeHost.reactApplicationContext())
61+
closeSqlDatabaseConnection(reactHost.currentReactContext)
10262
}
10363

10464
fun stopShakeDetector() {
10565
shakeDetector?.stop()
10666
}
10767

108-
override fun onReactContextInitialized(context: ReactContext) {
109-
val preferences = AppPreferences(context)
110-
if (preferences.isElementInspectorEnabled) {
111-
toggleElementInspector(context)
112-
}
113-
}
114-
11568
fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
11669
return devMenuTouchEventHandler?.handle(ev) ?: false
11770
}
@@ -139,7 +92,6 @@ class MendixInitializer(
13992
preferences.setDevMode((mendixApp.showExtendedDevMenu))
14093

14194
clearCachedReactNativeDevBundle(context.application)
142-
reactHost.addReactInstanceEventListener(this)
14395
}
14496
}
14597

android/src/main/java/com/mendix/mendixnative/activity/MendixReactActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ open class MendixReactActivity : ReactActivity(), DevAppMenuHandler, LaunchScree
3131
?: throw ClassCastException("Application needs to implement MendixApplication")
3232

3333
mendixInitializer =
34-
MendixInitializer(this, reactHost, reactNativeHost, mendixApplication.useDeveloperSupport)
35-
mendixInitializer.onCreate(mendixApp!!, this, intent.getBooleanExtra(CLEAR_DATA, false))
34+
MendixInitializer(this, reactHost, mendixApplication.useDeveloperSupport)
35+
mendixInitializer.onCreate(mendixApp!!, intent.getBooleanExtra(CLEAR_DATA, false))
3636

3737
super.onCreate(null)
3838
}

android/src/main/java/com/mendix/mendixnative/fragment/MendixReactFragment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ open class MendixReactFragment : ReactFragment(), MendixReactFragmentView {
6767
val hasRNDeveloperSupport = requireArguments().getBoolean(ARG_USE_DEVELOPER_SUPPORT, false)
6868

6969
mendixInitializer =
70-
MendixInitializer(requireActivity(), reactHost!!, reactNativeHost, hasRNDeveloperSupport).also {
71-
it.onCreate(mendixApp!!, this, clearData)
70+
MendixInitializer(requireActivity(), reactHost!!, hasRNDeveloperSupport).also {
71+
it.onCreate(mendixApp!!, clearData)
7272
}
7373

7474
super.onCreate(savedInstanceState)

android/src/main/java/com/mendix/mendixnative/react/ClearData.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import android.content.Context
55
import android.util.Log
66
import android.webkit.CookieManager
77
import android.widget.Toast
8-
import com.facebook.react.ReactNativeHost
8+
import com.facebook.react.ReactHost
99
import com.facebook.react.bridge.ReactContext
1010
import com.facebook.react.modules.network.NetworkingModule
1111
import com.mendix.mendixnative.encryption.MendixEncryptedStorage
@@ -34,9 +34,9 @@ fun clearData(applicationContext: Application) = clearCookies().also {
3434
fileBackend.deleteDirectory(applicationContext.filesDir)
3535
}
3636

37-
fun clearDataWithReactContext(applicationContext: Application, reactNativeHost: ReactNativeHost, cb: (success: Boolean) -> Unit) {
37+
fun clearDataWithReactContext(applicationContext: Application, reactHost: ReactHost, cb: (success: Boolean) -> Unit) {
3838
clearCachedReactNativeDevBundle(applicationContext)
39-
val reactContext = reactNativeHost.reactContext()
39+
val reactContext = reactHost.currentReactContext
4040
val fileBackend = FileBackend(applicationContext)
4141
fileBackend.deleteDirectory(applicationContext.filesDir)
4242
val errorString = "Clearing %s failed. Please clear your data from the launch screen."
@@ -57,7 +57,7 @@ fun clearDataWithReactContext(applicationContext: Application, reactNativeHost:
5757
reportError("database")
5858
}
5959

60-
if (!clearAsyncStorage(reactNativeHost)) {
60+
if (!clearAsyncStorage(reactHost)) {
6161
reportError("async storage")
6262
}
6363

@@ -88,7 +88,7 @@ fun clearDataWithReactContext(applicationContext: Application, reactNativeHost:
8888
}
8989

9090
fun deleteAppDatabaseAsync(reactContext: ReactContext?, cb: BooleanCallback) {
91-
val opSQLiteModule = reactContext?.getNativeModule(OPSQLiteModule::class.java)
91+
val opSQLiteModule = reactContext?.nativeModule<OPSQLiteModule>(OPSQLiteModule.NAME)
9292
if (opSQLiteModule != null) {
9393
try {
9494
opSQLiteModule.deleteAllDBs()
@@ -108,8 +108,8 @@ fun deleteAppDatabaseAsync(reactContext: ReactContext?, cb: BooleanCallback) {
108108
* Note: Previous implementation only checked module availability without clearing.
109109
* This now actually clears the storage using AsyncStorageModule.clear().
110110
*/
111-
fun clearAsyncStorage(reactNativeHost: ReactNativeHost): Boolean {
112-
val asyncStorageModule = reactNativeHost.reactContext()?.getNativeModule(AsyncStorageModule::class.java)
111+
fun clearAsyncStorage(reactHost: ReactHost): Boolean {
112+
val asyncStorageModule = reactHost.nativeModule<AsyncStorageModule>(AsyncStorageModule.NAME)
113113
if (asyncStorageModule != null) {
114114
try {
115115
// Clear AsyncStorage synchronously - clear() expects a callback but we're using fire-and-forget
@@ -131,7 +131,7 @@ fun clearSecureStorage(context: Context?): Boolean =
131131
context?.let { MendixEncryptedStorage.getMendixEncryptedStorage(it).clear() } ?: false
132132

133133
fun clearCookiesAsync(reactContext: ReactContext?, cb: (success: Boolean) -> Unit) {
134-
val networkingModule = reactContext?.getNativeModule(NetworkingModule::class.java)
134+
val networkingModule = reactContext?.nativeModule<NetworkingModule>(NetworkingModule.NAME)
135135
if (networkingModule != null) {
136136
try {
137137
networkingModule.clearCookies { result ->

android/src/main/java/com/mendix/mendixnative/react/CloseApp.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import com.op.sqlite.OPSQLiteModule
1010
* This is called during app shutdown to gracefully close database connections.
1111
*/
1212
fun closeSqlDatabaseConnection(reactContext: ReactContext?) {
13-
val opSQLiteModule = reactContext?.getNativeModule(OPSQLiteModule::class.java)
13+
val opSQLiteModule = reactContext?.nativeModule<OPSQLiteModule>(OPSQLiteModule.NAME)
1414
if (opSQLiteModule != null) {
1515
try {
1616
opSQLiteModule.closeAllConnections()
Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,24 @@
11
package com.mendix.mendixnative.react
22

3-
import android.annotation.SuppressLint
43
import android.util.Log
54
import com.facebook.react.ReactApplication
6-
import com.facebook.react.ReactNativeHost
5+
import com.facebook.react.ReactHost
76
import com.facebook.react.bridge.NativeModule
87
import com.facebook.react.bridge.ReactApplicationContext
98
import com.facebook.react.bridge.ReactContext
10-
11-
inline fun <reified T: NativeModule> ReactContext.typeSafeNativeModule(): T? {
9+
inline fun <reified T: NativeModule> ReactContext.nativeModule(name: String): T? {
1210
return try {
13-
getNativeModule(T::class.java)
11+
getNativeModule(name) as? T
1412
} catch (e: Exception) {
1513
Log.e("ModuleAccess", "Error getting module ${T::class.simpleName}", e)
1614
null
1715
}
1816
}
1917

20-
inline fun <reified T: NativeModule> ReactNativeHost.typeSafeNativeModule(): T? {
21-
return reactContext()?.typeSafeNativeModule<T>()
22-
}
23-
24-
fun ReactNativeHost.reactContext(): ReactContext? {
25-
return reactInstanceManager.currentReactContext
18+
inline fun <reified T: NativeModule> ReactHost.nativeModule(name: String): T? {
19+
return currentReactContext?.nativeModule<T>(name)
2620
}
2721

28-
fun ReactNativeHost.reactApplicationContext(): ReactApplicationContext? {
29-
val context = reactContext()
30-
if (context is ReactApplicationContext) {
31-
return context
32-
}
33-
return null
22+
inline fun <reified T: NativeModule> ReactApplicationContext.nativeModule(name: String): T? {
23+
return (applicationContext as? ReactApplication)?.reactHost?.nativeModule<T>(name)
3424
}

android/src/main/java/com/mendix/mendixnative/react/NativeErrorHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import com.facebook.react.modules.core.ExceptionsManagerModule
1313
class NativeErrorHandler(val reactContext: ReactApplicationContext) {
1414
fun handle(message: String?, stackTrace: ReadableArray?) {
1515
// Use typed module access instead of generic typeSafeNativeModule
16-
val exceptionsManagerModule = reactContext.getNativeModule(ExceptionsManagerModule::class.java)
16+
val exceptionsManagerModule = reactContext.nativeModule<ExceptionsManagerModule>(ExceptionsManagerModule.NAME)
1717
exceptionsManagerModule?.reportSoftException(message, stackTrace, 0.0)
1818

1919
// Note: updateExceptionMessage is not available in RN 0.77.1+

0 commit comments

Comments
 (0)