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

Authenticated WebView improvement [Part 1] #13468

Merged
merged 12 commits into from
Feb 10, 2025

Conversation

hichamboushaba
Copy link
Member

@hichamboushaba hichamboushaba commented Feb 5, 2025

Part of: #13467

Tip

Excluding the commit f0ce7cd when reviewing would make the review easier, this commit just renames few classes.

Description

This PR is a preparation for the next PR that implements the improvements suggested in pe5sF9-3QB-p2, it handles the following changes:

  1. It simplifies the code of the WCWebView composable, and make some changes to make it more use better Compose idiomatic approaches.
  2. It removes some unused code (more details in the comments below)
  3. It allows setting a custom WebViewClient, this turned out to be not needed for this feature, but I believe it can be useful for other features.
  4. Rename the various classes related to the Authenticated WebView from WPComWebView... to AuthenticatedWebView... to align better with the new roles.

Steps to reproduce

This PR shouldn't introduce any behavior changes (except one for Blaze campaign details that I will explain below), so just testing few areas that use the WCWebView and the AuthenticatedWebView, for example:

  1. Order card reader from the Payments hub.
  2. Theme settings for Atomic websites.
  3. Analytics reports for Atomic websites.

Testing information

  • Confirm that there are no regressions.

The tests that have been performed

^

  • 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.

@hichamboushaba hichamboushaba added the type: task An internally driven task. label Feb 5, 2025
@dangermattic
Copy link
Collaborator

dangermattic commented Feb 5, 2025

4 Warnings
⚠️ View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
⚠️ Class WCWebChromeClient is missing tests, but unit-tests-exemption label was set to ignore this.
⚠️ Class WCWebViewClient is missing tests, but unit-tests-exemption label was set to ignore this.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Feb 5, 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
Commit9a4f298
Direct Downloadwoocommerce-wear-prototype-build-pr13468-9a4f298.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Feb 5, 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
Commit9a4f298
Direct Downloadwoocommerce-prototype-build-pr13468-9a4f298.apk

@hichamboushaba hichamboushaba marked this pull request as ready for review February 6, 2025 14:13
@@ -32,7 +32,6 @@ fun BlazeCampaignDetailWebViewScreen(
userAgent = userAgent,
wpComAuthenticator = wpComAuthenticator,
onUrlLoaded = onUrlLoaded,
clearCache = true,
Copy link
Member Author

Choose a reason for hiding this comment

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

clearing cache was enabled here for Blaze campaign details, I don't think this was intentional, so I removed it. The feature works without issues without this, but if I'm missing something, I can bring it back (cc @JorgeMucientes).

Copy link
Contributor

Choose a reason for hiding this comment

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

I also tested this and found no issues. I see no reason to clear the cache in this case, so it looks good to me.

}

webView?.let { webView ->
LaunchedEffect(url) {
Copy link
Member Author

Choose a reason for hiding this comment

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

With using a LaunchedEffect for this, we simplified the code quite a bit as we don't need to check what was the last requested URL.
This also will help in the next PR, as we need to make authenticateAndLoadUrl a suspendable function.


Box(modifier = modifier) {
val webViewAlpha by remember {
derivedStateOf {
Copy link
Member Author

Choose a reason for hiding this comment

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

Using derivedStateOf for this feels more Compose idiomatic than the local functions we were using before, and should be better for performance, as before we were recalculating the alpha on each recomposition even if it didn't change.

@irfano irfano self-assigned this Feb 6, 2025
Copy link
Contributor

@irfano irfano left a comment

Choose a reason for hiding this comment

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

I tested web views on various screens and couldn't find any issues. Organized commits help a lot with the review, thank you for that.

I noticed an issue, but I’m unsure if it was introduced in this PR, and I couldn’t find an error log at first glance. When the Themes screen is open, and I put the app in the background and relaunch it, the app doesn’t start on the Themes screen. Instead, it shows the main screen. I also tested this in trunk, and it resumes from the Themes screen there. Could you check this, please?

Screen_recording_20250208_173756.webm

@@ -32,7 +32,6 @@ fun BlazeCampaignDetailWebViewScreen(
userAgent = userAgent,
wpComAuthenticator = wpComAuthenticator,
onUrlLoaded = onUrlLoaded,
clearCache = true,
Copy link
Contributor

Choose a reason for hiding this comment

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

I also tested this and found no issues. I see no reason to clear the cache in this case, so it looks good to me.

@hichamboushaba
Copy link
Member Author

I noticed an issue, but I’m unsure if it was introduced in this PR, and I couldn’t find an error log at first glance. When the Themes screen is open, and I put the app in the background and relaunch it, the app doesn’t start on the Themes screen. Instead, it shows the main screen. I also tested this in trunk, and it resumes from the Themes screen there. Could you check this, please?

I can't reproduce this issue using this branch, and this PR didn't make any changes to this part, I modified only the handling of the theme preview logic, which is in ThemePreviewFragment, while this issue from your video is in the ThemePickerFragment.

From the look of your video, it seems the "recent apps" repasses the Intent and creates a new task, which removes the AppSettingsActivity from the backstack, I'm not sure why it happens in this case, but it might be a good idea to force close the app, then launch it from the launcher directly, and then re-test, and see if the issue happens?

Copy link
Contributor

@irfano irfano left a comment

Choose a reason for hiding this comment

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

I wiped the emulator’s data and performed a cold boot, but the issue persisted. I then created a new emulator, and the issue is no longer reproducible. That’s strange, it must be related to the emulator itself. In any case, everything looks good. 👍🏻

@irfano irfano enabled auto-merge February 10, 2025 17:03
@irfano irfano added this to the 21.8 milestone Feb 10, 2025
@irfano irfano merged commit b1a251e into trunk Feb 10, 2025
16 checks passed
@irfano irfano deleted the issue/13467-improve-authenticated-webview-1 branch February 10, 2025 17:04
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 6.57895% with 71 lines in your changes missing coverage. Please review.

Project coverage is 37.89%. Comparing base (3f3a643) to head (9a4f298).
Report is 123 commits behind head on trunk.

Files with missing lines Patch % Lines
...erce/android/ui/compose/component/web/WCWebView.kt 0.00% 27 Missing ⚠️
...ndroid/ui/compose/component/web/WCWebViewClient.kt 0.00% 15 Missing ⚠️
...ocommerce/android/ui/themes/ThemePreviewWebView.kt 0.00% 9 Missing ⚠️
...roid/ui/compose/component/web/WCWebViewSettings.kt 0.00% 8 Missing ⚠️
...ui/common/webview/AuthenticatedWebViewViewModel.kt 0.00% 3 Missing ⚠️
...android/ui/compose/component/web/WCWebViewEvent.kt 0.00% 3 Missing ⚠️
.../android/ui/common/webview/WebViewAuthenticator.kt 0.00% 1 Missing ⚠️
...roid/ui/compose/component/web/WCWebChromeClient.kt 0.00% 1 Missing ⚠️
...oid/ui/google/webview/GoogleAdsWebViewViewModel.kt 0.00% 1 Missing ⚠️
...n/accountmismatch/AccountMismatchErrorViewModel.kt 0.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff            @@
##              trunk   #13468   +/-   ##
=========================================
  Coverage     37.88%   37.89%           
- Complexity     8956     8957    +1     
=========================================
  Files          2050     2053    +3     
  Lines        112105   112092   -13     
  Branches      14173    14162   -11     
=========================================
+ Hits          42474    42477    +3     
+ Misses        65751    65736   -15     
+ Partials       3880     3879    -1     

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: task An internally driven task. unit-tests-exemption
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants