Skip to content

Commit 5d72eb6

Browse files
committed
support for older Android versions
1 parent 4440547 commit 5d72eb6

File tree

1 file changed

+23
-0
lines changed
  • android/src/main/java/com/swmansion/rnscreens/gamma/tabs

1 file changed

+23
-0
lines changed

android/src/main/java/com/swmansion/rnscreens/gamma/tabs/TabsHost.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package com.swmansion.rnscreens.gamma.tabs
22

33
import android.content.res.Configuration
4+
import android.os.Build
45
import android.view.Choreographer
56
import android.view.Gravity
67
import android.view.MenuItem
78
import android.view.View
9+
import android.view.WindowInsets
810
import android.widget.FrameLayout
911
import androidx.appcompat.view.ContextThemeWrapper
12+
import androidx.core.view.children
1013
import androidx.fragment.app.FragmentManager
1114
import com.facebook.react.modules.core.ReactChoreographer
1215
import com.facebook.react.uimanager.ThemedReactContext
@@ -444,6 +447,26 @@ class TabsHost(
444447
override fun getInterfaceInsets(): EdgeInsets =
445448
EdgeInsets(0.0f, 0.0f, (bottomNavigationView.bottom - bottomNavigationView.top).toFloat(), 0.0f)
446449

450+
override fun dispatchApplyWindowInsets(insets: WindowInsets?): WindowInsets? {
451+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
452+
return super.dispatchApplyWindowInsets(insets)
453+
}
454+
455+
// On Android versions prior to R, insets dispatch is broken.
456+
// In order to mitigate this, we override dispatchApplyWindowInsets with
457+
// correct implementation. To simplify it, we skip the call to TabsHost's
458+
// onApplyWindowInsets.
459+
if (insets?.isConsumed ?: true) {
460+
return insets
461+
}
462+
463+
for (child in children) {
464+
child.dispatchApplyWindowInsets(insets)
465+
}
466+
467+
return insets
468+
}
469+
447470
internal fun onViewManagerAddEventEmitters() {
448471
// When this is called from View Manager the view tag is already set
449472
check(id != NO_ID) { "[RNScreens] TabsHost must have its tag set when registering event emitters" }

0 commit comments

Comments
 (0)