appandflow / appandflow/react-native-safe-area-context

returning inset bottom on samsung S8 even with edge-to-edge hidden nav bar

Abierto
#555 1 comentario 2 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
TypeScript
Estrellas
2.8k
Forks
258
Merge medio
3 d 1 h
PR fusionados (30 d)
2

Descripción

i'm using expo 52 and edge-to-edge support and when i tested on my samsung galaxy s8, the navigation bar is hidden but the inset is wrong.

![388208896-83a72475-5420-48ea-8e63-be5b6ef2a3c1 (1)](https://github.com/user-attachments/assets/02636d47-7a1d-4249-b48a-724c3d70dbf4)

the value should be zero since the nav is hidden but it's 144.

```kotlin

fun getSafeAreaInsets(view: View): EdgeInsets? {
// The view has not been layout yet.
if (view.height == 0) {
return null
}
val rootView = view.rootView
val windowInsets = getRootWindowInsetsCompat(rootView) ?: return null

// Calculate the part of the view that overlaps with window insets.
val windowWidth = rootView.width.toFloat()
val windowHeight = rootView.height.toFloat()
val visibleRect = android.graphics.Rect()
view.getGlobalVisibleRect(visibleRect)
Log.d(
"DebugTag", // Replace with your desired tag
"Computed values: top=${visibleRect.top}, height=${view.height}, " +
"windowHeight=$windowHeight, insetsBottom=${windowInsets.bottom}, " +
"result=${max(min(visibleRect.top + view.height - windowHeight, 0f) + windowInsets.bottom, 0f)}"
)
return EdgeInsets(
top = max(windowInsets.top - visibleRect.top, 0f),
right = max(min(visibleRect.left + view.width - windowWidth, 0f) + windowInsets.right, 0f),
bottom = max(min(visibleRect.top + view.height - windowHeight, 0f) + windowInsets.bottom, 0f),
left = max(windowInsets.left - visibleRect.left, 0f))
}
```

```
Computed values: top=0, height=2220, windowHeight=2220.0, insetsBottom=144.0, result=144.0
```

trying to understand a bit, `getRootWindowInsetsCompatM` seems to be the function used to get the insets on my samsung.

insets in `getRootWindowInsetsCompatM` uses `rootView.rootWindowInsets` which returns:

```
// without navigation bar showing
API Level: WindowInsets{systemWindowInsets=Rect(0, 72 - 0, 144) windowDecorInsets=Rect(0, 0 - 0, 0) stableInsets=Rect(0, 72 - 0, 144)}
```

i try to reactivate the navigationBar to see what was logged and it looks like it gets the same values :/

```
// with navigation bar showing
API Level: WindowInsets{systemWindowInsets=Rect(0, 72 - 0, 144) windowDecorInsets=Rect(0, 0 - 0, 0) stableInsets=Rect(0, 72 - 0, 144)}
```

issue also seems to be that the code below return true even when the navigation bar is hidden :/

```rootWindowInsets?.isVisible(WindowInsetsCompat.Type.navigationBars())```

what i maybe found so far but need `activity` is something like this [https://stackoverflow.com/questions/51317263/how-to-know-when-samsung-s8-s8-s9-ect-bottom-navigation-bar-is-visible](https://stackoverflow.com/questions/51317263/how-to-know-when-samsung-s8-s8-s9-ect-bottom-navigation-bar-is-visible)

if you want me to test a specific code to replace the `rootView.rootWindowInsets` and see if it returns the right value, happy to help

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.