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

Issue/11750 dashboard big screen support #13488

Merged
merged 17 commits into from
Feb 11, 2025

Conversation

JorgeMucientes
Copy link
Contributor

@JorgeMucientes JorgeMucientes commented Feb 7, 2025

Closes: #13079

Description

Based on the changes I worked on here: pe5sF9-3si-p2 and resulting in this PR work, I've refactored the prior implementation to avoid using LazyStaggeredGrid to support big screen in the dashboard tab. Instead, this relies on a custom implementation that will manually add 2 or 3 columns to the dashboard based on the screen's currentWindowAdaptiveInfo().windowSizeClass.

Changes added:

  • Removed usage of xml NestedScrollView. This was needed in order to add Composable colums with vertical scroll that work well/coordinate with the collapsing toolbar.
  • Refactored pull to refresh implementation to use Composable approach instead of relying in our custom view.
  • Adjusted columns and manually created grid to coordinate with the collapsing toolbar.

There's one thing I'm not fully convinced. To determine the number of columns, I'm using windowSizeClass.windowWidthSizeClass.

Screenshot 2025-02-07 at 09 13 45

This results in bigger phones showing 3 columns in landscape (see screen recordings below). I don't think it is a major issue, but I'd say two columns would look better. Let me know what you think, although I suspect it won't be straightforward to force two columns for mobile phones on landscape mode.

Testing information

Just run the app on the phone screen and tablet screen and check that the dashboard works as expected.

  • Rotate the device and test the number of columns adjusts accordingly
  • Check pull to refresh works as expected
  • Check scrolling up and down works well with the collapsing toolbar
  • Add and remove cards at will and check that they are displayed in the right order.

The tests that have been performed

The above ☝🏼

Images/gif

Tablet Experience

TablerLayout.mp4

Large phone Eexperience (Pixel 8 pro)

LargePhone.mp4

Smaller phone experience

smallerPhone.mp4
  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on big (tablet) and small (phone) in case of UI changes, and no regressions are added.

- Replace custom `WindowSizeClass` with `WindowWidthSizeClass` from `androidx.window.core.layout`.
- Use `currentWindowAdaptiveInfo` instead custom extension that ignores screen width to calculate SizeClass
- Update the number of columns in the Dashboard based on the Window Size Class.
- Use a `Column` with vertical scrolling instead of `LazyColumn` when `numberOfColumns` is 1.
- When multiple columns in a row instead of LazyVerticalStaggeredGrid that doesn't work well with nested scrolling interactions
- Adds dependency to adaptiveAndroid
@JorgeMucientes JorgeMucientes added the feature: dashboard Related to home screen project label Feb 7, 2025
@JorgeMucientes JorgeMucientes added this to the 21.8 milestone Feb 7, 2025
@dangermattic
Copy link
Collaborator

dangermattic commented Feb 7, 2025

1 Warning
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Feb 7, 2025

📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
App Name WooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commit88ccc00
Direct Downloadwoocommerce-wear-prototype-build-pr13488-88ccc00.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Feb 7, 2025

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App Name WooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commit88ccc00
Direct Downloadwoocommerce-prototype-build-pr13488-88ccc00.apk

@JorgeMucientes JorgeMucientes modified the milestones: 21.8, 21.7 Feb 7, 2025
mainActivityViewModel: MainActivityViewModel,
dashboardViewModel: DashboardViewModel,
blazeCampaignCreationDispatcher: BlazeCampaignCreationDispatcher,
widgetModifier: Modifier

Check warning

Code scanning / Android Lint

Guidelines for Modifier parameters in a Composable function Warning

Modifier parameter should be named modifier
@JorgeMucientes JorgeMucientes marked this pull request as ready for review February 7, 2025 08:23
@JorgeMucientes JorgeMucientes requested a review from a team as a code owner February 7, 2025 08:23
@@ -411,6 +411,7 @@ dependencies {
implementation(libs.androidx.compose.material.icons.extended)
implementation(libs.androidx.compose.ui.text.google.fonts)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.adaptive.android)
Copy link
Contributor Author

@JorgeMucientes JorgeMucientes Feb 7, 2025

Choose a reason for hiding this comment

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

Added this dependency to rely on official library to categorize screen size. We currently have a custom implmentation of WindowSizeClass but I think we should be using the official one. Also the custom implementation of WindowSizeClass currently only exposes windowHeightSizeClass but not windowWidthSizeClass. So instead of manually adding windowWidthSizeClass, I figured we could use the official size class library for it.

@hichamboushaba hichamboushaba self-assigned this Feb 7, 2025
@JorgeMucientes JorgeMucientes modified the milestones: 21.7, 21.8 Feb 7, 2025
@JorgeMucientes
Copy link
Contributor Author

Setting the milestone to 21.8. I noticed the code freeze hasn't happened yet. I don't want to rush this into trunk and rather leave more time for testing, as there are multiple changes in one of the main screens of the app.

Copy link
Contributor

@pachlava pachlava left a comment

Choose a reason for hiding this comment

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

@JorgeMucientes 👋

I noticed that this fails:

> Task :WooCommerce:compileWasabiDebugAndroidTestKotlin FAILED

e: file:///Users/.../woocommerce-android/WooCommerce/src/androidTest/kotlin/com/woocommerce/android/e2e/screens/mystore/DashboardScreen.kt:17:37 Unresolved reference 'my_store_refresh_layout'.

