Skip to content

Commit

Permalink
Feat/ SortableList - add ItemMargin prop (#2561)
Browse files Browse the repository at this point in the history
* add ItemMargin prop

* move height calculation

* renaming

* Prettify

---------

Co-authored-by: M-i-k-e-l <[email protected]>
  • Loading branch information
lidord-wix and M-i-k-e-l authored May 23, 2023
1 parent f41adf1 commit c56e413
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/components/sortableList/SortableList.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"type": "number",
"default": "1",
"description": "Scale the item once dragged."
},
{
"name": "itemProps",
"type": "{margins?: {marginTop?: number; marginBottom?: number; marginLeft?: number; marginRight?: number}}",
"description": "Extra props for the item."
}
],
"snippet": [
Expand Down
1 change: 1 addition & 0 deletions src/components/sortableList/SortableListContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface SortableListContextType<ItemT extends SortableListItemProps> {
onItemLayout: ViewProps['onLayout'];
enableHaptic?: boolean;
scale?: number;
itemProps?: {margins?: {marginTop?: number; marginBottom?: number; marginLeft?: number; marginRight?: number}};
}

// @ts-ignore
Expand Down
2 changes: 2 additions & 0 deletions src/components/sortableList/SortableListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const SortableListItem = (props: Props) => {
const {
data,
itemHeight,
itemProps,
onItemLayout,
itemsOrder,
lockedIds,
Expand Down Expand Up @@ -167,6 +168,7 @@ const SortableListItem = (props: Props) => {
zIndex,
transform: [{translateY: translateY.value}, {scale}],
opacity,
...itemProps?.margins,
...shadow
};
});
Expand Down
5 changes: 3 additions & 2 deletions src/components/sortableList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function generateLockedIds<ItemT extends SortableListItemProps>(data: SortableLi

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

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

Expand All @@ -60,6 +60,7 @@ const SortableList = <ItemT extends SortableListItemProps>(props: SortableListPr
lockedIds,
onChange,
itemHeight,
itemProps,
onItemLayout,
enableHaptic,
scale
Expand Down
4 changes: 4 additions & 0 deletions src/components/sortableList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ export interface SortableListProps<ItemT extends SortableListItemProps>
* (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)
*/
enableHaptic?: boolean;
/**
* Extra props for the item
*/
itemProps?: {margins?: {marginTop?: number; marginBottom?: number; marginLeft?: number; marginRight?: number}};
}

0 comments on commit c56e413

Please sign in to comment.