DebugDrawer
DebugDrawer copied to clipboard
android:windowTranslucentStatus not working
Hi,
android:windowTranslucentStatus
is not working when debug drawer attached to activity.
What is the reason for this? How to solve this?
Not just that. Also other style configurations with non-standard status bar. The DrawerLayout
injected at the root of the hierarchy is a bit intrusive and overrides some parameters. I would prefer some less intrusive method like a sticky notification. Right-side sliding is used by quite many apps.
Did anyone forked the project and make it work with transparent/translucent status bar? It took me a couple of hours before I realized that this library was interfering with my app to show a transparent status bar.
The problem is that their DrawerLayout consume window insets and they don't get passed on to the actual content.
I just leave this here:
DebugDrawer.Builder(activity)
.modules(
BuildModule(),
DeviceModule(),
TimberModule(),
SettingsModule()
).build()
// DebugDrawer breaks translucent status bar on Common onboarding screen. They
// internally use [ScrimInsetsFrameLayout] which consumes insets. Make sure insets
// get passed to children as well.
val content: ViewGroup? = activity.findViewById(R.id.dd_content_layout) as? ViewGroup
val parent: ViewGroup? = content?.parent as? ViewGroup
content?.redispatchWindowInsetsToAllChildren()
parent?.redispatchWindowInsetsToAllChildren()
/**
* Fixes a problem with fitsSystemWindows where only the first view in viewHierarchy has a chance
* to offset itself away from Status and Navigation bars. Typically when a view is defined
* to fitsSystemWindows, it consumes those offsets, leaving no offsets for other views.
* Listen for dispatch of WindowInsets and redispatch the offsets to all children. Even if the first
* child consumes offsets, other children get the original offsets and can react accordingly as well.
*/
fun ViewGroup.redispatchWindowInsetsToAllChildren() {
ViewCompat.setOnApplyWindowInsetsListener(this) { view, insets ->
var consumed = false
val parent = view as ViewGroup
for (i in 0 until parent.childCount) {
val child = parent.getChildAt(i)
// Dispatch the insets to the child
val childResult = ViewCompat.dispatchApplyWindowInsets(child, insets)
// If the child consumed the insets, record it
if (childResult.isConsumed) {
consumed = true
}
}
// If any of the children consumed the insets, return an appropriate value
if (consumed) insets.consumeSystemWindowInsets() else insets
}
}
This fixes the problem where status bar and navigation bar are not transparent. But the drawer's content is now also drawn behind the status and navigation bars, which is okay with me.