Making tests execution impossible. This is caused by the removal of my_store_refresh_layout from fragment_dashboard.xml and probably can be fixed by replacing R.id.my_store_refresh_layout in DashboardScreen.kt:17:37 by another component (ideally, unique), the presence of which can inform that we're on the Dashboard Screen.

@pachlava pachlava self-requested a review February 7, 2025 12:28
@codecov-commenter
Copy link

codecov-commenter commented Feb 7, 2025

Codecov Report

Attention: Patch coverage is 9.90991% with 100 lines in your changes missing coverage. Please review.

Project coverage is 37.88%. Comparing base (5f2395f) to head (88ccc00).
Report is 18 commits behind head on trunk.

Files with missing lines Patch % Lines
...ommerce/android/ui/dashboard/DashboardContainer.kt 0.00% 94 Missing ⚠️
...ommerce/android/ui/dashboard/DashboardViewModel.kt 64.70% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #13488      +/-   ##
============================================
- Coverage     37.90%   37.88%   -0.02%     
  Complexity     8981     8981              
============================================
  Files          2053     2053              
  Lines        112183   112254      +71     
  Branches      14173    14188      +15     
============================================
+ Hits          42524    42532       +8     
- Misses        65783    65844      +61     
- Partials       3876     3878       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@pachlava pachlava left a comment

Choose a reason for hiding this comment

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

@JorgeMucientes I took a liberty of updating the missing reference in UI tests with 581d2e9, so tests-wise it's good to go now

@JorgeMucientes
Copy link
Contributor Author

@JorgeMucientes I took a liberty of updating the missing reference in UI tests with 581d2e9, so tests-wise it's good to go now

Awesome @pachlava. Thanks so much for proactively taking a look into this 🥇

Copy link
Member

@hichamboushaba hichamboushaba left a comment

Choose a reason for hiding this comment

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

Really nice work @JorgeMucientes 👏, code looks good, but:

There's one thing I'm not fully convinced. To determine the number of columns, I'm using windowSizeClass.windowWidthSizeClass.

I'm not convinced either by this, the three columns looks really cramped in phones, and could also in some tablets. I also prefer using the default libraries whenever possible, but for this case, it seems the default doesn't match what we need, WDYT about going the manual way here? Instead of using the SizeClass, we can simply wrap everything in a BoxWithConstraints, and use the maxWidth property to calculate the number of columns, and we can then have a column width that looks better.

.fillMaxSize()
.background(MaterialTheme.colors.surface)
.padding(16.dp),
numberOfColumns = when (windowSizeClass.windowWidthSizeClass) {
Copy link
Member

Choose a reason for hiding this comment

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

Should we coerce the numberOfColumns to the number of available cards (coerceIn(maximumValue = state.widgets.size)? For example if I have only one card, and I use the app in landscape, it will appear like this:

Screenshot_20250210_185256

Comment on lines +354 to +356
override fun scrollToTop() {
return
}
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a TODO about bringing back this functionality? This was called when re-selecting the tab, but it's broken now, as MainActivity#getActiveTopLevelFragment seems broken in trunk, I will try to investigate why later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, good point. I removed the nestedScrollView on XML I'm not sure how feasible would it be to fix this. Going to investigate it, if its a quick change, I'll apply it in this PR. If not, I'll create a new GH issue.

Copy link
Member

Choose a reason for hiding this comment

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

One way would be to host the ScrollState in the ViewModel (or the Fragment if we can easily restore its state), and then pass it to the Composable code from there, and use its function (animateScrollTo or scrollTo) for triggering the scroll to top.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I look a bit into this, and fixing it is more complicated than I though.
I did some quick and dirty changes to try to fix shouldExpandToolbar and scrollToTop from DashboardFragment and noticed the following issues:

  • scrollToTop() is never called when re-selecting the tab. This happens to all the other tabs as well and it is because getActiveTopLevelFragment() returns null always, when reselecting any tab. I don't know since when this is broken and haven't had the time to dig deper
    Regarding shouldExpandToolbar, I think there's a race condition where shouldExpandToolbar() is called when the toolbar is already expanded (too late). This causes the toolbar to always be in expanded mode when navigating back to My Store tabs from other tabs, regardless of the scrollState value.

Created a GH issue but I won't have time to look into this shortly.

The number of columns in the grid layout should not exceed the number of available widgets.
Stop relying on Android material 3 WindowSizeClass categorization since the existing values doesn't work for us leading to a cramped UI with 3 columns on phones in landscape mode.
@JorgeMucientes
Copy link
Contributor Author

Thanks for the careful review @hichamboushaba.
Those are really great suggestions for improving the experience. I've applied them both. Ready for another round 👍🏼

Copy link
Member

@hichamboushaba hichamboushaba left a comment

Choose a reason for hiding this comment

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

Great work 👏, this works really well, thanks @JorgeMucientes.

@JorgeMucientes JorgeMucientes merged commit 08a9a97 into trunk Feb 11, 2025
15 checks passed
@JorgeMucientes JorgeMucientes deleted the issue/11750-dashboard-big-screen-support branch February 11, 2025 20:35
Copy link

sentry-io bot commented Feb 11, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ ApplicationNotResponding: Background ANR com.woocommerce.android.ui.dashboard.stats.Dash... View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: dashboard Related to home screen project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants