-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathModalHostLayout.kt
More file actions
78 lines (62 loc) · 2.67 KB
/
ModalHostLayout.kt
File metadata and controls
78 lines (62 loc) · 2.67 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
package com.reactnativenavigation.react.modal
import android.annotation.SuppressLint
import android.annotation.TargetApi
import android.view.View
import android.view.ViewGroup
import android.view.ViewStructure
import android.view.accessibility.AccessibilityEvent
import com.facebook.react.bridge.LifecycleEventListener
import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.UiThreadUtil
import com.facebook.react.uimanager.ThemedReactContext
import com.reactnativenavigation.options.Options
import com.reactnativenavigation.options.params.Bool
import com.reactnativenavigation.utils.CompatUtils
import com.reactnativenavigation.viewcontrollers.viewcontroller.YellowBoxDelegate
import com.reactnativenavigation.viewcontrollers.viewcontroller.overlay.ViewControllerOverlay
import java.util.*
@SuppressLint("ViewConstructor")
open class ModalHostLayout(reactContext: ThemedReactContext) : ViewGroup(reactContext), LifecycleEventListener {
val viewController = ModalLayoutController(
reactContext,
reactContext.currentActivity, CompatUtils.generateViewId().toString(),
YellowBoxDelegate(reactContext), Options().apply {
hardwareBack.dismissModalOnPress = Bool(false)
}, ViewControllerOverlay(reactContext),
getHostId = { this.id }
)
private val mHostView = viewController.view.modalContentLayout
init {
(context as ReactContext).addLifecycleEventListener(this)
}
@TargetApi(23)
override fun dispatchProvideStructure(structure: ViewStructure?) {
structure?.let { mHostView.dispatchProvideStructure(it) }
}
override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {}
override fun addView(child: View?, index: Int) {
UiThreadUtil.assertOnUiThread()
mHostView.addView(child, index)
}
override fun getChildCount(): Int {
return mHostView.childCount
}
override fun getChildAt(index: Int): View? {
return mHostView.getChildAt(index)
}
override fun removeView(child: View?) {
UiThreadUtil.assertOnUiThread()
mHostView.removeView(child)
}
override fun removeViewAt(index: Int) {
UiThreadUtil.assertOnUiThread()
val child = getChildAt(index)
mHostView.removeView(child)
}
override fun addChildrenForAccessibility(outChildren: ArrayList<View?>?) {}
override fun dispatchPopulateAccessibilityEvent(event: AccessibilityEvent?): Boolean { return false }
open fun onDropInstance() { (this.context as ReactContext).removeLifecycleEventListener(this) }
override fun onHostResume() {}
override fun onHostPause() {}
override fun onHostDestroy() { onDropInstance() }
}