Skip to content

Feat/ SortableList - add ItemMargin prop #2561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}};
}