Skip to content

Commit e2f48cc

Browse files
refactor: remove outdated code
1 parent 3697e3d commit e2f48cc

6 files changed

Lines changed: 167 additions & 51 deletions

File tree

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

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

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

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

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ class MendixInitializer(
4141
MxConfiguration.runtimeUrl = runtimeUrl
4242
MxConfiguration.warningsFilter = mendixApp.warningsFilter
4343

44-
// This is here to make sure that a clean host instance is initialised.
45-
reactHost.invalidate()
44+
// Destroy any existing ReactInstance so we start fresh, but do NOT invalidate —
45+
// invalidate() is terminal in bridgeless mode and prevents the host from ever being reused.
46+
reactHost.destroy("Clean start for new Mendix app", null)
4647
if (clearData) clearData(context.application)
4748
if (hasRNDeveloperSupport) setupDeveloperApp(runtimeUrl, mendixApp)
4849
}
@@ -54,7 +55,9 @@ class MendixInitializer(
5455
if (hasRNDeveloperSupport) {
5556
AppPreferences(context.applicationContext).setElementInspector(false)
5657
}
57-
reactHost.invalidate()
58+
// Destroy the current instance but keep the host reusable — invalidate() is terminal
59+
// in bridgeless mode and would prevent the host from ever starting a new instance.
60+
reactHost.destroy("MendixInitializer.onDestroy()", null)
5861

5962
// We need to close all databases separately to avoid hitting a read only state exception
6063
// Databases need to close after we are done closing the react native host to avoid db locks

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.facebook.react.common.annotations.UnstableReactNativeAPI
1010
import com.facebook.react.defaults.DefaultComponentsRegistry
1111
import com.facebook.react.defaults.DefaultReactHostDelegate
1212
import com.facebook.react.defaults.DefaultTurboModuleManagerDelegate
13+
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener
1314
import com.facebook.react.devsupport.interfaces.RedBoxHandler
1415
import com.facebook.react.fabric.ComponentFactory
1516
import com.facebook.react.runtime.ReactHostImpl
@@ -20,6 +21,7 @@ import com.mendix.mendixnative.error.ErrorHandler
2021
import com.mendix.mendixnative.error.ErrorHandlerFactory
2122
import com.mendix.mendixnative.error.mapErrorHandlerToRedBox
2223
import com.mendix.mendixnative.handler.DummyErrorHandler
24+
import com.mendix.mendixnative.devsupport.MendixDevSupportManagerFactory
2325
import com.mendix.mendixnative.react.ota.OtaJSBundleUrlProvider
2426
import com.mendix.mendixnative.react.splash.MendixSplashScreenPresenter
2527
import com.mendixnative.MendixNativePackage
@@ -106,11 +108,12 @@ abstract class MendixReactApplication : Application(), MendixApplication, ErrorH
106108
val componentFactory = ComponentFactory()
107109
DefaultComponentsRegistry.register(componentFactory)
108110
ReactHostImpl(
109-
applicationContext,
110-
delegate,
111-
componentFactory,
112-
true /* allowPackagerServerAccess */,
113-
useDeveloperSupport,
111+
context = applicationContext,
112+
reactHostDelegate = delegate,
113+
componentFactory = componentFactory,
114+
allowPackagerServerAccess = true,
115+
useDevSupport = useDeveloperSupport,
116+
devSupportManagerFactory = MendixDevSupportManagerFactory(devBundleDownloadListener),
114117
)
115118
}
116119

@@ -158,4 +161,14 @@ abstract class MendixReactApplication : Application(), MendixApplication, ErrorH
158161

