Skip to content

Commit 754b185

Browse files
committed
refactor: changes after rebase
1 parent 1da87e0 commit 754b185

File tree

1 file changed

+43
-68
lines changed

1 file changed

+43
-68
lines changed

android/src/main/java/com/reactnativekeyboardcontroller/views/EdgeToEdgeReactViewGroup.kt

Lines changed: 43 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -25,62 +25,22 @@ class EdgeToEdgeReactViewGroup(private val reactContext: ThemedReactContext) : R
2525
private var isNavigationBarTranslucent = false
2626
private var eventView: ReactViewGroup? = null
2727

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-
6528
// region View lifecycles
6629
override fun onAttachedToWindow() {
6730
super.onAttachedToWindow()
6831

69-
Handler(Looper.getMainLooper()).post(this::setupWindowInsets)
70-
reactContext.currentActivity?.let {
71-
WindowCompat.setDecorFitsSystemWindows(
72-
it.window,
73-
false,
74-
)
75-
}
76-
7732
val activity = reactContext.currentActivity
78-
7933
if (activity == null) {
8034
Log.w(TAG, "Can not setup keyboard animation listener, since `currentActivity` is null")
8135
return
8236
}
8337

38+
Handler(Looper.getMainLooper()).post(this::setupWindowInsets)
39+
WindowCompat.setDecorFitsSystemWindows(
40+
activity.window,
41+
false,
42+
)
43+
8444
eventView = ReactViewGroup(context)
8545
val root = this.getContentView()
8646
root?.addView(eventView)
@@ -91,27 +51,6 @@ class EdgeToEdgeReactViewGroup(private val reactContext: ThemedReactContext) : R
9151
deferredInsetTypes = WindowInsetsCompat.Type.ime(),
9252
dispatchMode = WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE,
9353
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-
},
11554
)
11655

11756
eventView?.let {
@@ -138,9 +77,45 @@ class EdgeToEdgeReactViewGroup(private val reactContext: ThemedReactContext) : R
13877
}
13978
// endregion
14079

80+
// region Private functions/class helpers
14181
private fun getContentView(): FitWindowsLinearLayout? {
14282
return reactContext.currentActivity?.window?.decorView?.rootView?.findViewById(
143-
R.id.action_bar_root,
83+
androidx.appcompat.R.id.action_bar_root,
14484
)
14585
}
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
146121
}

0 commit comments

Comments
 (0)