woocommerce / woocommerce-android

WooCommerce Android app
https://www.woocommerce.com/mobile
GNU General Public License v2.0
277 stars 135 forks source link

Fix crash on order details when tapping customer info buttons #12920

Closed hichamboushaba closed 1 week ago

hichamboushaba commented 1 week ago

Closes: #12913 Closes: #12919

Description

This PR fixes a crash that can occur in order details screen when tapping on of the buttons of the OrderDetailCustomerInfoView, the crash occurs if the user tries to tap on the buttons after the view was detached from the window, this can happen during transition animations, and happens more frequently on tablets given how the navigation works with the dual pane mode.

For technical side, this crash happens because when the fragment view is destroyed, the NavHostFragment will detach the navController, so if a button click listener was to be invoked after this, the findNavController will throw the exception.

Steps to reproduce

Please repeat the following on both trunk and this branch to confirm the fix.

  1. Use a physical device.
  2. Open the order list on dual pane mode (Either on a tablet, or alternatively on a phone by opening the order list when the phone is on landscape)
  3. Use two fingers to tap instantly on both:
    • The shipping section of order details.
    • The row of another order.
  4. Repeat 3 few times, and the app should crash occasionally on trunk, and shouldn't crash on this branch.

Alternatively, if the above wasn't enough to reproduce it, please apply the following patch to simulate it, the patch will trigger manually the click after the view is destroyed, which should cause the crash on trunk and would confirm the fix of this branch.

Patch ```patch Index: WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/details/views/OrderDetailCustomerInfoView.kt IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/details/views/OrderDetailCustomerInfoView.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/details/views/OrderDetailCustomerInfoView.kt --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/details/views/OrderDetailCustomerInfoView.kt (revision 564631291444e615d443e2bd4f6e00d8252602d8) +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/details/views/OrderDetailCustomerInfoView.kt (date 1731511463945) @@ -40,7 +40,7 @@ private const val TELEGRAM_PACKAGE_NAME = "org.telegram.messenger" } - private val binding = OrderDetailCustomerInfoBinding.inflate(LayoutInflater.from(ctx), this) + val binding = OrderDetailCustomerInfoBinding.inflate(LayoutInflater.from(ctx), this) private var isCustomerInfoViewExpanded = false override fun onSaveInstanceState(): Parcelable { Index: WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/details/OrderDetailFragment.kt IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/details/OrderDetailFragment.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/details/OrderDetailFragment.kt --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/details/OrderDetailFragment.kt (revision 564631291444e615d443e2bd4f6e00d8252602d8) +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/details/OrderDetailFragment.kt (date 1731508415600) @@ -311,7 +311,9 @@ override fun onDestroyView() { super.onDestroyView() + val customerInfoBinding = binding.orderDetailCustomerInfo.binding _binding = null + customerInfoBinding.customerInfoShippingAddressSection.callOnClick() } fun onPrepareMenu(menu: Menu) { ```

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:

dangermattic commented 1 week ago
1 Warning
:warning: View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.

Generated by :no_entry_sign: Danger

wpmobilebot commented 1 week ago
📲 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
Commitaa2a8f7bcdccb86877e8b8b4b444b6b943bf8321
Direct Downloadwoocommerce-wear-prototype-build-pr12920-aa2a8f7.apk
wpmobilebot commented 1 week ago

📲 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
Commitaa2a8f7bcdccb86877e8b8b4b444b6b943bf8321
Direct Downloadwoocommerce-prototype-build-pr12920-aa2a8f7.apk