Skip to content

Commit 5a680d8

Browse files
authored
Remove unnecessary throw (#2446)
## Description Removes redundant `throw` as it was inside `try...catch` anyway.
1 parent a8d17fa commit 5a680d8

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

src/handlers/gestures/reanimatedWrapper.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,28 @@ let Reanimated: {
2929

3030
try {
3131
Reanimated = require('react-native-reanimated');
32+
} catch (e) {
33+
// When 'react-native-reanimated' is not available we want to quietly continue
34+
// @ts-ignore TS demands the variable to be initialized
35+
Reanimated = undefined;
36+
}
3237

33-
if (!Reanimated.useSharedValue) {
34-
// @ts-ignore Make sure the loaded module is actually Reanimated, if it's not
35-
// reset the module to undefined so we can fallback to the default implementation
36-
Reanimated = undefined;
37-
throw new Error('react-native-reanimated is not found');
38-
}
38+
if (!Reanimated?.useSharedValue) {
39+
// @ts-ignore Make sure the loaded module is actually Reanimated, if it's not
40+
// reset the module to undefined so we can fallback to the default implementation
41+
Reanimated = undefined;
42+
}
3943

40-
if (!Reanimated.setGestureState) {
41-
Reanimated.setGestureState = () => {
42-
'worklet';
43-
console.warn(
44-
tagMessage(
45-
'Please use newer version of react-native-reanimated in order to control state of the gestures.'
46-
)
47-
);
48-
};
49-
}
50-
// When 'react-native-reanimated' is not available we want to
51-
// quietly continue
52-
// eslint-disable-next-line no-empty
53-
} catch (e) {}
44+
if (Reanimated !== undefined && !Reanimated.setGestureState) {
45+
// The loaded module is Reanimated but it doesn't have the setGestureState defined
46+
Reanimated.setGestureState = () => {
47+
'worklet';
48+
console.warn(
49+
tagMessage(
50+
'Please use newer version of react-native-reanimated in order to control state of the gestures.'
51+
)
52+
);
53+
};
54+
}
5455

5556
export { Reanimated };

0 commit comments

Comments
 (0)