Skip to content

Commit 9a8114c

Browse files
refactor: remove unused imports and clean up touch event handling in Mendix components
1 parent 7335246 commit 9a8114c

3 files changed

Lines changed: 9 additions & 53 deletions

File tree

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

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

33
import android.app.Activity
4-
import android.view.MotionEvent
54
import com.facebook.react.ReactHost
6-
import com.facebook.react.common.ShakeDetector
75
import com.facebook.react.devsupport.DevSupportManagerBase
8-
import com.facebook.react.devsupport.attachMendixSupportManagerShakeDetector
9-
import com.facebook.react.devsupport.makeShakeDetector
106
import com.facebook.react.modules.network.OkHttpClientProvider
117
import com.mendix.mendixnative.config.AppPreferences
12-
import com.mendix.mendixnative.handler.DevMenuTouchEventHandler
138
import com.mendix.mendixnative.react.*
149
import com.mendix.mendixnative.request.MendixNetworkInterceptor
1510
import com.mendix.mendixnative.util.CookieEncryption
@@ -23,8 +18,6 @@ class MendixInitializer(
2318
private val reactHost: ReactHost,
2419
private val hasRNDeveloperSupport: Boolean = false,
2520
) {
26-
private var shakeDetector: ShakeDetector? = null
27-
private var devMenuTouchEventHandler: DevMenuTouchEventHandler? = null
2821

2922
fun onCreate(mendixApp: MendixApp, clearData: Boolean) {
3023
// Assign mendix xas id interceptor to okhttp
@@ -41,17 +34,15 @@ class MendixInitializer(
4134
MxConfiguration.runtimeUrl = runtimeUrl
4235
MxConfiguration.warningsFilter = mendixApp.warningsFilter
4336

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)
37+
// Reload only if there's already a running instance.
38+
if (reactHost.currentReactContext != null) {
39+
reactHost.reload("Clean start for new Mendix app")
40+
}
4741
if (clearData) clearData(context.application)
4842
if (hasRNDeveloperSupport) setupDeveloperApp(runtimeUrl, mendixApp)
4943
}
5044

5145
fun onDestroy() {
52-
// Stop shaking as early as possible to avoid orphaned dialogs
53-
stopShakeDetector()
54-
5546
if (hasRNDeveloperSupport) {
5647
AppPreferences(context.applicationContext).setElementInspector(false)
5748
}
@@ -64,26 +55,6 @@ class MendixInitializer(
6455
closeSqlDatabaseConnection(reactHost.currentReactContext)
6556
}
6657

67-
fun stopShakeDetector() {
68-
shakeDetector?.stop()
69-
}
70-
71-
fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
72-
return devMenuTouchEventHandler?.handle(ev) ?: false
73-
}
74-
75-
private fun attachShakeDetector(devAppMenuHandler: DevAppMenuHandler) {
76-
if (shakeDetector == null) {
77-
shakeDetector = makeShakeDetector(context.applicationContext) {
78-
devAppMenuHandler.showDevAppMenu()
79-
}
80-
}
81-
82-
(reactHost.devSupportManager as? DevSupportManagerBase)?.run {
83-
attachMendixSupportManagerShakeDetector(shakeDetector!!, this)
84-
}
85-
}
86-
8758
private fun setupDeveloperApp(
8859
runtimeUrl: String,
8960
mendixApp: MendixApp

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.mendix.mendixnative.activity
22

33
import android.os.Bundle
44
import android.view.KeyEvent
5-
import android.view.MotionEvent
65
import com.facebook.react.ReactActivity
76
import com.facebook.react.ReactActivityDelegate
87
import com.facebook.react.bridge.ReactContext
@@ -42,12 +41,6 @@ open class MendixReactActivity : ReactActivity(), DevAppMenuHandler, LaunchScree
4241
super.onDestroy()
4342
}
4443

45-
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
46-
return if (mendixInitializer.dispatchTouchEvent(ev)) {
47-
true
48-
} else super.dispatchTouchEvent(ev)
49-
}
50-
5144
override fun getMainComponentName(): String? {
5245
return MAIN_COMPONENT_NAME
5346
}
@@ -65,7 +58,7 @@ open class MendixReactActivity : ReactActivity(), DevAppMenuHandler, LaunchScree
6558
override fun createReactActivityDelegate(): ReactActivityDelegate {
6659
return object : ReactActivityDelegate(this, mainComponentName) {
6760
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
68-
if (keyCode == KeyEvent.KEYCODE_MENU) {
61+
if (mendixApp?.showExtendedDevMenu == true && keyCode == KeyEvent.KEYCODE_MENU) {
6962
showDevAppMenu()
7063
return true
7164
}

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.mendix.mendixnative.fragment
33
import android.content.Intent
44
import android.os.Bundle
55
import android.view.KeyEvent
6-
import android.view.MotionEvent
76
import com.facebook.react.devsupport.interfaces.DevSupportManager
87
import com.mendix.mendixnative.DevAppMenuHandler
98
import com.mendix.mendixnative.MendixInitializer
@@ -86,6 +85,9 @@ open class MendixReactFragment : ReactFragment(), MendixReactFragmentView {
8685
}
8786

8887
override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
88+
if (mendixApp?.showExtendedDevMenu != true) {
89+
return false
90+
}
8991
if (keyCode == KeyEvent.KEYCODE_MENU || doubleTapReloadRecognizer.didDoubleTapBacktick(
9092
keyCode,
9193
view
@@ -104,23 +106,13 @@ open class MendixReactFragment : ReactFragment(), MendixReactFragmentView {
104106
}
105107

106108
open fun onCloseProjectSelected() {
107-
// Closing shake detection to avoid dialog from triggering while closing
108-
mendixInitializer.stopShakeDetector();
109-
}
110-
111-
override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
112-
return mendixInitializer.dispatchTouchEvent(ev)
113109
}
114110
}
115111

116-
interface MendixReactFragmentView : DevAppMenuHandler, TouchEventDispatcher, BackButtonHandler {
112+
interface MendixReactFragmentView : DevAppMenuHandler, BackButtonHandler {
117113
fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean
118114
}
119115

120-
interface TouchEventDispatcher {
121-
fun dispatchTouchEvent(ev: MotionEvent?): Boolean
122-
}
123-
124116
interface BackButtonHandler {
125117
fun onBackPressed(): Boolean
126118
}

0 commit comments

Comments
 (0)