-
-
Notifications
You must be signed in to change notification settings - Fork 441
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
Fix dark status bar icons when player is in fullscreen #3445
Conversation
fun Activity.setLightStatusBarIcons() { | ||
WindowCompat.getInsetsController(window, window.decorView).isAppearanceLightStatusBars = false | ||
} | ||
|
||
fun Activity.setDarkStatusBarIcons() { | ||
WindowCompat.getInsetsController(window, window.decorView).isAppearanceLightStatusBars = true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the method names should be swapped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are correct. Here we have to change the statusbar icon color but there's no direct method to change icon color directly. So if we set the statusbar as light then icons will be dark
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, missed that.
Edit: Instead of adding these extensions, you could just create a WindowInsetsControllerCompat
in the fragment itself and reuse it as needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we can do that. It's just a preference. By doing what you suggested the code is not reusable and using functions make code more readable in my opinion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but it's not like the code is being used anywhere else in your changeset. If it needs to be used in other places as well, it can be easily refactored.
// set status bar icon color to white | ||
mainActivity.setLightStatusBarIcons() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// set status bar icon color to white | |
mainActivity.setLightStatusBarIcons() | |
// set status bar icon color to white | |
windowInsetsControllerCompat.isAppearanceLightStatusBars = false |
The WindowInsetsControllerCompat
object used here could be created/destroyed in the relevant fragment lifecycle callbacks (onCreate, onDestroy), like with the fragment's view binding.
if (mainActivity.isLightTheme) { | ||
mainActivity.setDarkStatusBarIcons() | ||
} else { | ||
mainActivity.setLightStatusBarIcons() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (mainActivity.isLightTheme) { | |
mainActivity.setDarkStatusBarIcons() | |
} else { | |
mainActivity.setLightStatusBarIcons() | |
} | |
windowInsetsControllerCompat.isAppearanceLightStatusBars = when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) { | |
Configuration.UI_MODE_NIGHT_YES -> false | |
Configuration.UI_MODE_NIGHT_NO -> true | |
else -> true | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Thank you! |
Before:
After: