-
Notifications
You must be signed in to change notification settings - Fork 130
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
[2 pane layout] Tablet mode detection logic change #13228
Changes from 3 commits
b45041b
62428af
e0b9d62
f43bda8
f4e100c
e74ef96
3f8497f
dd61dda
91c4324
7e2c9bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,17 +15,29 @@ import androidx.annotation.ColorRes | |
import androidx.core.content.ContextCompat | ||
import com.woocommerce.android.util.SystemVersionUtils | ||
import kotlinx.parcelize.Parcelize | ||
import kotlin.math.max | ||
import kotlin.math.min | ||
|
||
val Context.windowSizeClass: WindowSizeClass | ||
get() = determineWindowWidthSizeClassByGivenSize(resources.configuration.screenWidthDp) | ||
get() = determineWindowSizeClassByDimensions( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AnirudhBhat I think we can not use the same semantics here if we change the logic. Window classes we use here are from https://m3.material.io/foundations/layout/applying-layout/window-size-classes and those are determined based on the width of a device. Reusing the same concept but with different logic may bring confusion and errors I am thinking that:
wdyt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the late response. I agree with your opinion that mixing Window classes and our custom detection logic would create confusion. I've updated the logic to remove Window class reference. Please take a look. |
||
resources.configuration.screenWidthDp, | ||
resources.configuration.screenHeightDp | ||
) | ||
|
||
val Context.windowHeightSizeClass: WindowSizeClass | ||
get() = determineWindowHeightSizeClassByGivenSize(resources.configuration.screenHeightDp) | ||
|
||
private fun determineWindowWidthSizeClassByGivenSize(sizeDp: Int): WindowSizeClass { | ||
private fun determineWindowSizeClassByDimensions(widthDp: Int, heightDp: Int): WindowSizeClass { | ||
val shortSize = min(widthDp, heightDp) | ||
val longSize = max(widthDp, heightDp) | ||
|
||
return when { | ||
sizeDp < WindowSizeClass.Compact.maxWidthDp -> WindowSizeClass.Compact | ||
sizeDp < WindowSizeClass.Medium.maxWidthDp -> WindowSizeClass.Medium | ||
shortSize < WindowSizeClass.Compact.maxWidthDp || longSize < WindowSizeClass.Compact.maxHeightDp -> { | ||
WindowSizeClass.Compact | ||
} | ||
shortSize < WindowSizeClass.Medium.maxWidthDp || longSize < WindowSizeClass.Medium.maxHeightDp -> { | ||
WindowSizeClass.Medium | ||
} | ||
else -> WindowSizeClass.ExpandedAndBigger | ||
} | ||
} | ||
|
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.
np: I think this is not a refactoring, but change of the logic
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.
Updated here: dd61dda