Skip to content

Commit 359e517

Browse files
Replace callerDestinationId with popDestination approach
Instead of passing a caller destination ID through the refund nav graph, use popBackStack's inclusive parameter to pop the issueRefundFragment, which removes the entire refund graph from the back stack regardless of the caller. This makes the refund flow caller-agnostic and scales to any future integrations.
1 parent 65aba04 commit 359e517

File tree

5 files changed

+14
-18
lines changed

5 files changed

+14
-18
lines changed

WooCommerce/src/main/kotlin/com/woocommerce/android/extensions/FragmentExt.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ import kotlin.math.abs
3131
* @param [key] A unique string that is the same as the one used in [handleResult]
3232
* @param [result] A result value to be returned
3333
* @param [destinationId] an optional destinationId, that can be used to navigate up to a specified destination
34+
* @param [popDestination] whether to pop the destinationId from the back stack when navigating back, used only
35+
* when [destinationId] is specified
3436
*
3537
*/
3638
fun <T> Fragment.navigateBackWithResult(
3739
key: String,
3840
result: T,
3941
@IdRes destinationId: Int? = null,
42+
popDestination: Boolean = false,
4043
@IdRes navHostId: Int? = null,
4144
) {
4245
val navController = if (navHostId != null) findNavController(navHostId) else findNavController()
@@ -49,7 +52,7 @@ fun <T> Fragment.navigateBackWithResult(
4952
entry?.savedStateHandle?.set(key, result)
5053

5154
if (destinationId != null) {
52-
findNavController().popBackStack(destinationId, false)
55+
findNavController().popBackStack(destinationId, popDestination)
5356
} else {
5457
findNavController().navigateUp()
5558
}
@@ -63,7 +66,6 @@ fun <T> Fragment.navigateBackWithResult(
6366
* @param [key] A unique string that is the same as the one used in [handleResult]
6467
* @param [result] A result value to be returned
6568
* @param [childId] an destinationId, that used to navigate up from the specified destination
66-
* @param [navHostId] An optional ID of the NavHostFragment, it's useful when the fragment is used in two-pane layouts
6769
*/
6870
fun <T> Fragment.navigateToParentWithResult(key: String, result: T, @IdRes childId: Int) {
6971
if (findNavController().currentDestination?.id != childId) {
@@ -79,14 +81,17 @@ fun <T> Fragment.navigateToParentWithResult(key: String, result: T, @IdRes child
7981
*
8082
* @param [key] A unique string that is the same as the one used in [handleNotice]
8183
* @param [destinationId] an optional destinationId, that can be used to navigating up to a specified destination
84+
* @param [popDestination] whether to pop the destinationId from the back stack when navigating back, used only
85+
* when [destinationId] is specified
8286
* @param [navHostId] An optional ID of the NavHostFragment, it's useful when the fragment is used in two-pane layouts
8387
*/
8488
fun Fragment.navigateBackWithNotice(
8589
key: String,
8690
@IdRes destinationId: Int? = null,
91+
popDestination: Boolean = false,
8792
@IdRes navHostId: Int? = null,
8893
) {
89-
navigateBackWithResult(key, key, destinationId, navHostId)
94+
navigateBackWithResult(key, key, destinationId, popDestination, navHostId)
9095
}
9196

9297
/**

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/bookings/details/BookingDetailsFragment.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ class BookingDetailsFragment : BaseFragment() {
7878
findNavController().navigateSafely(
7979
BookingDetailsFragmentDirections
8080
.actionBookingDetailsFragmentToIssueRefund(
81-
orderId = event.orderId,
82-
callerDestinationId = R.id.bookingDetailsFragment
81+
orderId = event.orderId
8382
)
8483
)
8584
}

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/payments/refunds/RefundSummaryFragment.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ class RefundSummaryFragment : BaseFragment(R.layout.fragment_refund_summary), Ba
123123
when (event) {
124124
is ShowSnackbar -> uiMessageResolver.getSnack(event.message, *event.args).show()
125125
is Exit -> {
126-
val callerDestId = findNavController()
127-
.getBackStackEntry(R.id.nav_graph_refunds)
128-
.arguments?.getInt("callerDestinationId", 0) ?: 0
129-
val destId = if (callerDestId != 0) callerDestId else R.id.orderDetailFragment
130-
navigateBackWithNotice(REFUND_ORDER_NOTICE_KEY, destId)
126+
navigateBackWithNotice(
127+
key = REFUND_ORDER_NOTICE_KEY,
128+
destinationId = R.id.issueRefundFragment,
129+
popDestination = true
130+
)
131131
}
132132
is ShowRefundConfirmation -> {
133133
val action =

WooCommerce/src/main/res/navigation/nav_graph_bookings_details.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
android:name="orderId"
2222
android:defaultValue="0L"
2323
app:argType="long" />
24-
<argument
25-
android:name="callerDestinationId"
26-
android:defaultValue="0"
27-
app:argType="integer" />
2824
</action>
2925
</fragment>
3026

WooCommerce/src/main/res/navigation/nav_graph_refunds.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:id="@+id/nav_graph_refunds"
66
app:startDestination="@id/issueRefundFragment" >
7-
<argument
8-
android:name="callerDestinationId"
9-
android:defaultValue="0"
10-
app:argType="integer" />
117
<fragment
128
android:id="@+id/refundSummaryFragment"
139
android:name="com.woocommerce.android.ui.payments.refunds.RefundSummaryFragment"

0 commit comments

Comments
 (0)