Skip to content

Dynamic Button

The Dynamic Button is a versatile iOS bridge component that dynamically manages navigation bar buttons, including cart badges, search/scan actions, and product share.

Basic Info

Incoming Events (Web → Native)

The component listens for several events dispatched from the web view.

EventDescriptionData StructureMetadata
connect / homeConfigures the navigation bar for the home context (Cart, QR Scan, Barcode Scan).{"cart": "count_string"}N/A
productConfigures the navigation bar for the product context (Cart, Share).{"cart": "count_string"}{"url": "share_url"}
navigationbackhideHides the navigation back button.N/AN/A
modalopenHides the back button and shows a cross (dismiss) button.N/AN/A
modaldismissShows the back button if the web view can go back.N/AN/A
cartcountUpdates the cart badge count dynamically.{"count": "count_string"}N/A

Detailed Event Logic

home / connect

Adds three buttons to the right side of the navigation bar:

  1. Cart Button: Shows a badge with the cart count (from json.cart). Tapping it sends a cart reply.
  2. QR Scanner: Opens a native QR code scanner. On completion, sends a scan reply with the result.
  3. Barcode Scanner: Opens an ML-powered barcode scanner with options for "Detect Object" or "Read Text". On completion, sends a scan reply with the result.

product

Adds two buttons to the right side of the navigation bar:

  1. Cart Button: Shows a badge with the cart count (from json.cart).
  2. Share Button: Opens the native iOS share sheet using the URL provided in message.metadata.url.

Outgoing Events (Native → Web)

These are sent as replies to the initial message that registered the component or button.

ActionReply TypeData StructureTrigger
Tapping Cart ButtoncartN/AUser taps cart icon or badge.
Modal Dismissedmodal_dismiss{"code": "modal_dismiss"}User taps the cross (X) button.
QR/Barcode Scannedscan{"code": "result_string"}Scanner successfully detects a code.
ML Object/Text Detectedscan{"code": "result_string"}ML scanner successfully detects object/text.

Technical Details

  • Cart Badge: The badge updates automatically when the cartcount event is received or when context changes (home, product).
  • Back Button: Automatically hides when navigationbackhide is received or when navigation starts in a modal context.
  • Scanner: The QR scanner supports .qr, .ean13, and .ean8 formats.

Released under the MIT License.