Skip to content

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

Open
@wcastand

Description

@wcastand

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)

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

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions