Skip to content

Commit 9075ed4

Browse files
Merge pull request #40 from mendix/moo/MOO-2265-update-deprecated-apis
[MOO-2265] - Update deprecated apis
2 parents caca72f + 2898f17 commit 9075ed4

51 files changed

Lines changed: 365 additions & 810 deletions

File tree

Some content is hidden

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

android/src/main/java/com/facebook/react/devsupport/MendixShakeDetector.kt

Lines changed: 0 additions & 46 deletions
This file was deleted.

android/src/main/java/com/mendix/mendixnative/MendixApplication.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.mendix.mendixnative.react.splash.MendixSplashScreenPresenter;
66

77
import java.util.List;
8-
import java.util.Map;
98

109
public interface MendixApplication extends ReactApplication {
1110
boolean getUseDeveloperSupport();

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.mendix.mendixnative
22

33
import android.app.Activity
44
import com.facebook.react.ReactHost
5-
import com.facebook.react.devsupport.DevSupportManagerBase
65
import com.facebook.react.modules.network.OkHttpClientProvider
76
import com.mendix.mendixnative.config.AppPreferences
87
import com.mendix.mendixnative.react.*
@@ -34,12 +33,23 @@ class MendixInitializer(
3433
MxConfiguration.runtimeUrl = runtimeUrl
3534
MxConfiguration.warningsFilter = mendixApp.warningsFilter
3635

36+
// Must run before the first access to `reactHost` below (and before any reload).
37+
// `PackagerConnectionSettings.debugServerHost` caches its value in memory for the
38+
// lifetime of the process the first time it's read (e.g. by an eager dev-support
39+
// settings reload triggered as soon as ReactHost/DevSupportManager is constructed).
40+
// If that first read happens before we persist the real Metro host, RN falls back
41+
// to its hardcoded emulator default (10.0.2.2:8081) and keeps using it for the rest
42+
// of the process — even though the correct host is written to SharedPreferences —
43+
// which is why a fresh app process (restart) "fixes" it but reload within the same
44+
// process does not. Resolving/pushing the host here, before `reactHost` is touched,
45+
// avoids that stale cache entirely.
46+
if (hasRNDeveloperSupport) setupDeveloperApp(runtimeUrl, mendixApp)
47+
3748
// Reload only if there's already a running instance.
3849
if (reactHost.currentReactContext != null) {
3950
reactHost.reload("Clean start for new Mendix app")
4051
}
4152
if (clearData) clearData(context.application)
42-
if (hasRNDeveloperSupport) setupDeveloperApp(runtimeUrl, mendixApp)
4353
}
4454

4555
fun onDestroy() {
@@ -65,6 +75,14 @@ class MendixInitializer(
6575
preferences.setDeltas(false)
6676
preferences.setDevMode((mendixApp.showExtendedDevMenu))
6777

78+
// Explicitly push the freshly resolved host into the live ReactHost's
79+
// PackagerConnectionSettings. Writing to SharedPreferences alone (above) isn't
80+
// enough if RN already cached a stale/default debug server host in memory for
81+
// this process — this overwrite takes effect immediately, regardless of when
82+
// that first (possibly premature) read happened.
83+
reactHost.devSupportManager?.devSettings?.packagerConnectionSettings?.debugServerHost =
84+
preferences.getMetroBundlerHost()
85+
6886
clearCachedReactNativeDevBundle(context.application)
6987
}
7088
}

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

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.mendix.mendixnative
22

33
import android.app.Application
44
import com.facebook.react.ReactHost
5-
import com.facebook.react.ReactNativeHost
65
import com.facebook.react.ReactPackage
76
import com.facebook.react.bridge.JSBundleLoader
87
import com.facebook.react.bridge.JSBundleLoaderDelegate
@@ -28,8 +27,6 @@ import com.mendixnative.MendixNativePackage
2827
import java.util.*
2928
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
3029

31-
import com.facebook.react.defaults.DefaultReactNativeHost
32-
3330
abstract class MendixReactApplication : Application(), MendixApplication, ErrorHandlerFactory {
3431
private val appSessionId = "" + Math.random() * 1000 + Date().time
3532
override fun getAppSessionId(): String = appSessionId
@@ -44,33 +41,11 @@ abstract class MendixReactApplication : Application(), MendixApplication, ErrorH
4441

4542
private var jsBundleFileProvider: JSBundleFileProvider? = jsBundleProvider
4643

47-
override var reactNativeHost: ReactNativeHost = object : DefaultReactNativeHost(this) {
48-
override fun getUseDeveloperSupport(): Boolean = this@MendixReactApplication.useDeveloperSupport
49-
50-
override fun getPackages(): List<ReactPackage> {
51-
val pkgs: MutableList<ReactPackage> = ArrayList()
52-
// Use the packages provided by the concrete Application subclass.
53-
pkgs.addAll(this@MendixReactApplication.packages)
54-
// Inject splashScreenPresenter into any MendixNativePackage instances without creating duplicates.
55-
applyInternalPackageAugmentations(pkgs)
56-
return pkgs
57-
}
58-
59-
override fun getJSBundleFile(): String? = this@MendixReactApplication.jsBundleFile
60-
override fun getJSMainModuleName(): String = "index"
61-
override fun getBundleAssetName(): String? = super.getBundleAssetName()
62-
override fun getRedBoxHandler(): RedBoxHandler? = null
63-
64-
// Hermes & New Arch flags; Hermes executor will be picked automatically when isHermesEnabled is true.
65-
override val isNewArchEnabled: Boolean = true
66-
override val isHermesEnabled: Boolean = true
67-
}
68-
6944
/**
70-
* Build the [ReactHost] ourselves instead of using [DefaultReactHost.getDefaultReactHost],
71-
* because that factory evaluates [ReactNativeHost.getJSBundleFile] once at creation time and
72-
* bakes the result into a fixed [JSBundleLoader]. After an OTA update deploys a new bundle,
73-
* a subsequent [ReactHost.reload] would still load the stale bundle.
45+
* Build the [ReactHost] with a custom [JSBundleLoader] instead of using a static bundle path.
46+
* The default approach evaluates the bundle file path once at creation time and bakes it into
47+
* a fixed [JSBundleLoader]. After an OTA update deploys a new bundle, a subsequent
48+
* [ReactHost.reload] would still load the stale bundle.
7449
*
7550
* By providing a **dynamic** [JSBundleLoader] whose [JSBundleLoader.loadScript] calls
7651
* [getJSBundleFile] on every invocation, each reload picks up the latest bundle path —
@@ -133,10 +108,7 @@ abstract class MendixReactApplication : Application(), MendixApplication, ErrorH
133108
override fun onCreate() {
134109
super.onCreate()
135110
SoLoader.init(this, OpenSourceMergedSoMapping)
136-
// Only load the New Architecture entry point when enabled (always true here, but guarded for safety).
137-
if (reactNativeHost is DefaultReactNativeHost) {
138-
load()
139-
}
111+
load()
140112
}
141113

142114
override fun getJSBundleFile(): String? {

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package com.mendix.mendixnative.activity
22

3+
import android.os.Build
34
import android.os.Bundle
45
import android.view.KeyEvent
56
import com.facebook.react.ReactActivity
67
import com.facebook.react.ReactActivityDelegate
7-
import com.facebook.react.bridge.ReactContext
88
import com.facebook.react.devsupport.interfaces.DevSupportManager
99
import com.mendix.mendixnative.DevAppMenuHandler
1010
import com.mendix.mendixnative.MendixApplication
1111
import com.mendix.mendixnative.MendixInitializer
1212
import com.mendix.mendixnative.react.MendixApp
1313
import com.mendix.mendixnative.react.splash.MendixSplashScreenPresenter
14-
import com.mendix.mendixnative.util.MendixBackwardsCompatUtility
14+
import java.io.Serializable
1515

1616
open class MendixReactActivity : ReactActivity(), DevAppMenuHandler, LaunchScreenHandler {
1717

@@ -24,7 +24,7 @@ open class MendixReactActivity : ReactActivity(), DevAppMenuHandler, LaunchScree
2424

2525
override fun onCreate(savedInstanceState: Bundle?) {
2626
mendixApp = mendixApp
27-
?: intent.getSerializableExtra(MENDIX_APP_INTENT_KEY) as? MendixApp
27+
?: getSerializableData(MENDIX_APP_INTENT_KEY, MendixApp::class.java)
2828
?: throw IllegalStateException("MendixApp configuration can't be null")
2929
val mendixApplication = application as? MendixApplication
3030
?: throw ClassCastException("Application needs to implement MendixApplication")
@@ -36,6 +36,19 @@ open class MendixReactActivity : ReactActivity(), DevAppMenuHandler, LaunchScree
3636
super.onCreate(null)
3737
}
3838

39+
inline fun <reified T : Serializable> getSerializableData(key: String?, clazz: Class<T>): T? {
40+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
41+
intent.getSerializableExtra<T?>(key, clazz)
42+
} else {
43+
@Suppress("DEPRECATION")
44+
val data = intent.getSerializableExtra(key)
45+
if (data is T) {
46+
return data
47+
}
48+
return null
49+
}
50+
}
51+
3952
override fun onDestroy() {
4053
mendixInitializer.onDestroy()
4154
super.onDestroy()
@@ -46,12 +59,9 @@ open class MendixReactActivity : ReactActivity(), DevAppMenuHandler, LaunchScree
4659
}
4760

4861
override fun showDevAppMenu() {
49-
currentDevSupportManager?.showDevOptionsDialog();
62+
currentDevSupportManager?.showDevOptionsDialog()
5063
}
5164

52-
private val currentReactContext: ReactContext?
53-
get() = if (reactNativeHost.hasInstance()) reactInstanceManager.currentReactContext else null
54-
5565
val currentDevSupportManager: DevSupportManager?
5666
get() = reactHost.devSupportManager
5767

@@ -70,9 +80,7 @@ open class MendixReactActivity : ReactActivity(), DevAppMenuHandler, LaunchScree
7080
}
7181

7282
override fun showLaunchScreen() {
73-
if (!MendixBackwardsCompatUtility.getInstance().unsupportedFeatures.hideSplashScreenInClient && splashScreenPresenter != null) {
74-
splashScreenPresenter?.show(this)
75-
}
83+
splashScreenPresenter?.show(this)
7684
}
7785

7886
override fun hideLaunchScreen() {

android/src/main/java/com/mendix/mendixnative/api/RuntimeInfo.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
55
import com.mendix.mendixnative.config.AppUrl
66
import okhttp3.*
77
import okhttp3.MediaType.Companion.toMediaTypeOrNull
8+
import okhttp3.RequestBody.Companion.toRequestBody
89
import java.io.IOException
910
import java.util.concurrent.TimeUnit
1011

@@ -22,10 +23,7 @@ fun getRuntimeInfo(runtimeUrl: String, cb: (info: RuntimeInfoResponse) -> Unit)
2223
client.newCall(
2324
Request.Builder()
2425
.post(
25-
RequestBody.create(
26-
"application/json; charset=utf-8".toMediaTypeOrNull(),
27-
"{\"action\":\"info\"}"
28-
)
26+
"{\"action\":\"info\"}".toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull())
2927
)
3028
.url(AppUrl.removeTrailingSlash(AppUrl.ensureProtocol(runtimeUrl)) + "/xas/")
3129
.build()

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.mendix.mendixnative.fragment
22

33
import android.content.Intent
4+
import android.os.Build
45
import android.os.Bundle
56
import android.view.KeyEvent
67
import com.facebook.react.devsupport.interfaces.DevSupportManager
@@ -9,6 +10,7 @@ import com.mendix.mendixnative.MendixInitializer
910
import com.mendix.mendixnative.activity.LaunchScreenHandler
1011
import com.mendix.mendixnative.react.MendixApp
1112
import com.mendix.mendixnative.util.MendixDoubleTapRecognizer
13+
import java.io.Serializable
1214

1315
/**
1416
* Class used for Sample apps
@@ -54,7 +56,7 @@ open class MendixReactFragment : ReactFragment(), MendixReactFragmentView {
5456
}
5557

5658
if (mendixApp == null) {
57-
mendixApp = requireArguments().getSerializable(ARG_MENDIX_APP) as MendixApp?
59+
mendixApp = getSerializableData(ARG_MENDIX_APP, MendixApp::class.java)
5860
?: throw IllegalArgumentException("Mendix app is required")
5961
}
6062

@@ -73,9 +75,22 @@ open class MendixReactFragment : ReactFragment(), MendixReactFragmentView {
7375
super.onCreate(savedInstanceState)
7476
}
7577

78+
inline fun <reified T : Serializable> getSerializableData(key: String?, clazz: Class<T>): T? {
79+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
80+
requireArguments().getSerializable<T?>(key, clazz)
81+
} else {
82+
@Suppress("DEPRECATION")
83+
val data = requireArguments().getSerializable(key)
84+
if (data is T) {
85+
return data
86+
}
87+
return null
88+
}
89+
}
90+
7691
fun onNewIntent(intent: Intent) {
77-
if (reactNativeHost.hasInstance()) {
78-
reactNativeHost.reactInstanceManager.onNewIntent(intent);
92+
reactHost?.currentReactContext?.let {
93+
it.onNewIntent(it.currentActivity, intent)
7994
}
8095
}
8196

@@ -84,7 +99,7 @@ open class MendixReactFragment : ReactFragment(), MendixReactFragmentView {
8499
super.onDestroy()
85100
}
86101

87-
override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
102+
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
88103
if (keyCode == KeyEvent.KEYCODE_MENU || doubleTapReloadRecognizer.didDoubleTapBacktick(
89104
keyCode,
90105
view
@@ -100,7 +115,7 @@ open class MendixReactFragment : ReactFragment(), MendixReactFragmentView {
100115

101116
override fun showDevAppMenu() {
102117
activity?.let {
103-
currentDevSupportManager?.showDevOptionsDialog();
118+
currentDevSupportManager?.showDevOptionsDialog()
104119
}
105120
}
106121

@@ -109,7 +124,7 @@ open class MendixReactFragment : ReactFragment(), MendixReactFragmentView {
109124
}
110125

111126
interface MendixReactFragmentView : DevAppMenuHandler, BackButtonHandler {
112-
fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean
127+
fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean
113128
}
114129

115130
interface BackButtonHandler {

0 commit comments

Comments
 (0)