Last active
March 13, 2019 03:43
-
-
Save samuel22gj/2f67e8797ac9a39ab2e923d26b1e2487 to your computer and use it in GitHub Desktop.
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
/** | |
* @see <a href="https://medium.com/androiddevelopers/windows-insets-fragment-transitions-9024b239a436">Windows Insets + Fragment Transitions</a> | |
*/ | |
public class DispatchWindowInsetsToAllChildrenListener implements OnApplyWindowInsetsListener { | |
@Override | |
public WindowInsetsCompat onApplyWindowInsets(View view, WindowInsetsCompat windowInsetsCompat) { | |
boolean consumed = false; | |
if (view instanceof ViewGroup) { | |
ViewGroup viewGroup = (ViewGroup) view; | |
// Dispatch the insets to the child | |
int childCount = viewGroup.getChildCount(); | |
for (int i = 0; i < childCount; i++) { | |
View child = viewGroup.getChildAt(i); | |
WindowInsetsCompat childResult = ViewCompat.dispatchApplyWindowInsets(child, windowInsetsCompat); | |
// 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 | |
return consumed ? windowInsetsCompat.consumeSystemWindowInsets() : windowInsetsCompat; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment