Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
c982c0a
rename new swipeable component
latekvo Jun 10, 2024
74e2519
move and configure new swipeable
latekvo Jun 10, 2024
f27a4d5
Merge branch 'main' into @latekvo/add_reanimated_swipeable_row_compon…
latekvo Jun 11, 2024
56d35cb
fix linter issues
latekvo Jun 11, 2024
80a4acb
fix linter issues example
latekvo Jun 11, 2024
3e8dea7
add ReanimatedSwipeable to all relevant configuration files
latekvo Jun 11, 2024
ba1e9c6
add missing deps to animated styles
latekvo Jun 11, 2024
acd6e04
reset and recommit only essential changes
latekvo Jun 11, 2024
ea3eb3c
Merge branch '@latekvo/add_reanimated_swipeable_row_componenet' of ht…
latekvo Jun 11, 2024
b0a3ee2
remove reanimated instances in example config files
latekvo Jun 11, 2024
5cd05b9
break down animateRow
latekvo Jun 12, 2024
61c9d6e
Merge branch 'main' into @latekvo/add_reanimated_swipeable_row_compon…
latekvo Jun 12, 2024
f3931cf
break swipeableMethods dependancy loop
latekvo Jun 12, 2024
436e19c
fix example paths
latekvo Jun 12, 2024
3956f6d
remove unnecessary hook
latekvo Jun 12, 2024
443b5b2
remove unncessary ref
latekvo Jun 12, 2024
de9d392
fix spelling and imports
latekvo Jun 13, 2024
54041e8
deworkletize event dispatchers
latekvo Jun 13, 2024
07dbf17
fix invalid event dispatching logic
latekvo Jun 13, 2024
8db96e1
Merge branch 'main' into @latekvo/add_reanimated_swipeable_row_compon…
latekvo Jun 13, 2024
9c8450d
remove unnecessary typing
latekvo Jun 13, 2024
19916a7
add missing prop dep
latekvo Jun 13, 2024
6db0442
Merge branch '@latekvo/add_reanimated_swipeable_row_componenet' of ht…
latekvo Jun 13, 2024
85cca23
fix eslint warning in example
latekvo Jun 14, 2024
3966857
remove invalid file reference in tsconfig
latekvo Jun 14, 2024
2988d18
Merge branch 'main' into @latekvo/add_reanimated_swipeable_row_compon…
latekvo Jun 14, 2024
57b9c0f
disable 2 eslint warnings in ReanimatedSwipeable after confirming the…
latekvo Jun 14, 2024
1553a69
remove index import in favour of direct imports
latekvo Jun 14, 2024
afcd3fd
fix invalid prop access bug on mobile devices
latekvo Jun 17, 2024
b52b90f
align styling with the original
latekvo Jun 17, 2024
49111f1
fix config to transpile with correct path
latekvo Jun 17, 2024
88d906f
remove unnecessary config
latekvo Jun 17, 2024
04d521c
Merge branch 'main' into @latekvo/add_reanimated_swipeable_row_compon…
latekvo Jun 17, 2024
d9375d8
align touch detection box with the original
latekvo Jun 17, 2024
ea8f3cb
match spring characteristics with the original
latekvo Jun 17, 2024
c56f284
make returned progression continous, as per the original
latekvo Jun 17, 2024
98a6e25
Merge branch 'main' into @latekvo/add_reanimated_swipeable_row_compon…
latekvo Jun 17, 2024
3a75ce0
linter issue
latekvo Jun 17, 2024
b9b1b8a
add example comparing old and the new system
latekvo Jun 17, 2024
001b9e7
change naming scheme in transition example
latekvo Jun 18, 2024
6b894ff
fix random width bug
latekvo Jun 18, 2024
9f56020
make example items identical
latekvo Jun 18, 2024
a65d3b4
add swipe-back mechanic
latekvo Jun 18, 2024
c8d4e24
replace setting all remainingProps with an Extract type cast
latekvo Jun 18, 2024
50c3050
rename imports in example
latekvo Jun 18, 2024
3a11c51
remove unnecessary styling
latekvo Jun 18, 2024
d5c5281
Merge branch 'main' into @latekvo/add_reanimated_swipeable_row_compon…
latekvo Jun 18, 2024
37555fe
fix linting errors
latekvo Jun 18, 2024
f89c9c8
remove unnecessary prop extraction, add trackpad gesture support
latekvo Jun 18, 2024
7f70964
remove unnecessary useNativeAnimations prop
latekvo Jun 18, 2024
7868300
Merge branch 'main' into @latekvo/add_reanimated_swipeable_row_compon…
latekvo Jun 18, 2024
8e9b28d
rename imports in transition example
latekvo Jun 18, 2024
373e5a6
Merge branch '@latekvo/add_reanimated_swipeable_row_componenet' of ht…
latekvo Jun 18, 2024
5e56c6d
enable touchAction for tap gesture
latekvo Jun 19, 2024
4b66ca4
remove linter comments
latekvo Jun 19, 2024
c8e9fd9
remove unnecessary rect buttons
latekvo Jun 20, 2024
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
4 changes: 1 addition & 3 deletions FabricExample/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
"react-native-gesture-handler/DrawerLayout": [
"../src/components/DrawerLayout.tsx"
],
"react-native-gesture-handler/jest-utils": [
"../src/jestUtils/index.ts"
]
"react-native-gesture-handler/jest-utils": ["../src/jestUtils/index.ts"]
}
},
"include": ["src/**/*.ts", "src/**/*.tsx", "index.js"]
Expand Down
4 changes: 1 addition & 3 deletions MacOSExample/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
"react-native-gesture-handler/DrawerLayout": [
"../src/components/DrawerLayout.tsx"
],
"react-native-gesture-handler/jest-utils": [
"../src/jestUtils/index.ts"
]
"react-native-gesture-handler/jest-utils": ["../src/jestUtils/index.ts"]
}
}
}
6 changes: 6 additions & 0 deletions ReanimatedSwipeable/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"main": "../lib/commonjs/components/ReanimatedSwipeable",
"module": "../lib/module/components/ReanimatedSwipeable",
"react-native": "../src/components/ReanimatedSwipeable",
"types": "../lib/typescript/components/ReanimatedSwipeable.d.ts"
}
2 changes: 2 additions & 0 deletions e2e/web-tests/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module.exports = function (api) {
'../../src/components/DrawerLayout',
'react-native-gesture-handler/Swipeable':
'../../src/components/Swipeable',
'react-native-gesture-handler/ReanimatedSwipeable':
'../../src/components/ReanimatedSwipeable',
'react-native-gesture-handler': '../../src/index',
},
},
Expand Down
4 changes: 2 additions & 2 deletions e2e/web-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
// "extends": "expo/tsconfig.base",
"extends": "../../tsconfig.json",
"compilerOptions": {
"compilerOptions": {
// "strict": true,
"baseUrl": ".",
"paths": {
Expand All @@ -15,7 +15,7 @@
"react-native-gesture-handler/jest-utils": [
"../../src/jestUtils/index.ts"
],
"react": ["./node_modules/@types/react"],
"react": ["./node_modules/@types/react"]
}
},
"include": ["./tests/*.ts", "./components/*.tsx", "./App.tsx"]
Expand Down
12 changes: 7 additions & 5 deletions example/src/new_api/swipeable/AppleStyleSwipeableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import Animated, {
interpolate,
useAnimatedStyle,
} from 'react-native-reanimated';
import Swipeable, { SwipeableMethods } from 'src/new_api/swipeable/Swipeable';
import Swipeable, {
SwipeableMethods,
} from '../../../../src/components/ReanimatedSwipeable';

interface AppleStyleSwipeableRowProps {
children?: ReactNode;
Expand Down Expand Up @@ -135,16 +137,16 @@ export default function AppleStyleSwipeableRow({
enableTrackpadTwoFingerGesture
leftThreshold={30}
rightThreshold={40}
renderLeftActions={(_, progress) =>
renderLeftActions={(_: any, progress: SharedValue<number>) =>
renderLeftActions(_, progress, swipeableRow)
}
renderRightActions={(_, progress) =>
renderRightActions={(_: any, progress: SharedValue<number>) =>
renderRightActions(_, progress, swipeableRow)
}
onSwipeableWillOpen={(direction) => {
onSwipeableWillOpen={(direction: any) => {
console.log(`Opening swipeable from the ${direction}`);
}}
onSwipeableWillClose={(direction) => {
onSwipeableWillClose={(direction: any) => {
console.log(`Closing swipeable to the ${direction}`);
}}>
{children}
Expand Down
8 changes: 5 additions & 3 deletions example/src/new_api/swipeable/GmailStyleSwipeableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import Animated, {
interpolate,
useAnimatedStyle,
} from 'react-native-reanimated';
import Swipeable, { SwipeableMethods } from 'src/new_api/swipeable/Swipeable';
import Swipeable, {
SwipeableMethods,
} from '../../../../src/components/ReanimatedSwipeable';

interface LeftActionProps {
dragX: SharedValue<number>;
Expand Down Expand Up @@ -82,10 +84,10 @@ export default function GmailStyleSwipeableRow({
leftThreshold={80}
enableTrackpadTwoFingerGesture
rightThreshold={40}
renderLeftActions={(_, progress) =>
renderLeftActions={(_: any, progress: SharedValue<number>) =>
renderLeftActions(_, progress, swipeableRow)
}
renderRightActions={(_, progress) =>
renderRightActions={(_: any, progress: SharedValue<number>) =>
renderRightActions(_, progress, swipeableRow)
}>
{children}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"android/noreanimated/src/main/java/",
"apple/",
"Swipeable/",
"ReanimatedSwipeable/",
"jest-utils/",
"DrawerLayout/",
"README.md",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import React, {
ForwardedRef,
forwardRef,
useCallback,
useEffect,
useImperativeHandle,
useRef,
} from 'react';
Expand All @@ -17,7 +16,7 @@ import {
GestureUpdateEvent,
PanGestureHandlerEventPayload,
PanGestureHandlerProps,
} from 'react-native-gesture-handler';
} from '../.';
import Animated, {
Extrapolation,
SharedValue,
Expand Down Expand Up @@ -317,10 +316,41 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
);
};

const dispatchImmidiateEvents = useCallback(
(fromValue: number, toValue: number) => {
if (toValue > 0 && props.onSwipeableWillOpen) {
runOnJS(props.onSwipeableWillOpen)('left');
} else if (toValue < 0 && props.onSwipeableWillOpen) {
runOnJS(props.onSwipeableWillOpen)('right');
} else if (props.onSwipeableWillClose) {
const closingDirection = fromValue > 0 ? 'left' : 'right';
runOnJS(props.onSwipeableWillClose)(closingDirection);
}
},
[props.onSwipeableWillClose, props.onSwipeableWillOpen]
);

const dispatchEndEvents = useCallback(
(fromValue: number, toValue: number) => {
if (toValue > 0 && props.onSwipeableOpen) {
runOnJS(props.onSwipeableOpen)('left', swipeableMethods.current);
} else if (toValue < 0 && props.onSwipeableOpen) {
runOnJS(props.onSwipeableOpen)('right', swipeableMethods.current);
} else if (props.onSwipeableClose) {
const closingDirection = fromValue > 0 ? 'left' : 'right';
runOnJS(props.onSwipeableClose)(
closingDirection,
swipeableMethods.current
);
}
},
[props.onSwipeableClose, props.onSwipeableOpen]
);

const animateRow = useCallback(
(fromValue: number, toValue: number, velocityX?: number) => {
'worklet';

console.log('animatin');
rowState.value = Math.sign(toValue);

appliedTranslation.value = withSpring(
Expand All @@ -334,37 +364,20 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
},
(isFinished) => {
if (isFinished) {
if (toValue > 0 && props.onSwipeableOpen) {
runOnJS(props.onSwipeableOpen)(
'left',
swipeableMethods.current
);
} else if (toValue < 0 && props.onSwipeableOpen) {
runOnJS(props.onSwipeableOpen)(
'right',
swipeableMethods.current
);
} else if (props.onSwipeableClose) {
const closingDirection = fromValue > 0 ? 'left' : 'right';
runOnJS(props.onSwipeableClose)(
closingDirection,
swipeableMethods.current
);
}
dispatchEndEvents(fromValue, toValue);
}
}
);

if (toValue > 0 && props.onSwipeableWillOpen) {
runOnJS(props.onSwipeableWillOpen)('left');
} else if (toValue < 0 && props.onSwipeableWillOpen) {
runOnJS(props.onSwipeableWillOpen)('right');
} else if (props.onSwipeableWillClose) {
const closingDirection = fromValue > 0 ? 'left' : 'right';
runOnJS(props.onSwipeableWillClose)(closingDirection);
}
dispatchImmidiateEvents(fromValue, toValue);
},
[appliedTranslation, props, rowState, swipeableMethods]
[
appliedTranslation,
dispatchEndEvents,
dispatchImmidiateEvents,
props.animationOptions,
rowState,
]
);

const onRowLayout = ({ nativeEvent }: LayoutChangeEvent) => {
Expand All @@ -379,47 +392,39 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
dragOffsetFromRightEdge = 10,
} = props;

useEffect(() => {
swipeableMethods.current = {
close() {
'worklet';
animateRow(calculateCurrentOffset(), 0);
},
openLeft() {
'worklet';
animateRow(calculateCurrentOffset(), leftWidth.value);
},
openRight() {
'worklet';
rightWidth.value = rowWidth.value - rightOffset.value;
animateRow(calculateCurrentOffset(), -rightWidth.value);
},
reset() {
'worklet';
userDrag.value = 0;
appliedTranslation.value = 0;
rowState.value = 0;
},
};
}, [
animateRow,
calculateCurrentOffset,
appliedTranslation,
leftWidth,
rightOffset,
rightWidth,
rowState,
rowWidth,
userDrag,
]);
swipeableMethods.current = {
close() {
'worklet';
console.log('somethin');
animateRow(calculateCurrentOffset(), 0);
},
openLeft() {
'worklet';
animateRow(calculateCurrentOffset(), leftWidth.value);
},
openRight() {
'worklet';
rightWidth.value = rowWidth.value - rightOffset.value;
animateRow(calculateCurrentOffset(), -rightWidth.value);
},
reset() {
'worklet';
userDrag.value = 0;
appliedTranslation.value = 0;
rowState.value = 0;
},
};

const leftAnimatedStyle = useAnimatedStyle(() => ({
transform: [
{
translateX: leftActionTranslate.value,
},
],
}));
const leftAnimatedStyle = useAnimatedStyle(
() => ({
transform: [
{
translateX: leftActionTranslate.value,
},
],
}),
[leftActionTranslate]
);

const leftElement = renderLeftActions && (
<Animated.View style={[styles.leftActions, leftAnimatedStyle]}>
Expand All @@ -436,13 +441,16 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
</Animated.View>
);

const rightAnimatedStyle = useAnimatedStyle(() => ({
transform: [
{
translateX: rightActionTranslate.value,
},
],
}));
const rightAnimatedStyle = useAnimatedStyle(
() => ({
transform: [
{
translateX: rightActionTranslate.value,
},
],
}),
[rightActionTranslate]
);

const rightElement = renderRightActions && (
<Animated.View style={[styles.rightActions, rightAnimatedStyle]}>
Expand Down Expand Up @@ -530,9 +538,11 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
}
updateAnimatedEvent();
})
.onEnd((event) => {
handleRelease(event);
});
.onEnd(
(event: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
handleRelease(event);
}
);

panGesture.activeOffsetX([
-dragOffsetFromRightEdge,
Expand All @@ -544,10 +554,13 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
swipeableMethods,
]);

const animatedStyle = useAnimatedStyle(() => ({
transform: [{ translateX: appliedTranslation.value }],
pointerEvents: rowState.value === 0 ? 'auto' : 'box-only',
}));
const animatedStyle = useAnimatedStyle(
() => ({
transform: [{ translateX: appliedTranslation.value }],
pointerEvents: rowState.value === 0 ? 'auto' : 'box-only',
}),
[appliedTranslation, rowState]
);

const composedGesture = Gesture.Race(panGesture, tapGesture);
return (
Expand Down
7 changes: 6 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@
"noUnusedParameters": true,
"noUnusedLocals": true
},
"include": ["src/**/*.ts", "src/**/*.tsx", "jestSetup.js"],
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"jestSetup.js",
"Swipeable/Swipeable.tsx"
]
}