Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion android/src/main/java/com/swmansion/rnscreens/CustomToolbar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.Choreographer
import android.view.WindowInsets
import android.view.WindowManager
import androidx.appcompat.widget.Toolbar
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.facebook.react.modules.core.ReactChoreographer
import com.facebook.react.uimanager.ThemedReactContext
Expand Down Expand Up @@ -125,7 +126,20 @@ open class CustomToolbar(
val topInset = getDecorViewTopInset(decorView)

if (topInset > 0) {
applyExactPadding(paddingLeft, topInset, paddingRight, paddingBottom)
// In legacy (non edge-to-edge) mode, the system already positions the toolbar
// below the status bar, so applying paddingTop would cause double offset.
// We detect this by comparing toolbar's position on screen with the status bar inset:
// in edge-to-edge the toolbar starts at y=0, in legacy it starts at y=statusBarInset.
val insetsCompat = ViewCompat.getRootWindowInsets(decorView)
val statusBarInset = insetsCompat?.getInsets(WindowInsetsCompat.Type.statusBars())?.top ?: 0
val locationOnScreen = IntArray(2)
getLocationOnScreen(locationOnScreen)
val toolbarTopOnScreen = locationOnScreen[1]
val isEdgeToEdge = toolbarTopOnScreen < statusBarInset

if (isEdgeToEdge) {
applyExactPadding(paddingLeft, topInset, paddingRight, paddingBottom)
}
}
}

Expand Down