Skip to content

Reorganise common code that will be used by Accelerated Checkouts#242

Merged
markmur merged 10 commits into
mainfrom
sample-improvements
Aug 20, 2025
Merged

Reorganise common code that will be used by Accelerated Checkouts#242
markmur merged 10 commits into
mainfrom
sample-improvements

Conversation

@markmur

@markmur markmur commented Aug 12, 2025

Copy link
Copy Markdown
Contributor

What changes are you making?

Forms the basis for the incoming Accelerated Checkouts feature.

This PR includes the following:

  • Re-organizes event serialization from the ShopifyCheckoutSheetKit class to a dedicated ShopifyEventSerialization object which will be reused by Accelerated Checkouts
  • Also moves the UIColor extension to a dedicated file to provide some clean up
  • Creates a reusable hook for handling the events in the sample app. This will be used to log the events across both the CSK instance and the AC instances.
  • Updates the sample app to fetch thumbnail images and implements them in the various screens

PR Checklist

Important


Checklist for releasing a new version

Tip

See the Contributing documentation for instructions on how to publish a new version of the library.

@markmur markmur self-assigned this Aug 12, 2025
@github-actions

github-actions Bot commented Aug 12, 2025

Copy link
Copy Markdown

Coverage Report

Lines Statements Branches Functions
Coverage: 100%
100% (120/120) 98.03% (50/51) 100% (41/41)

Comment on lines +23 to +54
export function useShopifyEventHandlers(name?: string): EventHandlers {
const log = createDebugLogger(name ?? '');
const {clearCart} = useCart();

return useMemo(() => {
return {
onPress: () => {
log('onPress');
},
onFail: error => {
log('onFail', error);
},
onComplete: event => {
log('onComplete', event.orderDetails.id);
clearCart();
},
onCancel: () => {
log('onCancel');
},
onWebPixelEvent: event => {
log('onWebPixelEvent', event.name);
},
onClickLink: async url => {
log('onClickLink', url);

if (await Linking.canOpenURL(url)) {
await Linking.openURL(url);
}
},
};
}, [log, clearCart]);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These handlers will be reused in the sample app across the CheckoutSheetKit implementation as well as all the accelerated checkouts instances

@markmur markmur force-pushed the sample-improvements branch from 5d46d32 to e085858 Compare August 12, 2025 13:15
Comment on lines +66 to +100
static func serialize(checkoutCompletedEvent event: CheckoutCompletedEvent) -> [String: Any] {
return encodeToJSON(from: event)
}

/**
* Converts a PixelEvent to a React Native compatible dictionary.
*/
static func serialize(pixelEvent event: PixelEvent) -> [String: Any] {
switch event {
case .standardEvent(let standardEvent):
let encoded = encodeToJSON(from: standardEvent)
return [
"context": encoded["context"] ?? NSNull(),
"data": encoded["data"] ?? NSNull(),
"id": encoded["id"] ?? NSNull(),
"name": encoded["name"] ?? NSNull(),
"timestamp": encoded["timestamp"] ?? NSNull(),
"type": "STANDARD"
]

case .customEvent(let customEvent):
return [
"context": encodeToJSON(from: customEvent.context),
"customData": stringToJSON(from: customEvent.customData) ?? NSNull(),
"id": customEvent.id,
"name": customEvent.name,
"timestamp": customEvent.timestamp,
"type": "CUSTOM"
]
}
}

static func serialize(clickEvent url: URL) -> [String: URL] {
return ["url": url]
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These methods currently exist in the ShopifyCheckoutSheetKit.swift file, but the event handling will be reused in the AcceleratedCheckouts class (incoming), so I'm extracting them to an independent class.

@markmur markmur force-pushed the sample-improvements branch 4 times, most recently from 6e4680d to 3b7f9cb Compare August 12, 2025 13:39
Comment thread sample/Gemfile Outdated
@markmur markmur force-pushed the sample-improvements branch 2 times, most recently from 285adcc to 91c0b9e Compare August 12, 2025 17:50
@markmur markmur marked this pull request as ready for review August 12, 2025 18:01
@markmur markmur requested a review from a team as a code owner August 12, 2025 18:01
@markmur markmur force-pushed the sample-improvements branch from c887bcf to b2ebe3e Compare August 13, 2025 08:58
Comment thread snapshot.json
"ios/ShopifyCheckoutSheetKit.mm",
"ios/ShopifyCheckoutSheetKit.swift",
"ios/ShopifyCheckoutSheetKit+EventSerialization.swift",
"ios/ShopifyCheckoutSheetKit+Extensions.swift",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Had to update the snapshot for these new files

@markmur markmur force-pushed the sample-improvements branch 2 times, most recently from d9a710d to 07e60da Compare August 13, 2025 09:32
Comment thread sample/src/hooks/useCheckoutEventHandlers.ts Outdated
"recoverable": recoverable
]

@unknown default:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is the @unknown needed here? I hadn't seen this before but seems like swift enums shouldn't require this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's a way of announcing issues if our switch is not exhaustive. If we don't have a case for a known issue, the compiler will complain here

@markmur markmur force-pushed the sample-improvements branch from 07e60da to 590f709 Compare August 19, 2025 13:52
- Add getOptimizedImageUrl utility for Shopify CDN image optimization
- Add debugLog and createDebugLogger utilities with conditional development logging

These utilities improve sample app performance and debugging capabilities
and can be used independently of any feature development.
- Provides standardized event handlers with debug logging
- Includes handlers for press, fail, complete, cancel, render state changes, pixel events, and link clicks
- Integrates with existing cart context for order completion cleanup
- Can be used independently of any specific checkout features
@markmur markmur force-pushed the sample-improvements branch from 590f709 to c354c9d Compare August 20, 2025 13:35
@markmur markmur force-pushed the sample-improvements branch from fabcd0b to d6bd230 Compare August 20, 2025 13:41
@markmur markmur merged commit 409b422 into main Aug 20, 2025
13 of 15 checks passed
@markmur markmur deleted the sample-improvements branch August 20, 2025 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants