Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { faGripVertical } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome';
import { useCallback, useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Animated, { useAnimatedRef } from 'react-native-reanimated';
import Animated, {
LinearTransition,
useAnimatedRef
} from 'react-native-reanimated';
import type { OverDrag, SortableGridRenderItem } from 'react-native-sortables';
import Sortable from 'react-native-sortables';

Expand All @@ -25,12 +28,14 @@ export default function DragHandleExample() {

const renderItem = useCallback<SortableGridRenderItem<string>>(
({ item }) => (
<View style={styles.card}>
<Animated.View layout={LinearTransition} style={styles.card}>
<Text style={styles.text}>{item}</Text>
<Sortable.Handle>
<FontAwesomeIcon color={colors.white} icon={faGripVertical} />
</Sortable.Handle>
</View>
<Animated.View layout={LinearTransition}>
<Sortable.Handle>
<FontAwesomeIcon color={colors.white} icon={faGripVertical} />
</Sortable.Handle>
</Animated.View>
</Animated.View>
),
[]
);
Expand Down
12 changes: 6 additions & 6 deletions packages/react-native-sortables/src/components/SortableGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ function SortableGrid<I>(props: SortableGridProps<I>) {
if (!isVertical && !rowHeight) {
throw error('rowHeight is required for horizontal Sortable.Grid');
}

// this allows changing the number of columns/rows while developing
// code with no necessity to reload the app
// (state of the grid must be reset when this param changes)
const key = (groups << 1) | (isVertical ? 1 : 0);
if (columns !== undefined && columns < 1) {
throw error('columns must be greater than 0');
}
if (rows !== undefined && rows < 1) {
throw error('rows must be greater than 0');
}

const columnGapValue = useAnimatableValue(columnGap);
const rowGapValue = useAnimatableValue(rowGap);
Expand All @@ -88,7 +89,6 @@ function SortableGrid<I>(props: SortableGridProps<I>) {
{...sharedProps}
controlledContainerDimensions={controlledContainerDimensions}
itemKeys={itemKeys}
key={key}
initialItemsStyleOverride={
isVertical ? undefined : styles.horizontalStyleOverride
}
Expand Down