Skip to content

Commit 77910db

Browse files
committed
refactor
1 parent 5c722c2 commit 77910db

File tree

3 files changed

+57
-33
lines changed

3 files changed

+57
-33
lines changed

samples/MobileBuyIntegration/app/src/main/java/com/shopify/checkout_sdk_mobile_buy_integration_sample/CheckoutSdkApp.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import com.shopify.checkout_sdk_mobile_buy_integration_sample.common.SnackbarCon
6464
import com.shopify.checkout_sdk_mobile_buy_integration_sample.common.navigation.BottomAppBarWithNavigation
6565
import com.shopify.checkout_sdk_mobile_buy_integration_sample.common.navigation.CheckoutSdkNavHost
6666
import com.shopify.checkout_sdk_mobile_buy_integration_sample.common.navigation.Screen
67-
import com.shopify.checkout_sdk_mobile_buy_integration_sample.common.ui.CheckoutEventHandler
67+
import com.shopify.checkout_sdk_mobile_buy_integration_sample.common.ui.NativeSheetsOrchestrator
6868
import com.shopify.checkout_sdk_mobile_buy_integration_sample.common.ui.theme.CheckoutSdkSampleTheme
6969
import com.shopify.checkout_sdk_mobile_buy_integration_sample.logs.LogsViewModel
7070
import com.shopify.checkout_sdk_mobile_buy_integration_sample.settings.SettingsUiState
@@ -182,7 +182,7 @@ fun CheckoutSdkAppRoot(
182182
}
183183
}
184184

185-
CheckoutEventHandler()
185+
NativeSheetsOrchestrator()
186186
}
187187
}
188188
}

samples/MobileBuyIntegration/app/src/main/java/com/shopify/checkout_sdk_mobile_buy_integration_sample/common/MobileBuyEventProcessor.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import com.shopify.checkout_sdk_mobile_buy_integration_sample.common.analytics.A
3737
import com.shopify.checkout_sdk_mobile_buy_integration_sample.common.analytics.toAnalyticsEvent
3838
import com.shopify.checkout_sdk_mobile_buy_integration_sample.common.logs.Logger
3939
import com.shopify.checkout_sdk_mobile_buy_integration_sample.common.navigation.Screen
40-
import com.shopify.checkout_sdk_mobile_buy_integration_sample.common.ui.AddressPickerState
40+
import com.shopify.checkout_sdk_mobile_buy_integration_sample.common.ui.NativeSheet
41+
import com.shopify.checkout_sdk_mobile_buy_integration_sample.common.ui.NativeSheetState
4142
import com.shopify.checkoutsheetkit.CartDelivery
4243
import com.shopify.checkoutsheetkit.CartDeliveryAddressInput
4344
import com.shopify.checkoutsheetkit.CartSelectableAddressInput
@@ -96,7 +97,7 @@ class MobileBuyEventProcessor(
9697

9798
override fun onAddressChangeRequested(event: CheckoutAddressChangeRequestedEvent) {
9899
logger.log("Address change requested")
99-
AddressPickerState.showPicker(event)
100+
NativeSheetState.show(NativeSheet.Address(event))
100101
}
101102

102103
override fun onShowFileChooser(

samples/MobileBuyIntegration/app/src/main/java/com/shopify/checkout_sdk_mobile_buy_integration_sample/common/ui/CheckoutEventHandler.kt renamed to samples/MobileBuyIntegration/app/src/main/java/com/shopify/checkout_sdk_mobile_buy_integration_sample/common/ui/NativeSheetsOrchestrator.kt

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,48 +33,71 @@ import com.shopify.checkoutsheetkit.CheckoutAddressChangeRequestedEvent
3333
import com.shopify.checkoutsheetkit.DeliveryAddressChangePayload
3434

3535
/**
36-
* Handles checkout-related UI events (address picker, payment methods, etc.)
37-
* Centralizes all checkout event responses in one place.
36+
* Represents the different types of native sheets that can be displayed during checkout.
37+
*/
38+
sealed class NativeSheet {
39+
data class Address(val event: CheckoutAddressChangeRequestedEvent) : NativeSheet()
40+
// Future: data class Payment(val event: CheckoutPaymentMethodChangeRequestedEvent) : NativeSheet()
41+
}
42+
43+
/**
44+
* Orchestrates native sheets displayed during checkout (address picker, payment methods, etc.)
45+
* Watches for checkout events and launches the appropriate native sheet components.
46+
* Ensures only one sheet is displayed at a time.
47+
*/
48+
@Composable
49+
fun NativeSheetsOrchestrator() {
50+
when (val sheet = NativeSheetState.currentSheet) {
51+
is NativeSheet.Address -> AddressSheet(
52+
event = sheet.event,
53+
onDismiss = { NativeSheetState.dismiss() }
54+
)
55+
null -> { /* No sheet showing */ }
56+
}
57+
}
58+
59+
/**
60+
* Native sheet for address selection.
61+
* Presents a bottom sheet with address options and responds to the checkout with the selected address.
3862
*/
3963
@Composable
40-
fun CheckoutEventHandler() {
41-
val addressEvent = AddressPickerState.currentEvent
42-
addressEvent?.let { event ->
43-
AddressSelectionBottomSheet(
44-
onAddressSelected = { selectedAddress ->
45-
event.respondWith(
46-
DeliveryAddressChangePayload(
47-
delivery = CartDelivery(
48-
addresses = listOf(
49-
CartSelectableAddressInput(
50-
address = selectedAddress
51-
)
64+
fun AddressSheet(
65+
event: CheckoutAddressChangeRequestedEvent,
66+
onDismiss: () -> Unit
67+
) {
68+
AddressSelectionBottomSheet(
69+
onAddressSelected = { selectedAddress ->
70+
event.respondWith(
71+
DeliveryAddressChangePayload(
72+
delivery = CartDelivery(
73+
addresses = listOf(
74+
CartSelectableAddressInput(
75+
address = selectedAddress
5276
)
5377
)
5478
)
5579
)
56-
AddressPickerState.dismissPicker()
57-
},
58-
onDismiss = {
59-
AddressPickerState.dismissPicker()
60-
}
61-
)
62-
}
80+
)
81+
onDismiss()
82+
},
83+
onDismiss = onDismiss
84+
)
6385
}
6486

6587
/**
66-
* Shared state holder for address change events.
88+
* Shared state holder for native sheets.
89+
* Ensures only one sheet is displayed at a time.
6790
* Used to bridge between the event callback and Compose UI.
6891
*/
69-
object AddressPickerState {
70-
var currentEvent by mutableStateOf<CheckoutAddressChangeRequestedEvent?>(null)
92+
object NativeSheetState {
93+
var currentSheet by mutableStateOf<NativeSheet?>(null)
7194
private set
7295

73-
fun showPicker(event: CheckoutAddressChangeRequestedEvent) {
74-
currentEvent = event
96+
fun show(sheet: NativeSheet) {
97+
currentSheet = sheet
7598
}
7699

77-
fun dismissPicker() {
78-
currentEvent = null
100+
fun dismiss() {
101+
currentSheet = null
79102
}
80-
}
103+
}

0 commit comments

Comments
 (0)