Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full support for Android 15, edge-to-edge mode on Android 15 #4897

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

connyduck
Copy link
Collaborator

  • Update to Api 35
  • Update all dependencies that were blocked because they require Api 35
  • fix some deprecation warnings
  • implement the now required edge-to-edge mode

Edge-to-edge mode means that we now draw under the status bar and the navigation bar and need to make sure we don't overlap with them. Previously the system would do that for us, and we would only provide the color we want the bars in.

For the edge-to-edge mode there are two Apis that are important:

  • fitsSystemWindows - some Widgets, mostly from the Material library, automatically handle system insets if you set this attribute on them to true
  • ViewCompat.setOnApplyWindowInsetsListener - this allows you to manually handle the various insets. By returning new insets from the callback it is possible to tell the system which ones are handled and which ones should be taken care of by another view.

In most places edge-to-edge was straightforward to implement, except in ComposeActivity, AccountActivity and MainActivity which required a more custom approach, and a hacky solution to make landscape mode work in BaseActivity.

There is also the ViewCompat.setWindowInsetsAnimationCallback Api which allows animating with moving insets. I used that in LoginActivity and ComposeActivity to animate the Views together with the keyboard.

On Android Versions below 15 (Api <= 34) Tusky will look almost the same as before. I think the only exception is the main bottom bar, which is now slighty larger. We customized it to be smaller than the default, but in edge-to-edge mode the height needs to be wrap_content or it won't handle insets correctly.

Screenshots:

@connyduck connyduck requested review from Tak, Lakoja and charlag January 27, 2025 18:58
@Lakoja
Copy link
Collaborator

Lakoja commented Jan 27, 2025

Looks complicated. :-)

Some views need fine-tuning with this, I guess.
For example the Toot button looks a bit oddly placed. While the compose button seems ok.

@connyduck
Copy link
Collaborator Author

For example the Toot button looks a bit oddly placed.

I think that is just because of the rounded display in the screenshot? Its in the same position as before.

1
2

@connyduck
Copy link
Collaborator Author

There is a weird bug on this branch, when switching to a tab for the first time, it stays empty until touched. Can anybody else reproduce that?

(contentView.layoutParams as ViewGroup.MarginLayoutParams).leftMargin = displayCutoutInsets.left
(contentView.layoutParams as ViewGroup.MarginLayoutParams).rightMargin = displayCutoutInsets.right

WindowInsetsCompat.Builder(insets)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably simpler and more future-proof to build the new insets by calling insets.inset(insets.left, 0, insets.right, 0), which will modify all the inset types at once.

val displayCutoutInsets = insets.getInsets(displayCutout())
// use padding for system bar insets so they get our background color and margin for cutout insets to turn them black
contentView.updatePadding(left = systemBarInsets.left, right = systemBarInsets.right)
(contentView.layoutParams as ViewGroup.MarginLayoutParams).leftMargin = displayCutoutInsets.left
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proper way to update layout params is to set the layout params on the View again after modifying them, otherwise changes may not be visible if the view is already laid out. updateLayoutParams() extension method does that for you.

@cbeyls
Copy link
Contributor

cbeyls commented Jan 30, 2025

About the dependencies that were blocked because they require API 35: it's perfectly safe to upgrade the compileSdk version to be compatible with new Google libraries without changing the targetSdk version. You can always implement the new enforced behaviors later. Androidx libraries actually check both the platform SDK int and the target SDK version to ensure the correct behavior is applied.

@cbeyls
Copy link
Contributor

cbeyls commented Jan 30, 2025

Can you post a screenshot to show horizontal padding and insets in landscape mode? I'm curious to see how the drawer menu looks like and where it's drawn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants