@rork-ai/toolkit-sdk 0.2.42 → 0.2.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,215 +0,0 @@
1
- // @ts-nocheck
2
- import React, { useCallback, useEffect, useMemo, useRef } from "react";
3
- // Import from react-native-web directly to avoid infinite loop
4
- // (metro redirects "react-native" to our polyfill on web)
5
- import {
6
- ActivityIndicator,
7
- Animated,
8
- PanResponder,
9
- View,
10
- type GestureResponderEvent,
11
- type PanResponderGestureState,
12
- type RefreshControlProps,
13
- type StyleProp,
14
- type ViewStyle,
15
- } from "react-native-web";
16
-
17
- interface WebRefreshControlProps extends Omit<RefreshControlProps, "style"> {
18
- children?: React.ReactNode;
19
- style?: StyleProp<ViewStyle>;
20
- }
21
-
22
- export default function WebRefreshControl({
23
- refreshing,
24
- tintColor,
25
- colors,
26
- style,
27
- progressViewOffset,
28
- children,
29
- onRefresh,
30
- enabled,
31
- }: WebRefreshControlProps) {
32
- const onRefreshRef = useRef(onRefresh);
33
- useEffect(() => {
34
- onRefreshRef.current = onRefresh;
35
- }, [onRefresh]);
36
- const enabledRef = useRef(enabled);
37
- useEffect(() => {
38
- enabledRef.current = enabled;
39
- }, [enabled]);
40
-
41
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
- const containerRef = useRef<any>(null);
43
- const pullPosReachedState = useRef(0);
44
- const pullDownSwipeMargin = useRef(new Animated.Value(0));
45
-
46
- useEffect(() => {
47
- Animated.timing(pullDownSwipeMargin.current, {
48
- toValue: refreshing ? 50 : 0,
49
- duration: 350,
50
- useNativeDriver: false,
51
- }).start();
52
- if (refreshing) {
53
- pullPosReachedState.current = 0;
54
- }
55
- }, [refreshing]);
56
-
57
- const onPanResponderFinish = useCallback(() => {
58
- if (pullPosReachedState.current && onRefreshRef.current) {
59
- onRefreshRef.current();
60
- }
61
- if (!pullPosReachedState.current) {
62
- Animated.timing(pullDownSwipeMargin.current, {
63
- toValue: 0,
64
- duration: 350,
65
- useNativeDriver: false,
66
- }).start();
67
- }
68
- }, []);
69
-
70
- const panResponder = useRef(
71
- PanResponder.create({
72
- onStartShouldSetPanResponder: () => false,
73
- onStartShouldSetPanResponderCapture: () => false,
74
- onMoveShouldSetPanResponder: (
75
- _: GestureResponderEvent,
76
- gestureState: PanResponderGestureState,
77
- ) => {
78
- if (!containerRef.current) return false;
79
- // React 19 fix: use direct DOM traversal instead of findNodeHandle
80
- const scrollContainer = (containerRef.current as unknown as HTMLElement)
81
- ?.firstChild as HTMLElement | null;
82
- if (!scrollContainer) return false;
83
- return (
84
- scrollContainer.scrollTop === 0 &&
85
- Math.abs(gestureState.dy) > Math.abs(gestureState.dx) * 2 &&
86
- Math.abs(gestureState.vy) > Math.abs(gestureState.vx) * 2.5
87
- );
88
- },
89
- onMoveShouldSetPanResponderCapture: () => false,
90
- onPanResponderMove: (
91
- _: GestureResponderEvent,
92
- gestureState: PanResponderGestureState,
93
- ) => {
94
- if (enabledRef.current !== undefined && !enabledRef.current) return;
95
-
96
- const adjustedDy =
97
- gestureState.dy <= 0
98
- ? 0
99
- : (gestureState.dy * 150) / (gestureState.dy + 120); // Diminishing returns function
100
- pullDownSwipeMargin.current.setValue(adjustedDy);
101
- const newValue = adjustedDy > 45 ? 1 : 0;
102
- if (newValue !== pullPosReachedState.current) {
103
- pullPosReachedState.current = newValue;
104
- }
105
- },
106
- onPanResponderTerminationRequest: () => true,
107
- onPanResponderRelease: onPanResponderFinish,
108
- onPanResponderTerminate: onPanResponderFinish,
109
- }),
110
- );
111
-
112
- const refreshIndicatorColor = useMemo(
113
- () => (tintColor ? tintColor : colors && colors.length ? colors[0] : null),
114
- [colors, tintColor],
115
- );
116
-
117
- const containerStyle = useMemo(
118
- (): StyleProp<ViewStyle> => [
119
- style,
120
- // @ts-ignore - overflowY is valid on web
121
- {
122
- overflowY: "hidden",
123
- overflow: "hidden",
124
- paddingTop: progressViewOffset,
125
- },
126
- ],
127
- [progressViewOffset, style],
128
- );
129
-
130
- const indicatorTransformStyle = useMemo(
131
- () => ({
132
- alignSelf: "center" as const,
133
- justifyContent: "center" as const,
134
- alignItems: "center" as const,
135
- marginTop: -40,
136
- height: 40,
137
- transform: [{ translateY: pullDownSwipeMargin.current }],
138
- }),
139
- [],
140
- );
141
-
142
- // This is messing with react-native-web's internal implementation
143
- // Will probably break if anything changes on their end
144
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
145
- const AnimatedContentContainer =
146
- useMemo((): React.ComponentType<any> | null => {
147
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
148
- const childElement = children as React.ReactElement<any>;
149
- if (!childElement?.props?.children?.type) return null;
150
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
151
- return withAnimated((childProps: any) =>
152
- React.createElement(childElement.props.children.type, childProps),
153
- );
154
- }, [children]);
155
-
156
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
157
- const childElement = children as React.ReactElement<any>;
158
- const newContentContainerStyle = useMemo(
159
- () => [
160
- childElement?.props?.children?.props?.style,
161
- { transform: [{ translateY: pullDownSwipeMargin.current }] },
162
- ],
163
- [childElement?.props?.children?.props?.style],
164
- );
165
-
166
- if (!childElement || !AnimatedContentContainer) {
167
- return <>{children}</>;
168
- }
169
-
170
- const newChildren = React.cloneElement(
171
- childElement,
172
- {},
173
- <>
174
- <Animated.View style={indicatorTransformStyle}>
175
- <ActivityIndicator
176
- color={refreshIndicatorColor || "#999999"}
177
- size="small"
178
- />
179
- </Animated.View>
180
- <AnimatedContentContainer
181
- {...childElement.props.children.props}
182
- style={newContentContainerStyle}
183
- />
184
- </>,
185
- );
186
-
187
- return (
188
- <View
189
- ref={containerRef}
190
- style={containerStyle}
191
- {...panResponder.current.panHandlers}
192
- >
193
- {newChildren}
194
- </View>
195
- );
196
- }
197
-
198
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
199
- function withAnimated(
200
- WrappedComponent: React.ComponentType<any>,
201
- ): React.ComponentType<any> {
202
- const displayName =
203
- WrappedComponent.displayName || WrappedComponent.name || "Component";
204
-
205
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
206
- class WithAnimated extends React.Component<any> {
207
- static displayName = `WithAnimated(${displayName})`;
208
-
209
- render() {
210
- return <WrappedComponent {...this.props} />;
211
- }
212
- }
213
-
214
- return Animated.createAnimatedComponent(WithAnimated);
215
- }
@@ -1,111 +0,0 @@
1
- const VALUE_BYTES_LIMIT = 2048;
2
-
3
- const KEYCHAIN_CONSTANTS = {
4
- AFTER_FIRST_UNLOCK: 0,
5
- AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY: 1,
6
- ALWAYS: 2,
7
- WHEN_PASSCODE_SET_THIS_DEVICE_ONLY: 3,
8
- ALWAYS_THIS_DEVICE_ONLY: 4,
9
- WHEN_UNLOCKED: 5,
10
- WHEN_UNLOCKED_THIS_DEVICE_ONLY: 6,
11
- };
12
-
13
- export type KeychainAccessibilityConstant = number;
14
- export const {
15
- AFTER_FIRST_UNLOCK,
16
- AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY,
17
- ALWAYS,
18
- WHEN_PASSCODE_SET_THIS_DEVICE_ONLY,
19
- ALWAYS_THIS_DEVICE_ONLY,
20
- WHEN_UNLOCKED,
21
- WHEN_UNLOCKED_THIS_DEVICE_ONLY,
22
- } = KEYCHAIN_CONSTANTS;
23
-
24
- export type SecureStoreOptions = {
25
- keychainService?: string;
26
- requireAuthentication?: boolean;
27
- authenticationPrompt?: string;
28
- keychainAccessible?: KeychainAccessibilityConstant;
29
- };
30
-
31
- function isValidValue(value: string) {
32
- if (typeof value !== "string") {
33
- return false;
34
- }
35
- if (new Blob([value]).size > VALUE_BYTES_LIMIT) {
36
- // biome-ignore lint/suspicious/noConsole: useful for debugging
37
- console.warn(
38
- `Value being stored in SecureStore is larger than ${VALUE_BYTES_LIMIT} bytes and it may not be stored successfully.`,
39
- );
40
- }
41
- return true;
42
- }
43
-
44
- function getStorageKey(key: string): string {
45
- return `_create_secure_store_${key}`;
46
- }
47
-
48
- export async function isAvailableAsync(): Promise<boolean> {
49
- const testKey = "__SECURE_STORE_AVAILABILITY_TEST_KEY__";
50
- try {
51
- localStorage.setItem(testKey, "test");
52
- if (localStorage.getItem(testKey) !== "test") {
53
- return false;
54
- }
55
- localStorage.removeItem(testKey);
56
- return localStorage.getItem(testKey) === null;
57
- } catch {
58
- return false;
59
- }
60
- }
61
-
62
- export async function deleteItemAsync(
63
- key: string,
64
- _options: SecureStoreOptions = {},
65
- ): Promise<void> {
66
- localStorage.removeItem(getStorageKey(key));
67
- }
68
-
69
- export async function getItemAsync(
70
- key: string,
71
- _options: SecureStoreOptions = {},
72
- ): Promise<string | null> {
73
- return localStorage.getItem(getStorageKey(key));
74
- }
75
-
76
- export async function setItemAsync(
77
- key: string,
78
- value: string,
79
- _options: SecureStoreOptions = {},
80
- ): Promise<void> {
81
- if (!isValidValue(value)) {
82
- throw new Error(
83
- "Invalid value provided to SecureStore. Values must be strings; consider JSON-encoding your values if they are serializable.",
84
- );
85
- }
86
- localStorage.setItem(getStorageKey(key), value);
87
- }
88
-
89
- export function setItem(
90
- key: string,
91
- value: string,
92
- _options: SecureStoreOptions = {},
93
- ): void {
94
- if (!isValidValue(value)) {
95
- throw new Error(
96
- "Invalid value provided to SecureStore. Values must be strings; consider JSON-encoding your values if they are serializable.",
97
- );
98
- }
99
- localStorage.setItem(getStorageKey(key), value);
100
- }
101
-
102
- export function getItem(
103
- key: string,
104
- _options: SecureStoreOptions = {},
105
- ): string | null {
106
- return localStorage.getItem(getStorageKey(key));
107
- }
108
-
109
- export function canUseBiometricAuthentication(): boolean {
110
- return false;
111
- }
package/src/utils.ts DELETED
@@ -1,3 +0,0 @@
1
- export function isExpoGo() {
2
- return !!globalThis.expo?.modules?.ExpoGo;
3
- }