Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
18 changes: 13 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"types": "lib/typescript/index.d.ts",
"react-native": "src/index.ts",
"source": "src/index.ts",
"files": ["src", "lib", "mock.js"],
"files": [
"src",
"lib",
"mock.js"
],
"keywords": [
"react-native",
"ios",
Expand Down Expand Up @@ -55,7 +59,7 @@
"react-native": "0.76.0",
"react-native-builder-bob": "^0.30.3",
"react-native-gesture-handler": "~2.20.2",
"react-native-reanimated": "~3.16.1",
"react-native-reanimated": ">=3.16.1 <5",
"release-it": "^17.6.0",
"typescript": "^5.3.0"
},
Expand All @@ -68,16 +72,20 @@
"react-native-reanimated": ">=3.16.0"
},
"peerDependenciesMeta": {
"@types/react-native": {
"@types/react": {
"optional": true
},
"@types/react": {
"@types/react-native": {
"optional": true
}
},
"react-native-builder-bob": {
"source": "src",
"output": "lib",
"targets": ["commonjs", "module", "typescript"]
"targets": [
"commonjs",
"module",
"typescript"
]
}
}
10 changes: 6 additions & 4 deletions src/components/bottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import Animated, {
Extrapolation,
runOnUI,
cancelAnimation,
useWorkletCallback,
type WithSpringConfig,
type WithTimingConfig,
type SharedValue,
useReducedMotion,
ReduceMotion,
} from 'react-native-reanimated';
import { useWorkletCallback } from '../../hooks/useWorkletCallback';
import {
ANIMATION_SOURCE,
ANIMATION_STATE,
Expand Down Expand Up @@ -86,9 +86,11 @@ import {
} from './constants';
import type { AnimateToPositionType, BottomSheetProps } from './types';

Animated.addWhitelistedUIProps({
decelerationRate: true,
});
if (typeof Animated?.addWhitelistedUIProps === 'function') {
Animated.addWhitelistedUIProps({
decelerationRate: true,
});
}

type BottomSheet = BottomSheetMethods;

Expand Down
4 changes: 3 additions & 1 deletion src/components/bottomSheetDebugView/ReText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ interface TextProps {

const AnimatedTextInput = Animated.createAnimatedComponent(TextInput);

Animated.addWhitelistedNativeProps({ text: true });
if (typeof Animated?.addWhitelistedNativeProps === 'function') {
Animated.addWhitelistedNativeProps({ text: true });
}

const ReText = (props: TextProps) => {
const { text, value: _providedValue, style } = { style: {}, ...props };
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useGestureEventsHandlersDefault.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Keyboard, Platform } from 'react-native';
import {
runOnJS,
useSharedValue,
useWorkletCallback,
useSharedValue
} from 'react-native-reanimated';
import { useWorkletCallback } from './useWorkletCallback';
import {
ANIMATION_SOURCE,
GESTURE_SOURCE,
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useGestureEventsHandlersDefault.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Keyboard, Platform } from 'react-native';
import {
runOnJS,
useSharedValue,
useWorkletCallback,
} from 'react-native-reanimated';
import { useWorkletCallback } from './useWorkletCallback';
import {
ANIMATION_SOURCE,
GESTURE_SOURCE,
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useGestureHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
State,
} from 'react-native-gesture-handler';
import type { SharedValue } from 'react-native-reanimated';
import { useWorkletCallback } from 'react-native-reanimated';
import { useWorkletCallback } from './useWorkletCallback';
import { GESTURE_SOURCE } from '../constants';
import type {
GestureEventHandlerCallbackType,
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useKeyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
import {
runOnUI,
useAnimatedReaction,
useSharedValue,
useWorkletCallback,
useSharedValue
} from 'react-native-reanimated';
import { useWorkletCallback } from './useWorkletCallback';
import { KEYBOARD_STATE, SCREEN_HEIGHT } from '../constants';

const KEYBOARD_EVENT_MAPPER = {
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useScrollEventsHandlersDefault.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { State } from 'react-native-gesture-handler';
import { scrollTo, useWorkletCallback } from 'react-native-reanimated';
import { scrollTo } from 'react-native-reanimated';
import { useWorkletCallback } from './useWorkletCallback';
import { ANIMATION_STATE, SCROLLABLE_STATE, SHEET_STATE } from '../constants';
import type {
ScrollEventHandlerCallbackType,
Expand Down
19 changes: 19 additions & 0 deletions src/hooks/useWorkletCallback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useCallback} from 'react';
import * as Reanimated from 'react-native-reanimated';


// @ts-ignore Runtime check if has useWorkletCallback for supporting reanimated v3 and v4 at the same time.
const hasCallbackWorklet = typeof Reanimated?.useWorkletCallback === 'function';

/**
* Provide the same functionality that we had in reanimated v3.
* @param callback
*/
export const useWorkletCallback = hasCallbackWorklet
? (Reanimated.useWorkletCallback as <T extends (...args: any[]) => any>(cb: T, deps: readonly unknown[]) => T)
: function useWorkletCallback<T extends (...args: any[]) => any>(callback: T, deps: readonly unknown[]): T {
return useCallback((...args: Parameters<T>): ReturnType<T> => {
'worklet';
return callback?.(...args);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got the following error: Error: [Worklets] Tried to synchronously call a non-worklet function evaluatePosition on the UI thread.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i'm seeing that error still looks like the current approach is not enough for inner functions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

evaluatePosition is broken:

image

}, deps) as T;
};
Loading