Skip to content

Commit

Permalink
Update sample to call preload at a more appropriate time (#122)
Browse files Browse the repository at this point in the history
update sample to call preload at a more appropriate time
  • Loading branch information
kiftio authored Oct 8, 2024
1 parent a921f2f commit 10b21f6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

### Requirements

- JDK 11+
- JDK 17+
- Android SDK 23+
- The SDK is not compatible with checkout.liquid. The Shopify Store must be migrated for extensibility

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import androidx.compose.ui.unit.sp
import com.shopify.checkout_sdk_mobile_buy_integration_sample.AppBarState
import com.shopify.checkout_sdk_mobile_buy_integration_sample.common.toDisplayText
import com.shopify.checkoutsheetkit.DefaultCheckoutEventProcessor
import com.shopify.checkoutsheetkit.ShopifyCheckoutSheetKit

@Composable
fun <T: DefaultCheckoutEventProcessor> CartView(
Expand All @@ -61,6 +62,7 @@ fun <T: DefaultCheckoutEventProcessor> CartView(
checkoutEventProcessor: T,
) {
val state = cartViewModel.cartState.collectAsState().value
val activity = LocalContext.current as ComponentActivity

LaunchedEffect(state) {
setAppBarState(
Expand All @@ -78,6 +80,10 @@ fun <T: DefaultCheckoutEventProcessor> CartView(
}
)
)

if (state is CartState.Populated) {
ShopifyCheckoutSheetKit.preload(state.checkoutUrl, activity)
}
}

Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ fun ProductView(
) {

val productUIState = productViewModel.uiState.collectAsState().value
val activity = LocalContext.current as ComponentActivity

LaunchedEffect(productUIState) {
setAppBarState(
Expand Down Expand Up @@ -124,9 +123,6 @@ fun ProductView(
productViewModel.setIsAddingToCart(true)
cartViewModel.addToCart(selectedVariant.id) {
productViewModel.setIsAddingToCart(false)
if (it?.checkoutUrl != null) {
ShopifyCheckoutSheetKit.preload(it.checkoutUrl, activity)
}
}
}
}
Expand Down

0 comments on commit 10b21f6

Please sign in to comment.