fix older android versions
This commit is contained in:
+8
-3
@@ -38,9 +38,13 @@ class BottomSheetView(
|
|||||||
private var lastObservedContentHeight: Float = 0f
|
private var lastObservedContentHeight: Float = 0f
|
||||||
private var pendingLayoutUpdate: Boolean = false
|
private var pendingLayoutUpdate: Boolean = false
|
||||||
|
|
||||||
private val screenHeight =
|
private val screenHeight: Float =
|
||||||
context.resources.displayMetrics.heightPixels
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
||||||
.toFloat()
|
context.resources.displayMetrics.heightPixels.toFloat()
|
||||||
|
} else {
|
||||||
|
val wm = context.getSystemService(Context.WINDOW_SERVICE) as android.view.WindowManager
|
||||||
|
wm.currentWindowMetrics.bounds.height().toFloat()
|
||||||
|
}
|
||||||
|
|
||||||
private fun getNavigationBarHeight(): Int {
|
private fun getNavigationBarHeight(): Int {
|
||||||
val resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android")
|
val resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android")
|
||||||
@@ -203,6 +207,7 @@ class BottomSheetView(
|
|||||||
val bottomSheet = dialog.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)
|
val bottomSheet = dialog.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)
|
||||||
bottomSheet?.let {
|
bottomSheet?.let {
|
||||||
it.setBackgroundColor(0)
|
it.setBackgroundColor(0)
|
||||||
|
it.elevation = 0f
|
||||||
|
|
||||||
val behavior = BottomSheetBehavior.from(it)
|
val behavior = BottomSheetBehavior.from(it)
|
||||||
behavior.state = BottomSheetBehavior.STATE_HIDDEN
|
behavior.state = BottomSheetBehavior.STATE_HIDDEN
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<style name="EdgeToEdgeBottomSheetDialogTheme" parent="Theme.Material3.DayNight.BottomSheetDialog">
|
<style name="EdgeToEdgeBottomSheetDialogTheme" parent="ThemeOverlay.Material3.DayNight.BottomSheetDialog">
|
||||||
<!-- Enable edge-to-edge -->
|
<!-- Enable edge-to-edge, matching react-native-edge-to-edge's setup -->
|
||||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||||
<item name="android:windowIsFloating">false</item>
|
<item name="android:windowIsFloating">false</item>
|
||||||
|
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
|
||||||
|
<item name="android:fitsSystemWindows">false</item>
|
||||||
<item name="enableEdgeToEdge">true</item>
|
<item name="enableEdgeToEdge">true</item>
|
||||||
|
|
||||||
<!-- Configure bottom sheet to respect system window insets -->
|
<!-- Configure bottom sheet to respect system window insets -->
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ const IS_IOS15 =
|
|||||||
Platform.OS === 'ios' &&
|
Platform.OS === 'ios' &&
|
||||||
// semvar - can be 3 segments, so can't use Number(Platform.Version)
|
// semvar - can be 3 segments, so can't use Number(Platform.Version)
|
||||||
Number(Platform.Version.split('.').at(0)) < 16
|
Number(Platform.Version.split('.').at(0)) < 16
|
||||||
|
// older android versions (15 and below) aren't naturally edge-to-edge
|
||||||
|
// and behave a little differently
|
||||||
|
const IS_NON_E2E_ANDROID =
|
||||||
|
Platform.OS === 'android' && Number(Platform.Version) < 35
|
||||||
|
|
||||||
export class BottomSheetNativeComponent extends React.Component<
|
export class BottomSheetNativeComponent extends React.Component<
|
||||||
BottomSheetViewProps,
|
BottomSheetViewProps,
|
||||||
@@ -142,6 +146,13 @@ function BottomSheetNativeComponentInner({
|
|||||||
const cornerRadius = rest.cornerRadius ?? 0
|
const cornerRadius = rest.cornerRadius ?? 0
|
||||||
const {height: screenHeight} = useWindowDimensions()
|
const {height: screenHeight} = useWindowDimensions()
|
||||||
|
|
||||||
|
// sigh... on older Android versions, screenHeight does not include safe area insets
|
||||||
|
// on newer Androids + iOS, it does. we need to find the inner bit + the bottom inset
|
||||||
|
// for the sheet content
|
||||||
|
const sheetHeight = IS_NON_E2E_ANDROID
|
||||||
|
? screenHeight + insets.bottom
|
||||||
|
: screenHeight - insets.top
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NativeView
|
<NativeView
|
||||||
{...rest}
|
{...rest}
|
||||||
@@ -149,7 +160,7 @@ function BottomSheetNativeComponentInner({
|
|||||||
ref={nativeViewRef}
|
ref={nativeViewRef}
|
||||||
style={{
|
style={{
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
height: screenHeight - insets.top,
|
height: sheetHeight,
|
||||||
width: '100%',
|
width: '100%',
|
||||||
}}
|
}}
|
||||||
containerBackgroundColor={backgroundColor}>
|
containerBackgroundColor={backgroundColor}>
|
||||||
|
|||||||
Reference in New Issue
Block a user