Skip to content

Commit

Permalink
fix: Attempt to fix the FAB's weird margin behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
aikrq committed Dec 29, 2024
1 parent 5e9a1df commit f1f2e57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ protected void onCreate(Bundle savedInstanceState) {
binding = ManageLocallibrariesBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

ViewCompat.setOnApplyWindowInsetsListener(binding.downloadLibraryButton, new AddMarginOnApplyWindowInsetsListener(WindowInsetsCompat.Type.navigationBars(), WindowInsetsCompat.CONSUMED));
ViewCompat.setOnApplyWindowInsetsListener(binding.downloadLibraryButton,
new AddMarginOnApplyWindowInsetsListener(WindowInsetsCompat.Type.navigationBars() | WindowInsetsCompat.Type.ime()));

if (getIntent().hasExtra("sc_id")) {
String scId = Objects.requireNonNull(getIntent().getStringExtra("sc_id"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ public class AddMarginOnApplyWindowInsetsListener implements OnApplyWindowInsets
private final int insetsTypeMask;
private final WindowInsetsCompat returnValue;

/**
* @param insetsTypeMask Bit mask of {@link WindowInsetsCompat.Type}s to query the insets for.
*/
public AddMarginOnApplyWindowInsetsListener(int insetsTypeMask) {
this(insetsTypeMask, null);
}

/**
* @param insetsTypeMask Bit mask of {@link WindowInsetsCompat.Type}s to query the insets for.
* @param returnValue What {@link #onApplyWindowInsets(View, WindowInsetsCompat)} should return.
Expand All @@ -36,6 +43,6 @@ public WindowInsetsCompat onApplyWindowInsets(@NonNull View v, @NonNull WindowIn
} else {
throw new IllegalArgumentException("View's layout params must extend ViewGroup.MarginLayoutParams");
}
return returnValue;
return returnValue != null ? returnValue : insets;
}
}

0 comments on commit f1f2e57

Please sign in to comment.