Skip to content

Commit fcb9805

Browse files
committed
Improve support for RTL layout
Do not consume insets for footer frame.
1 parent a795b2e commit fcb9805

File tree

6 files changed

+82
-46
lines changed

6 files changed

+82
-46
lines changed

dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/activity/DynamicActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
267267
getBottomSheetBehavior();
268268

269269
if (isApplyFooterInsets()) {
270-
DynamicViewUtils.applyWindowInsetsBottom(mFrameFooter, true);
270+
DynamicViewUtils.applyWindowInsetsBottom(mFrameFooter);
271271
}
272272

273273
setFrameVisibility(mBottomSheet);

dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/activity/DynamicSystemActivity.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,25 +1166,23 @@ public void setNavigationBarColor(@ColorInt int color) {
11661166
if (isApplyEdgeToEdgeInsets() && getEdgeToEdgeView() != null) {
11671167
ViewCompat.setOnApplyWindowInsetsListener(getEdgeToEdgeView(),
11681168
new OnApplyWindowInsetsListener() {
1169-
@Override
1170-
public @NonNull WindowInsetsCompat onApplyWindowInsets(
1171-
@NonNull View v, @NonNull WindowInsetsCompat insets) {
1172-
if (!(v.getLayoutParams()
1173-
instanceof ViewGroup.MarginLayoutParams)) {
1174-
return insets;
1175-
}
1176-
1177-
final ViewGroup.MarginLayoutParams lp =
1178-
(ViewGroup.MarginLayoutParams) v.getLayoutParams();
1179-
lp.topMargin = insets.getInsets(
1180-
WindowInsetsCompat.Type.systemBars()).top;
1181-
v.setLayoutParams(lp);
1169+
@Override
1170+
public @NonNull WindowInsetsCompat onApplyWindowInsets(
1171+
@NonNull View v, @NonNull WindowInsetsCompat insets) {
1172+
if (v.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
1173+
final ViewGroup.MarginLayoutParams lp =
1174+
(ViewGroup.MarginLayoutParams) v.getLayoutParams();
1175+
lp.topMargin = insets.getInsets(
1176+
WindowInsetsCompat.Type.systemBars()).top;
1177+
v.setLayoutParams(lp);
1178+
1179+
DynamicViewUtils.applyWindowInsetsBottom(
1180+
getEdgeToEdgeViewBottom(), true);
1181+
}
11821182

1183-
DynamicViewUtils.applyWindowInsetsBottom(
1184-
getEdgeToEdgeViewBottom(), true);
1185-
return insets;
1186-
}
1187-
});
1183+
return insets;
1184+
}
1185+
});
11881186
}
11891187

