Skip to content

Commit c56e413

Browse files
Feat/ SortableList - add ItemMargin prop (#2561)
* add ItemMargin prop * move height calculation * renaming * Prettify --------- Co-authored-by: M-i-k-e-l <[email protected]>
1 parent f41adf1 commit c56e413

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

src/components/sortableList/SortableList.api.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
"type": "number",
3131
"default": "1",
3232
"description": "Scale the item once dragged."
33+
},
34+
{
35+
"name": "itemProps",
36+
"type": "{margins?: {marginTop?: number; marginBottom?: number; marginLeft?: number; marginRight?: number}}",
37+
"description": "Extra props for the item."
3338
}
3439
],
3540
"snippet": [

src/components/sortableList/SortableListContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface SortableListContextType<ItemT extends SortableListItemProps> {
1212
onItemLayout: ViewProps['onLayout'];
1313
enableHaptic?: boolean;
1414
scale?: number;
15+
itemProps?: {margins?: {marginTop?: number; marginBottom?: number; marginLeft?: number; marginRight?: number}};
1516
}
1617

1718
// @ts-ignore

src/components/sortableList/SortableListItem.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const SortableListItem = (props: Props) => {
3939
const {
4040
data,
4141
itemHeight,
42+
itemProps,
4243
onItemLayout,
4344
itemsOrder,
4445
lockedIds,
@@ -167,6 +168,7 @@ const SortableListItem = (props: Props) => {
167168
zIndex,
168169
transform: [{translateY: translateY.value}, {scale}],
169170
opacity,
171+
...itemProps?.margins,
170172
...shadow
171173
};
172174
});

src/components/sortableList/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function generateLockedIds<ItemT extends SortableListItemProps>(data: SortableLi
2222

2323
const SortableList = <ItemT extends SortableListItemProps>(props: SortableListProps<ItemT>) => {
2424
const themeProps = useThemeProps(props, 'SortableList');
25-
const {data, onOrderChange, enableHaptic, scale, ...others} = themeProps;
25+
const {data, onOrderChange, enableHaptic, scale, itemProps, ...others} = themeProps;
2626

2727
const itemsOrder = useSharedValue<string[]>(generateItemsOrder(data));
2828
const lockedIds = useSharedValue<Dictionary<boolean>>(generateLockedIds(data));
@@ -49,7 +49,7 @@ const SortableList = <ItemT extends SortableListItemProps>(props: SortableListPr
4949
const newHeight = Math.round(event.nativeEvent.layout.height);
5050
// Check validity for tests
5151
if (newHeight) {
52-
itemHeight.value = newHeight;
52+
itemHeight.value = newHeight + (itemProps?.margins?.marginTop ?? 0) + (itemProps?.margins?.marginBottom ?? 0);
5353
}
5454
}, []);
5555

@@ -60,6 +60,7 @@ const SortableList = <ItemT extends SortableListItemProps>(props: SortableListPr
6060
lockedIds,
6161
onChange,
6262
itemHeight,
63+
itemProps,
6364
onItemLayout,
6465
enableHaptic,
6566
scale

src/components/sortableList/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ export interface SortableListProps<ItemT extends SortableListItemProps>
2626
* (please note that react-native-haptic-feedback does not support the specific haptic type on Android starting on an unknown version, you can use 1.8.2 for it to work properly)
2727
*/
2828
enableHaptic?: boolean;
29+
/**
30+
* Extra props for the item
31+
*/
32+
itemProps?: {margins?: {marginTop?: number; marginBottom?: number; marginLeft?: number; marginRight?: number}};
2933
}

0 commit comments

Comments
 (0)