-
Notifications
You must be signed in to change notification settings - Fork 25
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
Always recompute screen size related calculations #654
Conversation
Currently, screen shize related calculations are done once and remembered on recompositions. This works well when adapting to the new size when orientation of the device is changed. However, when the activity hosting the composable restricts configuration changes, the remembered value is not recomputed preventing the presentables from adapting to the new screen size. As a solution, do not remember the size related calculation. Always calculate them on composition.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #654 +/- ##
============================================
- Coverage 81.52% 81.52% -0.00%
- Complexity 2129 2130 +1
============================================
Files 191 191
Lines 8909 8903 -6
Branches 1114 1114
============================================
- Hits 7263 7258 -5
+ Misses 1090 1089 -1
Partials 556 556
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@@ -58,8 +58,8 @@ internal fun FloatingButton( | |||
onDragFinished: (Offset) -> Unit | |||
) { | |||
// Floating button draggable area dimensions | |||
val heightDp = with(LocalConfiguration.current) { remember { mutableStateOf(screenHeightDp.dp) } } | |||
val widthDp = with(LocalConfiguration.current) { remember { mutableStateOf(screenWidthDp.dp) } } |
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.
Do we also need to recompute the offset for the floating button when the orientation is changed?
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.
Offset is provided from the FloatingButtonScreen
which is not remembered so that should be sufficient.
There's an instrumentation test for orientation change. Is it possible to modify it to verify the width and height are recalculated? |
The current instrumentation test for rotation is misleading as it not really testing rotation. It just simulates reconstruction. I am working on modifying it to actually test rotation. |
I couldn't find a reliable way to simulate device rotation using compose test rule :/ Closest I found was |
Description
Problem: Currently, screen size related calculations are done once and remembered on recompositions. This works well generally when adapting to the new size when orientation of the device is changed.
However, when the activity hosting the composable restricts configuration change (via
android:configChanges="orientation|..."
flags in the activity manifest), the remembered value is not recomputed preventing the presentables from adapting to the new screen size.Solution: Do not remember the size related calculations. Always calculate them on composition.
Related Issue
Internal (MOB-20923)
How Has This Been Tested?
Screenshots (if appropriate):
MessageScreenOrientationTests.webm
Types of changes
Checklist: