Created
December 2, 2019 10:03
-
-
Save hector6872/ec8afd0ac2508b35ed6ea25f8deebac3 to your computer and use it in GitHub Desktop.
A fragment container enabling the use of android:fitsSystemWindows in fragment layouts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WindowInsetsFrameLayout @JvmOverloads constructor( | |
context: Context, | |
attrs: AttributeSet? = null, | |
defStyleAttr: Int = 0 | |
) : FrameLayout(context, attrs, defStyleAttr) { | |
init { | |
setOnHierarchyChangeListener(object : OnHierarchyChangeListener { | |
override fun onChildViewAdded( | |
parent: View, | |
child: View | |
) { | |
requestApplyInsets() | |
} | |
override fun onChildViewRemoved( | |
parent: View, | |
child: View | |
) { | |
} | |
}) | |
} | |
override fun dispatchApplyWindowInsets(insets: WindowInsets): WindowInsets { | |
if (!insets.isConsumed) { | |
val count = childCount | |
for (i in 0 until count) { | |
val freshInsets = WindowInsets(insets) | |
getChildAt(i)?.let { safeChild -> | |
if (safeChild.visibility != View.GONE) safeChild.dispatchApplyWindowInsets(freshInsets) | |
} | |
} | |
} | |
return insets | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment