@@ -25,62 +25,22 @@ class EdgeToEdgeReactViewGroup(private val reactContext: ThemedReactContext) : R
25
25
private var isNavigationBarTranslucent = false
26
26
private var eventView: ReactViewGroup ? = null
27
27
28
- private fun setupWindowInsets () {
29
- val rootView = reactContext.rootView
30
- if (rootView != null ) {
31
- ViewCompat .setOnApplyWindowInsetsListener(rootView) { v, insets ->
32
- val content =
33
- reactContext.rootView?.findViewById<FitWindowsLinearLayout >(
34
- androidx.appcompat.R .id.action_bar_root,
35
- )
36
- val params = FrameLayout .LayoutParams (
37
- FrameLayout .LayoutParams .MATCH_PARENT ,
38
- FrameLayout .LayoutParams .MATCH_PARENT ,
39
- )
40
-
41
- params.setMargins(
42
- 0 ,
43
- if (this .isStatusBarTranslucent) {
44
- 0
45
- } else {
46
- insets?.getInsets(WindowInsetsCompat .Type .systemBars())?.top
47
- ? : 0
48
- },
49
- 0 ,
50
- if (this .isNavigationBarTranslucent) {
51
- 0
52
- } else {
53
- insets?.getInsets(WindowInsetsCompat .Type .navigationBars())?.bottom
54
- ? : 0
55
- },
56
- )
57
-
58
- content?.layoutParams = params
59
-
60
- insets
61
- }
62
- }
63
- }
64
-
65
28
// region View lifecycles
66
29
override fun onAttachedToWindow () {
67
30
super .onAttachedToWindow()
68
31
69
- Handler (Looper .getMainLooper()).post(this ::setupWindowInsets)
70
- reactContext.currentActivity?.let {
71
- WindowCompat .setDecorFitsSystemWindows(
72
- it.window,
73
- false ,
74
- )
75
- }
76
-
77
32
val activity = reactContext.currentActivity
78
-
79
33
if (activity == null ) {
80
34
Log .w(TAG , " Can not setup keyboard animation listener, since `currentActivity` is null" )
81
35
return
82
36
}
83
37
38
+ Handler (Looper .getMainLooper()).post(this ::setupWindowInsets)
39
+ WindowCompat .setDecorFitsSystemWindows(
40
+ activity.window,
41
+ false ,
42
+ )
43
+
84
44
eventView = ReactViewGroup (context)
85
45
val root = this .getContentView()
86
46
root?.addView(eventView)
@@ -91,27 +51,6 @@ class EdgeToEdgeReactViewGroup(private val reactContext: ThemedReactContext) : R
91
51
deferredInsetTypes = WindowInsetsCompat .Type .ime(),
92
52
dispatchMode = WindowInsetsAnimationCompat .Callback .DISPATCH_MODE_CONTINUE_ON_SUBTREE ,
93
53
context = reactContext,
94
- onApplyWindowInsetsListener = { _, insets ->
95
- val content = this .getContentView()
96
- content?.setPadding(
97
- 0 ,
98
- if (this .isStatusBarTranslucent) {
99
- 0
100
- } else {
101
- insets?.getInsets(WindowInsetsCompat .Type .systemBars())?.top
102
- ? : 0
103
- },
104
- 0 ,
105
- if (this .isNavigationBarTranslucent) {
106
- 0
107
- } else {
108
- insets?.getInsets(WindowInsetsCompat .Type .navigationBars())?.bottom
109
- ? : 0
110
- },
111
- )
112
-
113
- insets
114
- },
115
54
)
116
55
117
56
eventView?.let {
@@ -138,9 +77,45 @@ class EdgeToEdgeReactViewGroup(private val reactContext: ThemedReactContext) : R
138
77
}
139
78
// endregion
140
79
80
+ // region Private functions/class helpers
141
81
private fun getContentView (): FitWindowsLinearLayout ? {
142
82
return reactContext.currentActivity?.window?.decorView?.rootView?.findViewById(
143
- R .id.action_bar_root,
83
+ androidx.appcompat. R .id.action_bar_root,
144
84
)
145
85
}
86
+
87
+ private fun setupWindowInsets () {
88
+ val rootView = reactContext.rootView
89
+ if (rootView != null ) {
90
+ ViewCompat .setOnApplyWindowInsetsListener(rootView) { v, insets ->
91
+ val content = getContentView()
92
+ val params = FrameLayout .LayoutParams (
93
+ FrameLayout .LayoutParams .MATCH_PARENT ,
94
+ FrameLayout .LayoutParams .MATCH_PARENT ,
95
+ )
96
+
97
+ params.setMargins(
98
+ 0 ,
99
+ if (this .isStatusBarTranslucent) {
100
+ 0
101
+ } else {
102
+ insets?.getInsets(WindowInsetsCompat .Type .systemBars())?.top
103
+ ? : 0
104
+ },
105
+ 0 ,
106
+ if (this .isNavigationBarTranslucent) {
107
+ 0
108
+ } else {
109
+ insets?.getInsets(WindowInsetsCompat .Type .navigationBars())?.bottom
110
+ ? : 0
111
+ },
112
+ )
113
+
114
+ content?.layoutParams = params
115
+
116
+ insets
117
+ }
118
+ }
119
+ }
120
+ // endregion
146
121
}
0 commit comments