Skip to content

Commit 1e2d11b

Browse files
authored
docs: Documentation of some new props and features (#356)
## Description This PR: - adds new `reorderTriggerOrigin` and `overflow` props to docs - improves callbacks documentation and adds information about new feature - worklet callbacks - Updates the type of `DropIndicatorComponentProps` in docs to the correct type
1 parent 1d06c6f commit 1e2d11b

3 files changed

Lines changed: 202 additions & 61 deletions

File tree

packages/docs/docs/flex/props.mdx

Lines changed: 99 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Whenever `Animatable<T>` is used, it refers to the following type definition:
1111
type Animatable<T> = SharedValue<T> | T;
1212
```
1313

14-
This means that properties of type `Animatable<T>` can accept either:
14+
This means that properties of type `Animatable<T>` can accept either of the following:
1515

1616
- a Reanimated **Shared Value** (`SharedValue<T>`)
1717
- a **static value** of type `T`
@@ -268,7 +268,7 @@ This may sometimes cause **performance issues** as it requires layout recalculat
268268

269269
---
270270

271-
## Item Drag Settings
271+
## Item Drag
272272

273273
### overDrag
274274

@@ -325,6 +325,42 @@ The maximum distance (in pixels) the finger can move from the touch start positi
325325

326326
---
327327

328+
## Reordering
329+
330+
### strategy
331+
332+
Controls how items **are reordered** while the **active item** is being **dragged around**.
333+
334+
| type | default | required |
335+
| ---------------------- | -------- | -------- |
336+
| `SortableFlexStrategy` | 'insert' | NO |
337+
338+
- `'insert'` - items are reordered by inserting the active item at the target position and moving all items between the active item and the target position
339+
340+
<details>
341+
<summary>Type definitions</summary>
342+
343+
```tsx
344+
type SortableFlexStrategy = 'insert' | SortableFlexStrategyFactory;
345+
```
346+
347+
{/* TODO: Add link to docs page explaining how to use SortableFlexStrategyFactory */}
348+
349+
</details>
350+
351+
### reorderTriggerOrigin
352+
353+
Determines position of the reordering trigger point. If that point enters the area of a different item than the current one, the reordering will be triggered.
354+
355+
| type | default | required |
356+
| --------------------- | ---------- | -------- |
357+
| `'center' \| 'touch'` | `'center'` | NO |
358+
359+
- `'center'` - reordering will be triggered when the center of the active item enters the area of a different item
360+
- `'touch'` - reordering will be triggered when the touch point enters the area of a different item
361+
362+
---
363+
328364
## Active Item Decoration
329365

330366
All active item decoration settings are applied when the **item becomes active** (when drag gesture starts being handled).
@@ -536,11 +572,17 @@ Component to use as the drop indicator. It gives a **full control** over the dro
536572

537573
```tsx
538574
type DropIndicatorComponentProps = {
539-
activationProgress: SharedValue<number>;
540-
touchedItemKey: SharedValue<null | string>;
575+
/** Progress of the active item animation (from 0 to 1) */
576+
activeAnimationProgress: SharedValue<number>;
577+
/** Key of the currently dragged item, or null if no item is being dragged */
578+
activeItemKey: SharedValue<null | string>;
579+
/** Current index where the dragged item would be dropped */
541580
dropIndex: SharedValue<number>;
581+
/** Current position where the item would be dropped */
542582
dropPosition: SharedValue<Vector>;
583+
/** Array of item keys in their current order */
543584
orderedItemKeys: SharedValue<Array<string>>;
585+
/** Style to be applied to the drop indicator */
544586
style: ViewStyle;
545587
};
546588
```
@@ -553,13 +595,9 @@ type DropIndicatorComponentProps = {
553595

554596
Layout animations control how items animate when their positions change and when they are added or removed from the flex container.
555597

556-
:::note
557-
558598
- Item **entering** animations are **not** triggered during the **initial render** of the flex container
559599
- Item **exiting** animations are **not** triggered when the **entire flex container is unmounted**
560600

561-
:::
562-
563601
:::warning Warning (Web)
564602

565603
There are some **differences** in the **layout animations** implementation on **Web**:
@@ -676,6 +714,41 @@ import reorderVideo from '@site/static/video/flex-layout-transition-mode-reorder
676714

677715
## Callbacks
678716

717+
:::tip Performance Recommendation
718+
Use **worklet functions** for callbacks to run directly on the UI thread and avoid thread jumping overhead.
719+
:::
720+
721+
All callbacks accept two types of functions:
722+
723+
1. **Worklet Functions** (Recommended)
724+
725+
- To mark a function as worklet, you have to add `'worklet'` directive at the start of the function body
726+
- Run directly on the UI thread
727+
- More performant
728+
- Example:
729+
730+
```ts
731+
const onDragStart = useCallback((params: DragStartParams) => {
732+
'worklet';
733+
// Your code here
734+
}, []);
735+
```
736+
737+
2. **Plain JS Functions**
738+
- No special directive needed
739+
- Runs on the JS thread by using `runOnJS`
740+
- Less performant due to jumping between threads
741+
- Example:
742+
```ts
743+
const onDragStart = useCallback((params: DragStartParams) => {
744+
// Your code here
745+
}, []);
746+
```
747+
748+
:::info
749+
For more information about worklets refer to the [Reanimated documentation](https://docs.swmansion.com/react-native-reanimated/docs/guides/worklets/).
750+
:::
751+
679752
### onDragStart
680753

681754
Called when the drag gesture starts.
@@ -753,6 +826,12 @@ type OrderChangeParams = {
753826

754827
</details>
755828

829+
:::warning
830+
831+
**Don't use** this callback to update items order in state because it's called **frequently** during dragging. Use `onDragEnd` for **state updates** instead.
832+
833+
:::
834+
756835
---
757836

758837
### onDragMove
@@ -782,27 +861,6 @@ type DragMoveParams = {
782861

783862
## Other Settings
784863

785-
### strategy
786-
787-
Controls how items **are reordered** while the **active item** is being **dragged around**.
788-
789-
| type | default | required |
790-
| ---------------------- | -------- | -------- |
791-
| `SortableFlexStrategy` | 'insert' | NO |
792-
793-
<details>
794-
<summary>Type definitions</summary>
795-
796-
```tsx
797-
type SortableFlexStrategy = 'insert' | SortableFlexStrategyFactory;
798-
```
799-
800-
{/* TODO: Add link to docs page explaining how to use SortableFlexStrategyFactory */}
801-
802-
</details>
803-
804-
---
805-
806864
### customHandle
807865

808866
Controls whether drag gestures should be restricted to a custom handle component.
@@ -837,10 +895,22 @@ You can also use any other haptics library but you will have to trigger haptics
837895

838896
---
839897

898+
### overflow
899+
900+
Controls if the overflowing content should be clipped or visible. Applies only when no item is active.
901+
902+
| type | default | required |
903+
| ----------------------- | ---------- | -------- |
904+
| `'hidden' \| 'visible'` | `'hidden'` | NO |
905+
906+
---
907+
840908
### debug
841909

842910
Enables debug mode, which shows additional views helpful for debugging. This property is intended for the library **developers** and is not recommended for the library **users**.
843911

912+
Debug mode has no effect in production builds and can be used to debug the library only in the development environment.
913+
844914
| type | default | required |
845915
| --------- | ------- | -------- |
846916
| `boolean` | false | NO |

0 commit comments

Comments
 (0)