Skip to content

Commit ab6435b

Browse files
authored
chore: Organize third party dep helpers (#412)
## Description This PR moves `react-native-reanimated` and `react-native-haptic-feedback` helpers from the common `hooks` and `utils` dirs to the separate `integrations` directory.
1 parent 69ad8a6 commit ab6435b

62 files changed

Lines changed: 185 additions & 191 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/react-native-sortables/src/components/SortableGrid.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import type { SharedValue } from 'react-native-reanimated';
44
import { useAnimatedStyle, useDerivedValue } from 'react-native-reanimated';
55

66
import { DEFAULT_SORTABLE_GRID_PROPS } from '../constants';
7-
import { useAnimatableValue, useDragEndHandler } from '../hooks';
7+
import { useDragEndHandler } from '../hooks';
8+
import { useAnimatableValue } from '../integrations/reanimated';
89
import {
910
GRID_STRATEGIES,
1011
GridLayoutProvider,

packages/react-native-sortables/src/components/shared/DraggableView/ActiveItemPortal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {
55
useAnimatedReaction
66
} from 'react-native-reanimated';
77

8+
import { useMutableValue } from '../../../integrations/reanimated';
89
import { usePortalContext } from '../../../providers';
9-
import { useMutableValue } from '../../../utils';
1010

1111
type ActiveItemPortalProps = PropsWithChildren<{
1212
teleportedItemId: string;

packages/react-native-sortables/src/components/shared/DraggableView/DraggableView.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ import { Fragment, memo, useEffect, useState } from 'react';
33
import { GestureDetector } from 'react-native-gesture-handler';
44
import {
55
LayoutAnimationConfig,
6+
runOnUI,
67
useDerivedValue
78
} from 'react-native-reanimated';
89

10+
import type {
11+
AnimatedStyleProp,
12+
LayoutAnimation
13+
} from '../../../integrations/reanimated';
14+
import { useMutableValue } from '../../../integrations/reanimated';
915
import {
1016
CommonValuesContext,
1117
ItemContextProvider,
@@ -15,8 +21,7 @@ import {
1521
useMeasurementsContext,
1622
usePortalContext
1723
} from '../../../providers';
18-
import type { AnimatedStyleProp, LayoutAnimation } from '../../../types';
19-
import { getContextProvider, useMutableValue } from '../../../utils';
24+
import { getContextProvider } from '../../../utils';
2025
import ActiveItemPortal from './ActiveItemPortal';
2126
import ItemCell from './ItemCell';
2227
import TeleportedItemCell from './TeleportedItemCell';
@@ -50,9 +55,10 @@ function DraggableView({
5055
const itemStyles = useItemStyles(key, isActive, activationAnimationProgress);
5156
const gesture = useItemPanGesture(key, activationAnimationProgress);
5257

53-
useEffect(() => {
54-
return () => removeItemMeasurements(key);
55-
}, [key, removeItemMeasurements]);
58+
useEffect(
59+
() => runOnUI(removeItemMeasurements)(key),
60+
[key, removeItemMeasurements]
61+
);
5662

5763
useEffect(() => {
5864
if (!portalContext) {

packages/react-native-sortables/src/components/shared/DraggableView/ItemCell.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import Animated from 'react-native-reanimated';
99

1010
import type {
1111
AnimatedStyleProp,
12-
LayoutAnimation,
13-
MeasureCallback
14-
} from '../../../types';
12+
LayoutAnimation
13+
} from '../../../integrations/reanimated';
14+
import type { MeasureCallback } from '../../../types';
1515
import AnimatedOnLayoutView from '../AnimatedOnLayoutView';
1616

1717
export type ItemCellProps = PropsWithChildren<{

packages/react-native-sortables/src/components/shared/DraggableView/TeleportedItemCell.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import type { PropsWithChildren } from 'react';
22
import type { SharedValue } from 'react-native-reanimated';
33
import { LayoutAnimationConfig } from 'react-native-reanimated';
44

5+
import type { AnimatedStyleProp } from '../../../integrations/reanimated';
56
import { useTeleportedItemStyles } from '../../../providers';
6-
import type { AnimatedStyleProp, MeasureCallback } from '../../../types';
7+
import type { MeasureCallback } from '../../../types';
78
import ItemCell from './ItemCell';
89

910
type TeleportedItemCellProps = PropsWithChildren<{

packages/react-native-sortables/src/components/shared/DropIndicator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import Animated, {
1111
withTiming
1212
} from 'react-native-reanimated';
1313

14+
import { useMutableValue } from '../../integrations/reanimated';
1415
import { useCommonValuesContext } from '../../providers';
1516
import type {
1617
Dimensions,
1718
DropIndicatorComponentProps,
1819
Vector
1920
} from '../../types';
20-
import { useMutableValue } from '../../utils';
2121

2222
const DEFAULT_STYLE: ViewStyle = {
2323
opacity: 0

packages/react-native-sortables/src/constants/props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { ViewStyle } from 'react-native';
22

33
import { DefaultDropIndicator } from '../components/defaults';
4+
import type { DefaultProps } from '../helperTypes';
45
import type {
5-
DefaultProps,
66
SharedProps,
77
SortableCallbacks,
88
SortableFlexProps,
Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
31
import type { SharedValue } from 'react-native-reanimated';
42

3+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
54
export type AnyFunction = (...args: Array<any>) => any;
65

6+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
77
export type AnyRecord = Record<string, any>;
88

99
export type Simplify<T> = {
1010
[K in keyof T]: T[K];
1111
} & {};
1212

13-
export type Animatable<V> = SharedValue<V> | V;
14-
15-
type UnAnimatable<V> = V extends SharedValue<infer U> ? U : V;
16-
17-
export type AnimatableProps<T extends Record<string, any>> = {
18-
[K in keyof T]: Animatable<UnAnimatable<T[K]>>;
19-
};
20-
21-
export type AnimatedValues<T extends Record<string, any>> = {
22-
[K in keyof T]: SharedValue<UnAnimatable<T[K]>>;
23-
};
24-
2513
type RequiredExcept<T, K extends keyof T> = Omit<Required<T>, K> & Pick<T, K>;
2614

2715
export type RequiredBy<T, K extends keyof T> = Omit<T, K> &
@@ -32,7 +20,7 @@ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
3220
export type Maybe<T> = null | T | undefined;
3321

3422
export type DefaultProps<
35-
P extends Record<string, any>,
23+
P extends AnyRecord,
3624
O extends keyof P = never, // optional props
3725
E extends keyof P = never // exclude from default props (must be passed by the user)
3826
> = Omit<RequiredExcept<P, O>, E>;
@@ -44,7 +32,7 @@ type ReadonlySharedValue<V> = Readonly<Omit<SharedValue<V>, 'set'>>;
4432
export type DeepReadonly<T> = {
4533
readonly [K in keyof T]: T[K] extends SharedValue<infer U>
4634
? ReadonlySharedValue<U>
47-
: T[K] extends Record<string, any>
35+
: T[K] extends AnyRecord
4836
? DeepReadonly<T[K]>
4937
: Readonly<T[K]>;
5038
};

packages/react-native-sortables/src/hooks/callbacks/useDebouncedStableCallback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useRef } from 'react';
22

3-
import type { AnyFunction } from '../../types';
3+
import type { AnyFunction } from '../../helperTypes';
44
import useStableCallback from './useStableCallback';
55

66
export default function useDebouncedStableCallback<C extends AnyFunction>(

packages/react-native-sortables/src/hooks/callbacks/useStableCallback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useCallback, useEffect, useRef } from 'react';
22

3-
import type { AnyFunction } from '../../types';
3+
import type { AnyFunction } from '../../helperTypes';
44

55
export default function useStableCallback<C extends AnyFunction>(callback: C) {
66
const callbackRef = useRef(callback);

0 commit comments

Comments
 (0)