-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMendixReactActivity.kt
More file actions
95 lines (77 loc) · 3.01 KB
/
Copy pathMendixReactActivity.kt
File metadata and controls
95 lines (77 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.mendix.mendixnative.activity
import android.os.Bundle
import android.view.KeyEvent
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.bridge.ReactContext
import com.facebook.react.devsupport.interfaces.DevSupportManager
import com.mendix.mendixnative.DevAppMenuHandler
import com.mendix.mendixnative.MendixApplication
import com.mendix.mendixnative.MendixInitializer
import com.mendix.mendixnative.react.MendixApp
import com.mendix.mendixnative.react.splash.MendixSplashScreenPresenter
import com.mendix.mendixnative.util.MendixBackwardsCompatUtility
open class MendixReactActivity : ReactActivity(), DevAppMenuHandler, LaunchScreenHandler {
@JvmField
protected var mendixApp: MendixApp? = null
private lateinit var mendixInitializer: MendixInitializer
private var splashScreenPresenter: MendixSplashScreenPresenter? =
(application as? MendixApplication)?.createSplashScreenPresenter()
override fun onCreate(savedInstanceState: Bundle?) {
mendixApp = mendixApp
?: intent.getSerializableExtra(MENDIX_APP_INTENT_KEY) as? MendixApp
?: throw IllegalStateException("MendixApp configuration can't be null")
val mendixApplication = application as? MendixApplication
?: throw ClassCastException("Application needs to implement MendixApplication")
mendixInitializer =
MendixInitializer(this, reactHost, mendixApplication.useDeveloperSupport)
mendixInitializer.onCreate(mendixApp!!, intent.getBooleanExtra(CLEAR_DATA, false))
super.onCreate(null)
}
override fun onDestroy() {
mendixInitializer.onDestroy()
super.onDestroy()
}
override fun getMainComponentName(): String? {
return MAIN_COMPONENT_NAME
}
override fun showDevAppMenu() {
currentDevSupportManager?.showDevOptionsDialog();
}
private val currentReactContext: ReactContext?
get() = reactHost.currentReactContext
val currentDevSupportManager: DevSupportManager?
get() = reactHost.devSupportManager
override fun createReactActivityDelegate(): ReactActivityDelegate {
return object : ReactActivityDelegate(this, mainComponentName) {
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
if (keyCode == KeyEvent.KEYCODE_MENU) {
if (mendixApp?.showExtendedDevMenu == true) {
showDevAppMenu()
}
return true
}
return super.onKeyUp(keyCode, event)
}
}
}
override fun showLaunchScreen() {
if (!MendixBackwardsCompatUtility.getInstance().unsupportedFeatures.hideSplashScreenInClient && splashScreenPresenter != null) {
splashScreenPresenter?.show(this)
}
}
override fun hideLaunchScreen() {
if (splashScreenPresenter != null) {
splashScreenPresenter?.hide(this)
}
}
companion object {
const val MAIN_COMPONENT_NAME = "App"
const val MENDIX_APP_INTENT_KEY = "mendixAppIntentKey"
const val CLEAR_DATA = "clearData"
}
}
interface LaunchScreenHandler {
fun showLaunchScreen()
fun hideLaunchScreen()
}