-
-
Notifications
You must be signed in to change notification settings - Fork 963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unnecessary throw
#2446
Remove unnecessary throw
#2446
Conversation
@@ -34,7 +34,6 @@ try { | |||
// @ts-ignore Make sure the loaded module is actually Reanimated, if it's not | |||
// reset the module to undefined so we can fallback to the default implementation | |||
Reanimated = undefined; | |||
throw new Error('react-native-reanimated is not found'); | |||
} | |||
|
|||
if (!Reanimated.setGestureState) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without throw new Error
here the execution will continue. In the previous line, we assigned Reanimated = undefined
and in the following line we have a check !Reanimated.setGestureState
. If Reanimated
is undefined, this check will fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thing you've caught it 😅. I've put the code that followed the throw into the else branch so it should be clearer now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, the current flow looks even more complicated. What about the following?
try {
Reanimated = require('react-native-reanimated');
} catch (e) {
// When 'react-native-reanimated' is not available we want to
// quietly continue
}
if (!Reanimated?.useSharedValue) {
// @ts-ignore Make sure the loaded module is actually Reanimated, if it's not
// reset the module to undefined so we can fallback to the default implementation
Reanimated = undefined;
}
if (!Reanimated?.setGestureState) {
Reanimated.setGestureState = () => {
'worklet';
console.warn(
tagMessage(
'Please use newer version of react-native-reanimated in order to control state of the gestures.'
)
);
};
}
export { Reanimated };
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about something like this:
try {
Reanimated = require('react-native-reanimated');
} catch (e) {
// When 'react-native-reanimated' is not available we want to quietly continue
// @ts-ignore TS demands the variable to be initialized
Reanimated = undefined;
}
if (!Reanimated?.useSharedValue) {
// @ts-ignore Make sure the loaded module is actually Reanimated, if it's not
// reset the module to undefined so we can fallback to the default implementation
Reanimated = undefined;
} else if (!Reanimated?.setGestureState) {
// The loaded module is Reanimated but it doesn't have the setGestureState defined
Reanimated.setGestureState = () => {
'worklet';
console.warn(
tagMessage(
'Please use newer version of react-native-reanimated in order to control state of the gestures.'
)
);
};
}
export { Reanimated };
In your snippet, the execution continues after the first if
and we're back where we've started 😅.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. What I really meant was if (Reanimated !== undefined && !Reanimated.setGestureState)
which roughly translates to "when Reanimated is installed but doesn't have setGestureState" but else
is okay too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this is a nice place to use IIFE and early returns.
…400) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [react-native-gesture-handler](https://togithub.com/software-mansion/react-native-gesture-handler) | [`~2.9.0` -> `~2.11.0`](https://renovatebot.com/diffs/npm/react-native-gesture-handler/2.9.0/2.11.0) | [![age](https://badges.renovateapi.com/packages/npm/react-native-gesture-handler/2.11.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/react-native-gesture-handler/2.11.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/react-native-gesture-handler/2.11.0/compatibility-slim/2.9.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/react-native-gesture-handler/2.11.0/confidence-slim/2.9.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>software-mansion/react-native-gesture-handler</summary> ### [`v2.11.0`](https://togithub.com/software-mansion/react-native-gesture-handler/releases/tag/2.11.0) [Compare Source](https://togithub.com/software-mansion/react-native-gesture-handler/compare/2.10.2...2.11.0) A small release made for nice people at Expo 😃. #### 🐛 Bug fixes - Correctly attach root view recognizer in modals on iOS by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2498 **Full Changelog**: software-mansion/react-native-gesture-handler@2.10.2...2.11.0 ### [`v2.10.2`](https://togithub.com/software-mansion/react-native-gesture-handler/releases/tag/2.10.2) [Compare Source](https://togithub.com/software-mansion/react-native-gesture-handler/compare/2.10.1...2.10.2) #### 🐛 Bug fixes - Fix root view error for jest by [@​IvanIhnatsiuk](https://togithub.com/IvanIhnatsiuk) in [software-mansion/react-native-gesture-handler#2491 - Prevent GH buttons from activating when scrolling list by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2494 #### New Contributors - [@​IvanIhnatsiuk](https://togithub.com/IvanIhnatsiuk) made their first contribution in [software-mansion/react-native-gesture-handler#2491 **Full Changelog**: software-mansion/react-native-gesture-handler@2.10.1...2.10.2 ### [`v2.10.1`](https://togithub.com/software-mansion/react-native-gesture-handler/releases/tag/2.10.1) [Compare Source](https://togithub.com/software-mansion/react-native-gesture-handler/compare/2.10.0...2.10.1) #### 🐛 Bug fixes - Fix operation scheduling on iOS by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2483 ### [`v2.10.0`](https://togithub.com/software-mansion/react-native-gesture-handler/releases/tag/2.10.0) [Compare Source](https://togithub.com/software-mansion/react-native-gesture-handler/compare/2.9.0...2.10.0) #### ❗ Important changes - Enable the new web implementation by default by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2394 - Replace `setImmediate` and `requestAnimationFrame` with `queueMicrotask` by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2467 - Show error when gestures are used without root view by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2420 - Change how velocity is calculated on the new web implementation by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2443 #### 🐛 Bug fixes - Fix types for gestureHandlerRootHOC to accept component with props by [@​Nodonisko](https://togithub.com/Nodonisko) in [software-mansion/react-native-gesture-handler#2413 - Remove `DrawerLayoutAndroid` import on web by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2305 - Fix ripple always showing on Touchables when on Android 13 by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2418 - Whitelist `Native` gesture props in `GestureDetector` by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2433 - Fix Gesture Handlers getting stuck due to missing `up` event when using the new web implementation by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2442 - Fix Gesture Handler's buttons activating after scroll when using `RefreshControl` by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2457 - Make single instance assertion work with Gradle Configuration Cache by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2453 - fix: PureNativeButton is not exported by [@​magrinj](https://togithub.com/magrinj) in [software-mansion/react-native-gesture-handler#2447 - fix: do not apply namespace if it is not available in agp by [@​WoLewicki](https://togithub.com/WoLewicki) in [software-mansion/react-native-gesture-handler#2448 #### 👍 Improvements - Returns Swipeable reference on renderLeftActions by [@​ntocampos](https://togithub.com/ntocampos) in [software-mansion/react-native-gesture-handler#2426 - Add a method `reset` to component `Swipeable` by [@​UNIDY2002](https://togithub.com/UNIDY2002) in [software-mansion/react-native-gesture-handler#2431 - Remove conditional imports for native components by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2461 - Add `dragOffsetFromLeftEdge` and `dragOffsetFromRightEdge` props to `Swipeable` by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2408 #### 🔢 Miscellaneous - Bump ua-parser-js from 0.7.31 to 0.7.33 by [@​dependabot](https://togithub.com/dependabot) in [software-mansion/react-native-gesture-handler#2392 - Bump ua-parser-js from 0.7.24 to 0.7.33 in /docs by [@​dependabot](https://togithub.com/dependabot) in [software-mansion/react-native-gesture-handler#2389 - Hide `back-to-top` button in the docs by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2398 - Upgrade Expo in the example app to use API 47 by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2393 - chore: change fabric flag by [@​WoLewicki](https://togithub.com/WoLewicki) in [software-mansion/react-native-gesture-handler#2397 - Bump http-cache-semantics from 4.1.0 to 4.1.1 in /docs by [@​dependabot](https://togithub.com/dependabot) in [software-mansion/react-native-gesture-handler#2407 - Bump http-cache-semantics from 4.1.0 to 4.1.1 by [@​dependabot](https://togithub.com/dependabot) in [software-mansion/react-native-gesture-handler#2406 - End-to-end tests for web version by [@​m-bert](https://togithub.com/m-bert) in [software-mansion/react-native-gesture-handler#2298 - Bump ua-parser-js from 0.7.32 to 0.7.33 in /e2e/web-tests by [@​dependabot](https://togithub.com/dependabot) in [software-mansion/react-native-gesture-handler#2417 - Bump loader-utils from 1.4.0 to 1.4.2 in /e2e/web-tests by [@​dependabot](https://togithub.com/dependabot) in [software-mansion/react-native-gesture-handler#2416 - Bump decode-uri-component from 0.2.0 to 0.2.2 in /e2e/web-tests by [@​dependabot](https://togithub.com/dependabot) in [software-mansion/react-native-gesture-handler#2415 - Add `Handler state` section to sidebar by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2422 - Bump webpack from 5.73.0 to 5.76.1 in /docs by [@​dependabot](https://togithub.com/dependabot) in [software-mansion/react-native-gesture-handler#2436 - chore: set library namespace in build script by [@​kkafar](https://togithub.com/kkafar) in [software-mansion/react-native-gesture-handler#2435 - docs: add appjs banner by [@​kacperkapusciak](https://togithub.com/kacperkapusciak) in [software-mansion/react-native-gesture-handler#2432 - Bump [@​xmldom/xmldom](https://togithub.com/xmldom/xmldom) from 0.7.6 to 0.7.9 in /e2e/web-tests by [@​dependabot](https://togithub.com/dependabot) in [software-mansion/react-native-gesture-handler#2444 - Bump [@​sideway/formula](https://togithub.com/sideway/formula) from 3.0.0 to 3.0.1 in /e2e/web-tests by [@​dependabot](https://togithub.com/dependabot) in [software-mansion/react-native-gesture-handler#2445 - Bump minimist from 1.2.5 to 1.2.8 in /example by [@​dependabot](https://togithub.com/dependabot) in [software-mansion/react-native-gesture-handler#2456 - Move `GestureHandlerRootView` to `components` directory by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2468 - Remove unnecessary `throw` by [@​j-piasecki](https://togithub.com/j-piasecki) in [software-mansion/react-native-gesture-handler#2446 #### New Contributors - [@​Nodonisko](https://togithub.com/Nodonisko) made their first contribution in [software-mansion/react-native-gesture-handler#2413 - [@​ntocampos](https://togithub.com/ntocampos) made their first contribution in [software-mansion/react-native-gesture-handler#2426 - [@​UNIDY2002](https://togithub.com/UNIDY2002) made their first contribution in [software-mansion/react-native-gesture-handler#2431 - [@​magrinj](https://togithub.com/magrinj) made their first contribution in [software-mansion/react-native-gesture-handler#2447 **Full Changelog**: software-mansion/react-native-gesture-handler@2.9.0...2.10.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/dooboolab-community/dooboo-ui). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMTAuMCIsInVwZGF0ZWRJblZlciI6IjM1LjExMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Description
Removes redundant
throw
as it was insidetry...catch
anyway.