11901188
if (DynamicWindowUtils.isGestureNavigation(this)) {

dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/util/DynamicScrollUtils.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,16 @@ private static void initializeEdgeEffectFields(@Nullable Object clazz) {
203203
}
204204

205205
/**
206-
* Set the edge effect or glow color for the navigation view.
206+
* Returns the navigation menu view associated with the supplied navigation view.
207207
*
208208
* @param view The navigation view to be used.
209-
* @param color The color to be set.
209+
*
210+
* @return The navigation menu view associated with the supplied navigation view.
210211
*/
211-
public static void setEdgeEffectColor(@Nullable NavigationView view, @ColorInt int color) {
212+
public static @Nullable NavigationMenuView getNavigationMenuView(
213+
@Nullable NavigationView view) {
212214
if (view == null) {
213-
return;
215+
return null;
214216
}
215217

216218
initializeNavigationViewFields(view);
@@ -220,9 +222,26 @@ public static void setEdgeEffectColor(@Nullable NavigationView view, @ColorInt i
220222
F_NAVIGATION_VIEW_PRESENTER.get(view);
221223
initializeNavigationViewFields(presenter);
222224

223-
NavigationMenuView navigationMenuView = (NavigationMenuView)
224-
F_NAVIGATION_VIEW_RECYCLER_VIEW.get(presenter);
225-
setEdgeEffectColor(navigationMenuView, color, null);
225+
return (NavigationMenuView) F_NAVIGATION_VIEW_RECYCLER_VIEW.get(presenter);
226+
} catch (Exception ignored) {
227+
}
228+
229+
return null;
230+
}
231+
232+
/**
233+
* Set the edge effect or glow color for the navigation view.
234+
*
235+
* @param view The navigation view to be used.
236+
* @param color The color to be set.
237+
*/
238+
public static void setEdgeEffectColor(@Nullable NavigationView view, @ColorInt int color) {
239+
if (view == null) {
240+
return;
241+
}
242+
243+
try {
244+
setEdgeEffectColor(getNavigationMenuView(view), color, null);
226245
} catch (Exception ignored) {
227246
}
228247
}

dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/widget/DynamicBottomSheet.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,9 @@ public void applyWindowInsets() {
114114
@Override
115115
public @NonNull WindowInsetsCompat onApplyWindowInsets(
116116
@NonNull View v, @NonNull WindowInsetsCompat insets) {
117-
final boolean isRtl = DynamicViewUtils.isLayoutRtl(v);
118-
v.setPadding(isRtl ? right : left
119-
+ insets.getInsets(WindowInsetsCompat.Type.systemBars()).left,
117+
v.setPadding(left + insets.getInsets(WindowInsetsCompat.Type.systemBars()).left,
120118
top - insets.getInsets(WindowInsetsCompat.Type.systemBars()).top,
121-
isRtl ? left : right
122-
+ insets.getInsets(WindowInsetsCompat.Type.systemBars()).right,
119+
right + insets.getInsets(WindowInsetsCompat.Type.systemBars()).right,
123120
bottom + insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom);
124121
/*
125122
* Fix extra peek height when using top inset for coordinator layout and

dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/widget/DynamicCoordinatorLayout.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,12 @@ public void applyWindowInsets() {
9898
insets.getInsets(WindowInsetsCompat.Type.systemBars()).right,
9999
insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom);
100100

101-
final boolean isRtl = DynamicViewUtils.isLayoutRtl(v);
102101
if (DynamicViewUtils.isRootLayout(v) || ViewCompat.getFitsSystemWindows(v)) {
103-
v.setPadding(isRtl ? right : left + mInsets.left, top + mInsets.top,
104-
isRtl ? left : right + mInsets.right, bottom);
102+
v.setPadding(left + mInsets.left, top + mInsets.top,
103+
right + mInsets.right, bottom);
105104
} else {
106-
v.setPadding(isRtl ? right : left + mInsets.left, top + mInsets.top,
107-
isRtl ? left : right + mInsets.right, bottom + mInsets.bottom);
105+
v.setPadding(left + mInsets.left, top + mInsets.top,
106+
right + mInsets.right, bottom + mInsets.bottom);
108107
}
109108

110109
setWillNotDraw(insets.getInsets(

dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/widget/DynamicNavigationView.java

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import androidx.core.view.ViewCompat;
3030
import androidx.core.view.WindowInsetsCompat;
3131

32+
import com.google.android.material.internal.NavigationMenuView;
3233
import com.google.android.material.internal.ScrimInsetsFrameLayout;
3334
import com.google.android.material.navigation.NavigationView;
3435
import com.google.android.material.shape.MaterialShapeDrawable;
@@ -325,16 +326,33 @@ public void initialize() {
325326

326327
@Override
327328
public void applyWindowInsets() {
329+
final NavigationMenuView menuView = DynamicScrollUtils.getNavigationMenuView(this);
328330
final View header;
329331
final int left = getPaddingLeft();
330332
final int top = getPaddingTop();
331333
final int right = getPaddingRight();
332334
final int bottom = getPaddingBottom();
335+
final int menuLeft;
336+
final int menuTop;
337+
final int menuRight;
338+
final int menuBottom;
333339
final int headerLeft;
334340
final int headerTop;
335341
final int headerRight;
336342
final int headerBottom;
337343

344+
if (menuView != null) {
345+
menuLeft = menuView.getPaddingLeft();
346+
menuTop = menuView.getPaddingTop();
347+
menuRight = menuView.getPaddingRight();
348+
menuBottom = menuView.getPaddingBottom();
349+
} else {
350+
menuLeft = 0;
351+
menuTop = 0;
352+
menuRight = 0;
353+
menuBottom = 0;
354+
}
355+
338356
if (getHeaderCount() != 0) {
339357
header = getHeaderView(0);
340358
headerLeft = header.getPaddingLeft();
@@ -356,26 +374,31 @@ public void applyWindowInsets() {
356374
@NonNull View v, @NonNull WindowInsetsCompat insets) {
357375
final Rect rect = new Rect();
358376
rect.set(insets.getInsets(WindowInsetsCompat.Type.systemBars()).left,
359-
insets.getInsets(WindowInsetsCompat.Type.systemBars()).top, 0,
377+
insets.getInsets(WindowInsetsCompat.Type.systemBars()).top,
378+
insets.getInsets(WindowInsetsCompat.Type.systemBars()).right,
360379
insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom);
361380

362-
final boolean isRtl = DynamicViewUtils.isLayoutRtl(v);
363-
v.setPadding(isRtl ? right : left + rect.left, top,
364-
isRtl ? left : right, bottom + rect.bottom);
365-
366381
try {
367382
final Field fieldInsets =
368383
ScrimInsetsFrameLayout.class.getDeclaredField("insets");
369384
fieldInsets.setAccessible(true);
370385
fieldInsets.set(DynamicNavigationView.this, rect);
371-
372-
if (header != null) {
373-
header.setPadding(headerLeft, headerTop + rect.top,
374-
headerRight, headerBottom);
375-
}
376386
} catch (Exception ignored) {
377387
}
378388

389+
v.setPadding(left + rect.left, top,
390+
right + rect.right, bottom + rect.bottom);
391+
392+
if (menuView != null) {
393+
menuView.setPadding(menuLeft, header != null ? menuTop
394+
: menuTop + rect.top, menuRight, menuBottom);
395+
}
396+
397+
if (header != null) {
398+
header.setPadding(headerLeft, headerTop + rect.top,
399+
headerRight, headerBottom);
400+
}
401+
379402
return insets;
380403
}
381404
});

0 commit comments

Comments
 (0)