159162
open val jsBundleProvider: JSBundleFileProvider?
160163
get() = null
164+
165+
/**
166+
* Override this to provide a [DevBundleDownloadListener] that receives bundle download
167+
* progress, success, and failure callbacks. This is used to drive custom loading UIs.
168+
*
169+
* The listener is injected at [ReactHost] creation time via [MendixDevSupportManagerFactory].
170+
* Use a delegating holder pattern if the actual listener is created after app initialization.
171+
*/
172+
open val devBundleDownloadListener: DevBundleDownloadListener?
173+
get() = null
161174
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.mendix.mendixnative.devsupport
2+
3+
import android.content.Context
4+
import com.facebook.react.bridge.UiThreadUtil
5+
import com.facebook.react.common.SurfaceDelegateFactory
6+
import com.facebook.react.devsupport.DevSupportManagerBase
7+
import com.facebook.react.devsupport.ReactInstanceDevHelper
8+
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener
9+
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager
10+
import com.facebook.react.devsupport.interfaces.PausedInDebuggerOverlayManager
11+
import com.facebook.react.devsupport.interfaces.RedBoxHandler
12+
import com.facebook.react.packagerconnection.RequestHandler
13+
14+
/**
15+
* A public DevSupportManager implementation for Mendix apps in bridgeless mode.
16+
*
17+
* This mirrors the behavior of React Native's internal [BridgelessDevSupportManager]
18+
* but is accessible from external modules, allowing us to inject a custom
19+
* [DevBundleDownloadListener] at construction time without reflection.
20+
*/
21+
class MendixBridgelessDevSupportManager(
22+
applicationContext: Context,
23+
reactInstanceManagerHelper: ReactInstanceDevHelper,
24+
packagerPathForJSBundleName: String?,
25+
enableOnCreate: Boolean,
26+
redBoxHandler: RedBoxHandler?,
27+
devBundleDownloadListener: DevBundleDownloadListener?,
28+
minNumShakes: Int,
29+
customPackagerCommandHandlers: Map<String, RequestHandler>?,
30+
surfaceDelegateFactory: SurfaceDelegateFactory?,
31+
devLoadingViewManager: DevLoadingViewManager?,
32+
pausedInDebuggerOverlayManager: PausedInDebuggerOverlayManager?,
33+
) : DevSupportManagerBase(
34+
applicationContext,
35+
reactInstanceManagerHelper,
36+
packagerPathForJSBundleName,
37+
enableOnCreate,
38+
redBoxHandler,
39+
devBundleDownloadListener,
40+
minNumShakes,
41+
customPackagerCommandHandlers,
42+
surfaceDelegateFactory,
43+
devLoadingViewManager,
44+
pausedInDebuggerOverlayManager,
45+
) {
46+
override val uniqueTag: String get() = "MendixBridgeless"
47+
48+
override fun handleReloadJS() {
49+
UiThreadUtil.assertOnUiThread()
50+
hideRedboxDialog()
51+
reactInstanceDevHelper.reload("MendixBridgelessDevSupportManager.handleReloadJS()")
52+
}
53+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package com.mendix.mendixnative.devsupport
2+
3+
import android.content.Context
4+
import com.facebook.react.common.SurfaceDelegateFactory
5+
import com.facebook.react.devsupport.DevSupportManagerFactory
6+
import com.facebook.react.devsupport.ReactInstanceDevHelper
7+
import com.facebook.react.devsupport.ReleaseDevSupportManager
8+
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener
9+
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager
10+
import com.facebook.react.devsupport.interfaces.DevSupportManager
11+
import com.facebook.react.devsupport.interfaces.PausedInDebuggerOverlayManager
12+
import com.facebook.react.devsupport.interfaces.RedBoxHandler
13+
import com.facebook.react.packagerconnection.RequestHandler
14+
15+
/**
16+
* A [DevSupportManagerFactory] that creates [MendixBridgelessDevSupportManager] instances
17+
* with a custom [DevBundleDownloadListener] injected at construction time.
18+
*
19+
* This replaces the need for reflection-based listener injection.
20+
*/
21+
class MendixDevSupportManagerFactory(
22+
private val devBundleDownloadListener: DevBundleDownloadListener?,
23+
) : DevSupportManagerFactory {
24+
25+
@Deprecated("Use the create() overload with useDevSupport parameter for New Architecture.")
26+
override fun create(
27+
applicationContext: Context,
28+
reactInstanceManagerHelper: ReactInstanceDevHelper,
29+
packagerPathForJSBundleName: String?,
30+
enableOnCreate: Boolean,
31+
redBoxHandler: RedBoxHandler?,
32+
devBundleDownloadListener: DevBundleDownloadListener?,
33+
minNumShakes: Int,
34+
customPackagerCommandHandlers: Map<String, RequestHandler>?,
35+
surfaceDelegateFactory: SurfaceDelegateFactory?,
36+
devLoadingViewManager: DevLoadingViewManager?,
37+
pausedInDebuggerOverlayManager: PausedInDebuggerOverlayManager?,
38+
): DevSupportManager {
39+
return if (!enableOnCreate) {
40+
ReleaseDevSupportManager()
41+
} else {
42+
MendixBridgelessDevSupportManager(
43+
applicationContext,
44+
reactInstanceManagerHelper,
45+
packagerPathForJSBundleName,
46+
enableOnCreate,
47+
redBoxHandler,
48+
this.devBundleDownloadListener,
49+
minNumShakes,
50+
customPackagerCommandHandlers,
51+
surfaceDelegateFactory,
52+
devLoadingViewManager,
53+
pausedInDebuggerOverlayManager,
54+
)
55+
}
56+
}
57+
58+
override fun create(
59+
applicationContext: Context,
60+
reactInstanceManagerHelper: ReactInstanceDevHelper,
61+
packagerPathForJSBundleName: String?,
62+
enableOnCreate: Boolean,
63+
redBoxHandler: RedBoxHandler?,
64+
devBundleDownloadListener: DevBundleDownloadListener?,
65+
minNumShakes: Int,
66+
customPackagerCommandHandlers: Map<String, RequestHandler>?,
67+
surfaceDelegateFactory: SurfaceDelegateFactory?,
68+
devLoadingViewManager: DevLoadingViewManager?,
69+
pausedInDebuggerOverlayManager: PausedInDebuggerOverlayManager?,
70+
useDevSupport: Boolean,
71+
): DevSupportManager {
72+
return if (useDevSupport) {
73+
MendixBridgelessDevSupportManager(
74+
applicationContext,
75+
reactInstanceManagerHelper,
76+
packagerPathForJSBundleName,
77+
enableOnCreate,
78+
redBoxHandler,
79+
this.devBundleDownloadListener, // Our injected listener, ignoring the null passed by ReactHostImpl
80+
minNumShakes,
81+
customPackagerCommandHandlers,
82+
surfaceDelegateFactory,
83+
devLoadingViewManager,
84+
pausedInDebuggerOverlayManager,
85+
)
86+
} else {
87+
ReleaseDevSupportManager()
88+
}
89+
}
90+
}

0 commit comments

Comments
 (0)