diff --git a/package.json b/package.json index 570c445c6..084c996c7 100644 --- a/package.json +++ b/package.json @@ -40,9 +40,7 @@ }, "dependencies": { "@gorhom/portal": "1.0.13", - "invariant": "^2.2.4", - "nanoid": "^3.3.3", - "react-native-redash": "^16.1.1" + "invariant": "^2.2.4" }, "devDependencies": { "@commitlint/cli": "^13.1.0", diff --git a/src/components/bottomSheetModal/BottomSheetModal.tsx b/src/components/bottomSheetModal/BottomSheetModal.tsx index 4198cf5d1..e0070c5ce 100644 --- a/src/components/bottomSheetModal/BottomSheetModal.tsx +++ b/src/components/bottomSheetModal/BottomSheetModal.tsx @@ -8,7 +8,6 @@ import React, { useState, } from 'react'; import { Portal, usePortal } from '@gorhom/portal'; -import { nanoid } from 'nanoid/non-secure'; import BottomSheet from '../bottomSheet'; import { useBottomSheetModalInternal } from '../../hooks'; import { print } from '../../utilities'; @@ -18,6 +17,7 @@ import { } from './constants'; import type { BottomSheetModalMethods, BottomSheetMethods } from '../../types'; import type { BottomSheetModalProps } from './types'; +import { id } from '../../utilities/id'; type BottomSheetModal = BottomSheetModalMethods; @@ -80,7 +80,7 @@ const BottomSheetModalComponent = forwardRef< //#endregion //#region variables - const key = useMemo(() => name || `bottom-sheet-modal-${nanoid()}`, [name]); + const key = useMemo(() => name || `bottom-sheet-modal-${id()}`, [name]); //#endregion //#region private methods diff --git a/src/hooks/useGestureEventsHandlersDefault.tsx b/src/hooks/useGestureEventsHandlersDefault.tsx index 89130a3e5..b44bfa510 100644 --- a/src/hooks/useGestureEventsHandlersDefault.tsx +++ b/src/hooks/useGestureEventsHandlersDefault.tsx @@ -1,6 +1,5 @@ import { Keyboard, Platform } from 'react-native'; import { runOnJS, useWorkletCallback } from 'react-native-reanimated'; -import { clamp, snapPoint } from 'react-native-redash'; import { useBottomSheetInternal } from './useBottomSheetInternal'; import { ANIMATION_SOURCE, @@ -13,6 +12,8 @@ import type { GestureEventsHandlersHookType, GestureEventHandlerCallbackType, } from '../types'; +import { clamp } from '../utilities/clamp'; +import { snapPoint } from '../utilities/snapPoint'; type GestureEventContextType = { initialPosition: number; diff --git a/src/utilities/clamp.ts b/src/utilities/clamp.ts new file mode 100644 index 000000000..6e0059504 --- /dev/null +++ b/src/utilities/clamp.ts @@ -0,0 +1,8 @@ +export const clamp = ( + value: number, + lowerBound: number, + upperBound: number +) => { + 'worklet'; + return Math.min(Math.max(lowerBound, value), upperBound); +}; diff --git a/src/utilities/id.ts b/src/utilities/id.ts new file mode 100644 index 000000000..2f106671d --- /dev/null +++ b/src/utilities/id.ts @@ -0,0 +1,6 @@ +let current = 0; + +export const id = () => { + current = (current + 1) % Number.MAX_SAFE_INTEGER; + return current; +}; diff --git a/src/utilities/snapPoint.ts b/src/utilities/snapPoint.ts new file mode 100644 index 000000000..1b99e1653 --- /dev/null +++ b/src/utilities/snapPoint.ts @@ -0,0 +1,11 @@ +export const snapPoint = ( + value: number, + velocity: number, + points: ReadonlyArray +): number => { + 'worklet'; + const point = value + 0.2 * velocity; + const deltas = points.map(p => Math.abs(point - p)); + const minDelta = Math.min.apply(null, deltas); + return points.filter(p => Math.abs(point - p) === minDelta)[0]; +}; diff --git a/yarn.lock b/yarn.lock index 320bf8393..89ac6c242 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2043,11 +2043,6 @@ abort-controller@^3.0.0: dependencies: event-target-shim "^5.0.0" -abs-svg-path@^0.1.1: - version "0.1.1" - resolved "https://registry.yarnpkg.com/abs-svg-path/-/abs-svg-path-0.1.1.tgz#df601c8e8d2ba10d4a76d625e236a9a39c2723bf" - integrity sha1-32Acjo0roQ1KdtYl4japo5wnI78= - absolute-path@^0.0.0: version "0.0.0" resolved "https://registry.yarnpkg.com/absolute-path/-/absolute-path-0.0.0.tgz#a78762fbdadfb5297be99b15d35a785b2f095bf7" @@ -6296,7 +6291,7 @@ nan@^2.12.1: resolved "https://registry.yarnpkg.com/nan/-/nan-2.15.0.tgz#3f34a473ff18e15c1b5626b62903b5ad6e665fee" integrity sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ== -nanoid@^3.3.1, nanoid@^3.3.3: +nanoid@^3.3.1: version "3.3.3" resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.3.tgz#fd8e8b7aa761fe807dba2d1b98fb7241bb724a25" integrity sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w== @@ -6416,13 +6411,6 @@ normalize-path@^3.0.0: resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65" integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA== -normalize-svg-path@^1.0.1: - version "1.1.0" - resolved "https://registry.yarnpkg.com/normalize-svg-path/-/normalize-svg-path-1.1.0.tgz#0e614eca23c39f0cffe821d6be6cd17e569a766c" - integrity sha512-r9KHKG2UUeB5LoTouwDzBy2VxXlHsiM6fyLQvnJa0S5hrhzqElH/CH7TUGhT1fVvIYBIKf3OpY4YJ4CK+iaqHg== - dependencies: - svg-arc-to-cubic-bezier "^3.0.0" - normalize-url@^4.1.0: version "4.5.1" resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-4.5.1.tgz#0dd90cf1288ee1d1313b87081c9a5932ee48518a" @@ -6776,11 +6764,6 @@ parse-path@^4.0.0: qs "^6.9.4" query-string "^6.13.8" -parse-svg-path@^0.1.2: - version "0.1.2" - resolved "https://registry.yarnpkg.com/parse-svg-path/-/parse-svg-path-0.1.2.tgz#7a7ec0d1eb06fa5325c7d3e009b859a09b5d49eb" - integrity sha1-en7A0esG+lMlx9PgCbhZoJtdSes= - parse-url@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/parse-url/-/parse-url-6.0.0.tgz#f5dd262a7de9ec00914939220410b66cff09107d" @@ -7146,15 +7129,6 @@ react-native-reanimated@^2.8.0: setimmediate "^1.0.5" string-hash-64 "^1.0.3" -react-native-redash@^16.1.1: - version "16.1.1" - resolved "https://registry.yarnpkg.com/react-native-redash/-/react-native-redash-16.1.1.tgz#784cdf55672043aab9f15ae8c965dcbae8b119ba" - integrity sha512-pD3GMNqRz/5bUnX0ni4MMOBlVwH2dJnd7u6M80VqYGI87IfcuP6Sn1z171r0nUUeYvJ7blJQs0OKKmTsJIbWew== - dependencies: - abs-svg-path "^0.1.1" - normalize-svg-path "^1.0.1" - parse-svg-path "^0.1.2" - react-native@^0.62.2: version "0.62.3" resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.62.3.tgz#9a2e96af3dedd0723c8657831eec4ed3c30f3299" @@ -8200,11 +8174,6 @@ supports-color@^7.1.0: dependencies: has-flag "^4.0.0" -svg-arc-to-cubic-bezier@^3.0.0: - version "3.2.0" - resolved "https://registry.yarnpkg.com/svg-arc-to-cubic-bezier/-/svg-arc-to-cubic-bezier-3.2.0.tgz#390c450035ae1c4a0104d90650304c3bc814abe6" - integrity sha512-djbJ/vZKZO+gPoSDThGNpKDO+o+bAeA4XQKovvkNCqnIS2t+S4qnLAGQhyyrulhCFRl1WWzAp0wUDV8PpTVU3g== - table@^6.0.9: version "6.7.1" resolved "https://registry.yarnpkg.com/table/-/table-6.7.1.tgz#ee05592b7143831a8c94f3cee6aae4c1ccef33e2"