Skip to content

Commit 04c2f37

Browse files
Fix incorrect visibility check in EdgeToEdgeDelegate
The visibility check in `findTopBar`, `findBottomBar`, `applyInsetsToFloatingButtons`, and `isVisible` was inverted. This commit corrects the logic to ensure that these methods operate correctly based on the view's visibility. Additionally, the `applyInsetsAsMargin` method has been simplified by removing the `applyTop` and `applyBottom` parameters, as top margin insets are no longer applied.
1 parent d4fb8c4 commit 04c2f37

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

app/src/main/java/com/d4rk/androidtutorials/java/utils/EdgeToEdgeDelegate.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private static void enableEdgeToEdge(Activity activity) {
8181

8282
@Nullable
8383
private static View findTopBar(View view) {
84-
if (!isVisible(view)) {
84+
if (isVisible(view)) {
8585
return null;
8686
}
8787
if (isTopBar(view)) {
@@ -101,7 +101,7 @@ private static View findTopBar(View view) {
101101

102102
@Nullable
103103
private static View findBottomBar(View view) {
104-
if (!isVisible(view)) {
104+
if (isVisible(view)) {
105105
return null;
106106
}
107107
if (isBottomBar(view)) {
@@ -120,11 +120,11 @@ private static View findBottomBar(View view) {
120120
}
121121

122122
private static void applyInsetsToFloatingButtons(View view, int insetTypes) {
123-
if (!isVisible(view)) {
123+
if (isVisible(view)) {
124124
return;
125125
}
126126
if (view instanceof ExtendedFloatingActionButton || view instanceof FloatingActionButton) {
127-
applyInsetsAsMargin(view, insetTypes, false, true);
127+
applyInsetsAsMargin(view, insetTypes);
128128
return;
129129
}
130130
if (view instanceof ViewGroup viewGroup) {
@@ -153,7 +153,7 @@ private static boolean isBottomBar(View view) {
153153
}
154154

155155
private static boolean isVisible(View view) {
156-
return view.getVisibility() == View.VISIBLE;
156+
return view.getVisibility() != View.VISIBLE;
157157
}
158158

159159
private static void applyInsetsAsPadding(View view, int insetTypes,
@@ -199,9 +199,7 @@ private static void applyInsetsAsPadding(View view, int insetTypes,
199199
requestApplyInsetsWhenAttached(view);
200200
}
201201

202-
private static void applyInsetsAsMargin(View view, int insetTypes,
203-
boolean applyTop,
204-
boolean applyBottom) {
202+
private static void applyInsetsAsMargin(View view, int insetTypes) {
205203
if (view == null) {
206204
return;
207205
}
@@ -226,9 +224,9 @@ private static void applyInsetsAsMargin(View view, int insetTypes,
226224
Insets insets = windowInsets.getInsets(insetTypes);
227225
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
228226
MarginLayoutParamsCompat.setMarginStart(lp, margin.start + insets.left);
229-
lp.topMargin = margin.top + (applyTop ? insets.top : 0);
227+
lp.topMargin = margin.top;
230228
MarginLayoutParamsCompat.setMarginEnd(lp, margin.end + insets.right);
231-
lp.bottomMargin = margin.bottom + (applyBottom ? insets.bottom : 0);
229+
lp.bottomMargin = margin.bottom + (insets.bottom);
232230
v.setLayoutParams(lp);
233231
return windowInsets;
234232
});

0 commit comments

Comments
 (0)