Skip to content

Commit 626b4c4

Browse files
committed
chore: cleanup
1 parent 23a179c commit 626b4c4

2 files changed

Lines changed: 13 additions & 15 deletions

File tree

package/src/components/UIComponents/SwipableWrapper.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import ReanimatedSwipeable, {
1616

1717
import { useSwipeRegistryContext } from '../../contexts/swipeableContext/SwipeRegistryContext';
1818

19-
const ACTION_WIDTH = 50;
19+
const ACTION_WIDTH = 80;
2020
const DEFAULT_RIGHT_ACTIONS_WIDTH = ACTION_WIDTH * 2;
2121

2222
const animationOptions = {
@@ -53,12 +53,6 @@ export const SwipableWrapper = ({ children, swipeableId, swipableProps }: Swipab
5353
const swipeRegistry = useSwipeRegistryContext();
5454
const swipeableRef = useRef<SwipeableMethods | null>(null);
5555

56-
const {
57-
onSwipeableWillOpen: onSwipeableWillOpenFromProps,
58-
renderRightActions: renderRightActionsFromProps,
59-
...restSwipableProps
60-
} = swipableProps ?? {};
61-
6256
const defaultRenderRightActions = useCallback(
6357
(_progress: SharedValue<number>, translation: SharedValue<number>) => (
6458
<DefaultRightActions translation={translation} />
@@ -81,9 +75,9 @@ export const SwipableWrapper = ({ children, swipeableId, swipableProps }: Swipab
8175
if (swipeRegistry && swipeableId) {
8276
swipeRegistry.notifyWillOpen(swipeableId);
8377
}
84-
onSwipeableWillOpenFromProps?.(direction);
78+
swipableProps?.onSwipeableWillOpen?.(direction);
8579
},
86-
[onSwipeableWillOpenFromProps, swipeRegistry, swipeableId],
80+
[swipableProps, swipeRegistry, swipeableId],
8781
);
8882

8983
return (
@@ -96,8 +90,8 @@ export const SwipableWrapper = ({ children, swipeableId, swipableProps }: Swipab
9690
overshootRight={true}
9791
overshootFriction={16}
9892
renderLeftActions={undefined}
99-
renderRightActions={renderRightActionsFromProps ?? defaultRenderRightActions}
100-
{...restSwipableProps}
93+
renderRightActions={defaultRenderRightActions}
94+
{...swipableProps}
10195
>
10296
{children}
10397
</ReanimatedSwipeable>

package/src/contexts/swipeableContext/SwipeRegistryContext.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,25 @@ type SwipeRegistryContextValue = {
1717
const SwipeRegistryContext = createContext<SwipeRegistryContextValue | undefined>(undefined);
1818

1919
export const SwipeRegistryProvider = ({ children }: PropsWithChildren) => {
20-
const swipeablesRef = useRef<Map<string, CloseSwipeable>>(new Map());
20+
const swipeablesRef = useRef<Map<string, CloseSwipeable> | undefined>(undefined);
2121

2222
const registerSwipeable = useCallback((id: string, close: CloseSwipeable) => {
23+
if (!swipeablesRef.current) {
24+
swipeablesRef.current = new Map();
25+
}
26+
2327
swipeablesRef.current.set(id, close);
2428

2529
return () => {
26-
const registered = swipeablesRef.current.get(id);
30+
const registered = swipeablesRef.current?.get(id);
2731
if (registered === close) {
28-
swipeablesRef.current.delete(id);
32+
swipeablesRef.current?.delete(id);
2933
}
3034
};
3135
}, []);
3236

3337
const notifyWillOpen = useCallback((id: string) => {
34-
for (const [registeredId, close] of swipeablesRef.current.entries()) {
38+
for (const [registeredId, close] of swipeablesRef.current?.entries() ?? []) {
3539
if (registeredId !== id) {
3640
close();
3741
}

0 commit comments

Comments
 (0)