Mastering Complex Drag-and-Drop for Shopping Cart UI

This article provides an in‑depth technical walkthrough of the iCart shopping‑cart drag‑and‑drop feature, detailing the architecture, grouping rules, collision handling, non‑droppable logic, hover calculations, placement callbacks, performance optimizations, and future improvements for a smooth, stable user experience.

DaTaobao Tech
DaTaobao Tech
DaTaobao Tech
Mastering Complex Drag-and-Drop for Shopping Cart UI

Deep Dive into Shopping Cart Drag-and-Drop Implementation

We analyze the technical solution for a smooth, stable, and efficient drag‑and‑drop interaction in the iCart shopping cart, covering architecture, rules, data structures, and user experience.

2.1 Relationship between Cart, Groups and Drag

Cart items are grouped; groups can be reordered across stores, with rules such as items can be moved within the same store, groups can be reordered, combo items must stay together, and certain items have fixed positions.

Items within the same store can be freely reordered.

Items within the same group can be freely reordered.

Store items can be placed into any group.

Combo items must move together without interruption.

Group‑head items must stay at the top of the group.

2.2 Drag Rules

Define allowed operations: move into/out of groups, reorder within a group, join into a group, or remove from a group. The operation is described by a JSON object.

{
  "type": "reorderGroup|reorderInGroup|joinIntoGroup|removeFromGroup",
  "fromBundleId": "XXXXXXX",
  "toBundleId": "XXXXXXX",
  "from": "XXXXXXX",
  "to": "XXXXXXX"
}

2.3 Real‑World Mapping

Use a train‑car analogy to illustrate constraints: VIP cars cannot enter other VIP cars, groups correspond to carriages, items to passengers, and special rows (promotion, filter) act as separators.

3.1 Full Process Breakdown

Dragging consists of three steps: long‑press creates a proxy element, moving updates hover state and shows possible drop targets, and release triggers onReorder to place the item and send network updates.

Long press generates a proxy and hides the original component.

Moving updates hover, auto‑scrolls when near screen edges, and provides visual cues.

Release places the element, expands collapsed groups if needed, and sends a reorder request.

3.2 Hover Handling

During movement, each hover event provides an index; the front end uses this to determine allowed drop locations, ignoring non‑draggable cells such as promotion bars or filter rows.

3.3 Placement (onReorder)

On release, the front end calculates the final position based on the index, updates the UI, expands collapsed groups if necessary, and sends the reorder request to the backend.

4.1 Implementing Non‑Droppable Logic

Each list item has a reorderable flag; setting it to false blocks drops, ensuring items from one store cannot be placed in another.

4.2 Determining Drop Position

Maintain a flat array of visible items; use the index from Weex to map to the nearest droppable element, filtering out promotion bars, filters, and info‑flow components.

4.3 Handling Non‑Draggable Cells

Hidden elements (promotion, filter) keep a height of 0 but still participate in collision detection; the front end adjusts placement accordingly to avoid illegal positions.

5.1 Experience Optimizations

Address visual glitches such as height jumps when dragging groups by synchronizing proxy height changes with list updates, and unify callbacks for start and end of drag to avoid flicker.

5.2 Performance Tuning

Ensure smooth auto‑scroll by using constant step sizes and pre‑computing cell heights, reducing frame drops during long drags.

6.1 Recap

The solution balances Weex’s low‑level animation and collision handling with front‑end logic for rules, visibility, and network updates, achieving a responsive drag‑and‑drop experience in a complex cart UI.

6.2 Outlook

Future work may embed group concepts directly in the list component to simplify the architecture and further improve performance.

Drag-and-drop UI illustration
Drag-and-drop UI illustration
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

frontendWeexShopping CartDrag and Dropuser-experienceui-optimization
DaTaobao Tech
Written by

DaTaobao Tech

Official account of DaTaobao Technology

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.