@rootnative/web 0.0.0-alpha.3 → 0.0.0-alpha.4
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.
- package/CHANGELOG.md +21 -1
- package/dist/apis/AccessibilityInfo/index.d.ts +30 -0
- package/dist/apis/AccessibilityInfo/index.js +84 -0
- package/dist/apis/AccessibilityInfo/index.js.map +1 -0
- package/dist/apis/Alert/index.d.ts +22 -0
- package/dist/apis/Alert/index.js +141 -0
- package/dist/apis/Alert/index.js.map +1 -0
- package/dist/apis/AppState/index.d.ts +21 -0
- package/dist/apis/AppState/index.js +86 -0
- package/dist/apis/AppState/index.js.map +1 -0
- package/dist/apis/Appearance/index.d.ts +14 -0
- package/dist/apis/Appearance/index.js +39 -0
- package/dist/apis/Appearance/index.js.map +1 -0
- package/dist/apis/BackHandler/index.d.ts +10 -0
- package/dist/apis/BackHandler/index.js +16 -0
- package/dist/apis/BackHandler/index.js.map +1 -0
- package/dist/apis/Clipboard/index.d.ts +9 -0
- package/dist/apis/Clipboard/index.js +45 -0
- package/dist/apis/Clipboard/index.js.map +1 -0
- package/dist/apis/Dimensions/index.d.ts +19 -0
- package/dist/apis/Dimensions/index.js +66 -0
- package/dist/apis/Dimensions/index.js.map +1 -0
- package/dist/apis/I18nManager/index.d.ts +14 -0
- package/dist/apis/I18nManager/index.js +33 -0
- package/dist/apis/I18nManager/index.js.map +1 -0
- package/dist/apis/Keyboard/index.d.ts +36 -0
- package/dist/apis/Keyboard/index.js +149 -0
- package/dist/apis/Keyboard/index.js.map +1 -0
- package/dist/apis/Linking/index.d.ts +29 -0
- package/dist/apis/Linking/index.js +86 -0
- package/dist/apis/Linking/index.js.map +1 -0
- package/dist/apis/PanResponder/index.d.ts +50 -0
- package/dist/apis/PanResponder/index.js +239 -0
- package/dist/apis/PanResponder/index.js.map +1 -0
- package/dist/apis/PixelRatio/index.d.ts +8 -0
- package/dist/apis/PixelRatio/index.js +15 -0
- package/dist/apis/PixelRatio/index.js.map +1 -0
- package/dist/apis/Platform/index.d.ts +4 -0
- package/dist/apis/Platform/index.js +28 -0
- package/dist/apis/Platform/index.js.map +1 -0
- package/dist/apis/Platform/types.d.ts +19 -0
- package/dist/apis/Share/index.d.ts +30 -0
- package/dist/apis/Share/index.js +34 -0
- package/dist/apis/Share/index.js.map +1 -0
- package/dist/apis/StyleSheet/index.d.ts +23 -0
- package/dist/apis/StyleSheet/index.js +29 -0
- package/dist/apis/StyleSheet/index.js.map +1 -0
- package/dist/apis/StyleSheet/types.d.ts +328 -0
- package/dist/apis/Vibration/index.d.ts +9 -0
- package/dist/apis/Vibration/index.js +40 -0
- package/dist/apis/Vibration/index.js.map +1 -0
- package/dist/apis/processColor/index.d.ts +3 -0
- package/dist/apis/processColor/index.js +12 -0
- package/dist/apis/processColor/index.js.map +1 -0
- package/dist/apis/useColorScheme/index.d.ts +3 -0
- package/dist/apis/useColorScheme/index.js +13 -0
- package/dist/apis/useColorScheme/index.js.map +1 -0
- package/dist/apis/useWindowDimensions/index.d.ts +3 -0
- package/dist/apis/useWindowDimensions/index.js +19 -0
- package/dist/apis/useWindowDimensions/index.js.map +1 -0
- package/dist/bundler/index.js +30 -0
- package/dist/bundler/index.js.map +1 -0
- package/dist/bundler/inlinePlatformOS.js +121 -0
- package/dist/bundler/inlinePlatformOS.js.map +1 -0
- package/dist/bundler/worklets.js +61 -0
- package/dist/bundler/worklets.js.map +1 -0
- package/dist/compat/TurboModuleRegistry/index.d.ts +16 -0
- package/dist/compat/TurboModuleRegistry/index.js +14 -0
- package/dist/compat/TurboModuleRegistry/index.js.map +1 -0
- package/dist/compat/createElement/index.d.ts +9 -0
- package/dist/compat/createElement/index.js +40 -0
- package/dist/compat/createElement/index.js.map +1 -0
- package/dist/compat/findNodeHandle/index.d.ts +7 -0
- package/dist/compat/findNodeHandle/index.js +19 -0
- package/dist/compat/findNodeHandle/index.js.map +1 -0
- package/dist/components/ActivityIndicator/index.d.ts +5 -0
- package/dist/components/ActivityIndicator/index.js +74 -0
- package/dist/components/ActivityIndicator/index.js.map +1 -0
- package/dist/components/ActivityIndicator/types.d.ts +8 -0
- package/dist/components/Button/index.d.ts +5 -0
- package/dist/components/Button/index.js +48 -0
- package/dist/components/Button/index.js.map +1 -0
- package/dist/components/Button/types.d.ts +31 -0
- package/dist/components/FlatList/index.d.ts +5 -0
- package/dist/components/FlatList/index.js +433 -0
- package/dist/components/FlatList/index.js.map +1 -0
- package/dist/components/FlatList/types.d.ts +138 -0
- package/dist/components/FlatList/viewability.js +86 -0
- package/dist/components/FlatList/viewability.js.map +1 -0
- package/dist/components/Image/index.d.ts +7 -0
- package/dist/components/Image/index.js +301 -0
- package/dist/components/Image/index.js.map +1 -0
- package/dist/components/Image/source.js +97 -0
- package/dist/components/Image/source.js.map +1 -0
- package/dist/components/Image/types.d.ts +96 -0
- package/dist/components/KeyboardAvoidingView/index.d.ts +10 -0
- package/dist/components/KeyboardAvoidingView/index.js +118 -0
- package/dist/components/KeyboardAvoidingView/index.js.map +1 -0
- package/dist/components/KeyboardAvoidingView/types.d.ts +14 -0
- package/dist/components/Modal/index.d.ts +9 -0
- package/dist/components/Modal/index.js +271 -0
- package/dist/components/Modal/index.js.map +1 -0
- package/dist/components/Modal/types.d.ts +29 -0
- package/dist/components/Pressable/index.d.ts +5 -0
- package/dist/components/Pressable/index.js +106 -0
- package/dist/components/Pressable/index.js.map +1 -0
- package/dist/components/Pressable/types.d.ts +44 -0
- package/dist/components/RefreshControl/index.d.ts +5 -0
- package/dist/components/RefreshControl/index.js +176 -0
- package/dist/components/RefreshControl/index.js.map +1 -0
- package/dist/components/RefreshControl/pull.js +16 -0
- package/dist/components/RefreshControl/pull.js.map +1 -0
- package/dist/components/RefreshControl/types.d.ts +14 -0
- package/dist/components/ScrollView/index.d.ts +5 -0
- package/dist/components/ScrollView/index.js +318 -0
- package/dist/components/ScrollView/index.js.map +1 -0
- package/dist/components/ScrollView/snap.js +38 -0
- package/dist/components/ScrollView/snap.js.map +1 -0
- package/dist/components/ScrollView/types.d.ts +115 -0
- package/dist/components/StatusBar/index.d.ts +26 -0
- package/dist/components/StatusBar/index.js +113 -0
- package/dist/components/StatusBar/index.js.map +1 -0
- package/dist/components/Switch/index.d.ts +5 -0
- package/dist/components/Switch/index.js +89 -0
- package/dist/components/Switch/index.js.map +1 -0
- package/dist/components/Switch/types.d.ts +25 -0
- package/dist/components/Text/TextAncestorContext.d.ts +3 -0
- package/dist/components/Text/TextAncestorContext.js +6 -0
- package/dist/components/Text/TextAncestorContext.js.map +1 -0
- package/dist/components/Text/index.d.ts +6 -0
- package/dist/components/Text/index.js +133 -0
- package/dist/components/Text/index.js.map +1 -0
- package/dist/components/Text/types.d.ts +38 -0
- package/dist/components/TextInput/autocomplete.js +102 -0
- package/dist/components/TextInput/autocomplete.js.map +1 -0
- package/dist/components/TextInput/index.d.ts +8 -0
- package/dist/components/TextInput/index.js +290 -0
- package/dist/components/TextInput/index.js.map +1 -0
- package/dist/components/TextInput/types.d.ts +130 -0
- package/dist/components/TouchableHighlight/index.d.ts +5 -0
- package/dist/components/TouchableHighlight/index.js +109 -0
- package/dist/components/TouchableHighlight/index.js.map +1 -0
- package/dist/components/TouchableHighlight/types.d.ts +15 -0
- package/dist/components/TouchableNativeFeedback/index.d.ts +11 -0
- package/dist/components/TouchableNativeFeedback/index.js +29 -0
- package/dist/components/TouchableNativeFeedback/index.js.map +1 -0
- package/dist/components/TouchableNativeFeedback/types.d.ts +19 -0
- package/dist/components/TouchableOpacity/index.d.ts +5 -0
- package/dist/components/TouchableOpacity/index.js +122 -0
- package/dist/components/TouchableOpacity/index.js.map +1 -0
- package/dist/components/TouchableOpacity/types.d.ts +11 -0
- package/dist/components/TouchableWithoutFeedback/index.d.ts +5 -0
- package/dist/components/TouchableWithoutFeedback/index.js +70 -0
- package/dist/components/TouchableWithoutFeedback/index.js.map +1 -0
- package/dist/components/TouchableWithoutFeedback/types.d.ts +40 -0
- package/dist/components/View/index.d.ts +5 -0
- package/dist/components/View/index.js +50 -0
- package/dist/components/View/index.js.map +1 -0
- package/dist/components/View/types.d.ts +98 -0
- package/dist/dom/Head.d.ts +21 -0
- package/dist/dom/Head.js +53 -0
- package/dist/dom/Head.js.map +1 -0
- package/dist/dom/index.d.ts +2 -22
- package/dist/dom/index.js +1 -53
- package/dist/events/press/Pressability.d.ts +2 -0
- package/dist/events/press/Pressability.js +366 -0
- package/dist/events/press/Pressability.js.map +1 -0
- package/dist/events/press/cursorStyle.js +5 -0
- package/dist/events/press/cursorStyle.js.map +1 -0
- package/dist/events/press/index.d.ts +4 -0
- package/dist/events/press/mergeHandlers.js +30 -0
- package/dist/events/press/mergeHandlers.js.map +1 -0
- package/dist/events/press/types.d.ts +48 -0
- package/dist/events/press/usePressability.d.ts +4 -0
- package/dist/events/press/usePressability.js +18 -0
- package/dist/events/press/usePressability.js.map +1 -0
- package/dist/events/responderEvent.js +50 -0
- package/dist/events/responderEvent.js.map +1 -0
- package/dist/events/types.d.ts +33 -0
- package/dist/index.d.ts +66 -1597
- package/dist/index.js +42 -4864
- package/dist/reactNativeVersion.d.ts +7 -0
- package/dist/reactNativeVersion.js +10 -0
- package/dist/reactNativeVersion.js.map +1 -0
- package/dist/render/domProps.js +66 -0
- package/dist/render/domProps.js.map +1 -0
- package/dist/render/hitSlop.js +21 -0
- package/dist/render/hitSlop.js.map +1 -0
- package/dist/render/hostMethods.js +44 -0
- package/dist/render/hostMethods.js.map +1 -0
- package/dist/render/resolveTag.js +64 -0
- package/dist/render/resolveTag.js.map +1 -0
- package/dist/render/useElementLayout.js +25 -0
- package/dist/render/useElementLayout.js.map +1 -0
- package/dist/server/index.d.ts +2 -27
- package/dist/server/index.js +2 -2
- package/dist/{StyleRegistryContext-ROsMlY4O.js → style/StyleRegistryContext.js} +3 -3
- package/dist/style/StyleRegistryContext.js.map +1 -0
- package/dist/style/color.js +16 -0
- package/dist/style/color.js.map +1 -0
- package/dist/style/compile.js +72 -0
- package/dist/style/compile.js.map +1 -0
- package/dist/style/direction.js +33 -0
- package/dist/style/direction.js.map +1 -0
- package/dist/style/index.d.ts +1 -1
- package/dist/style/index.js +5 -2
- package/dist/style/index.js.map +1 -1
- package/dist/style/registry.d.ts +27 -0
- package/dist/{registry-Aa_Od5m0.js → style/registry.js} +3 -3
- package/dist/style/registry.js.map +1 -0
- package/dist/style/resolveStyle.js +181 -0
- package/dist/style/resolveStyle.js.map +1 -0
- package/dist/style/shadow.js +87 -0
- package/dist/style/shadow.js.map +1 -0
- package/dist/style/splitLayoutProps.js +52 -0
- package/dist/style/splitLayoutProps.js.map +1 -0
- package/dist/style/transform.js +35 -0
- package/dist/style/transform.js.map +1 -0
- package/dist/style/types.d.ts +4 -0
- package/dist/style/units.js +21 -0
- package/dist/style/units.js.map +1 -0
- package/dist/style/webStyle.js +9 -0
- package/dist/style/webStyle.js.map +1 -0
- package/dist/{env-DK5Mt9yX.js → utils/env.js} +2 -2
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/scrollLock.js +28 -0
- package/dist/utils/scrollLock.js.map +1 -0
- package/dist/utils/warn.js +11 -0
- package/dist/utils/warn.js.map +1 -0
- package/dist/vite/index.js +4 -202
- package/dist/vite/index.js.map +1 -1
- package/llms.txt +20 -0
- package/package.json +4 -3
- package/dist/StyleRegistryContext-ROsMlY4O.js.map +0 -1
- package/dist/compile-CVUjQrR9.js +0 -400
- package/dist/compile-CVUjQrR9.js.map +0 -1
- package/dist/dom/index.js.map +0 -1
- package/dist/env-DK5Mt9yX.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/registry-Aa_Od5m0.js.map +0 -1
- package/dist/types-BxTWbdj9.d.ts +0 -5
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { pointerCursorStyle } from "../../events/press/cursorStyle.js";
|
|
2
|
+
import { usePressability } from "../../events/press/usePressability.js";
|
|
3
|
+
import { mergeHandlers } from "../../events/press/mergeHandlers.js";
|
|
4
|
+
import { hitSlopClass } from "../../render/hitSlop.js";
|
|
5
|
+
import { useStyleRegistry } from "../../style/StyleRegistryContext.js";
|
|
6
|
+
import { useViewElement } from "../View/index.js";
|
|
7
|
+
import { memo, useMemo, useState } from "react";
|
|
8
|
+
// src/components/Pressable/index.tsx
|
|
9
|
+
const notCancelableStyle = Object.freeze({ touchAction: "none" });
|
|
10
|
+
const isFocusVisible = (element) => {
|
|
11
|
+
try {
|
|
12
|
+
return element.matches(":focus-visible");
|
|
13
|
+
} catch {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const Pressable = memo(function Pressable(props) {
|
|
18
|
+
const { android_disableSound, android_ripple: _androidRipple, blockNativeResponder, cancelable, children, delayHoverIn, delayHoverOut, delayLongPress, disabled, focusable, hitSlop, onBlur, onFocus, onHoverIn, onHoverOut, onLongPress, onPress, onPressIn, onPressMove, onPressOut, pressRetentionOffset, style, testOnly_pressed, unstable_pressDelay, ...rest } = props;
|
|
19
|
+
const [pressed, setPressed] = useState(false);
|
|
20
|
+
const [hovered, setHovered] = useState(false);
|
|
21
|
+
const [focused, setFocused] = useState(false);
|
|
22
|
+
const tracksState = typeof children === "function" || typeof style === "function";
|
|
23
|
+
const config = useMemo(() => ({
|
|
24
|
+
cancelable,
|
|
25
|
+
disabled,
|
|
26
|
+
hitSlop,
|
|
27
|
+
pressRectOffset: pressRetentionOffset,
|
|
28
|
+
android_disableSound,
|
|
29
|
+
delayHoverIn,
|
|
30
|
+
delayHoverOut,
|
|
31
|
+
delayLongPress,
|
|
32
|
+
delayPressIn: unstable_pressDelay,
|
|
33
|
+
blockNativeResponder,
|
|
34
|
+
onLongPress,
|
|
35
|
+
onPress,
|
|
36
|
+
onPressMove,
|
|
37
|
+
onPressIn: (event) => {
|
|
38
|
+
if (tracksState) setPressed(true);
|
|
39
|
+
onPressIn?.(event);
|
|
40
|
+
},
|
|
41
|
+
onPressOut: (event) => {
|
|
42
|
+
if (tracksState) setPressed(false);
|
|
43
|
+
onPressOut?.(event);
|
|
44
|
+
},
|
|
45
|
+
onHoverIn: (event) => {
|
|
46
|
+
if (tracksState) setHovered(true);
|
|
47
|
+
onHoverIn?.(event);
|
|
48
|
+
},
|
|
49
|
+
onHoverOut: (event) => {
|
|
50
|
+
if (tracksState) setHovered(false);
|
|
51
|
+
onHoverOut?.(event);
|
|
52
|
+
},
|
|
53
|
+
onFocus: (event) => {
|
|
54
|
+
if (tracksState && event.target === event.currentTarget) setFocused(isFocusVisible(event.currentTarget));
|
|
55
|
+
onFocus?.(event);
|
|
56
|
+
},
|
|
57
|
+
onBlur: (event) => {
|
|
58
|
+
if (tracksState && event.target === event.currentTarget) setFocused(false);
|
|
59
|
+
onBlur?.(event);
|
|
60
|
+
}
|
|
61
|
+
}), [
|
|
62
|
+
android_disableSound,
|
|
63
|
+
blockNativeResponder,
|
|
64
|
+
cancelable,
|
|
65
|
+
delayHoverIn,
|
|
66
|
+
delayHoverOut,
|
|
67
|
+
delayLongPress,
|
|
68
|
+
disabled,
|
|
69
|
+
hitSlop,
|
|
70
|
+
onBlur,
|
|
71
|
+
onFocus,
|
|
72
|
+
onHoverIn,
|
|
73
|
+
onHoverOut,
|
|
74
|
+
onLongPress,
|
|
75
|
+
onPress,
|
|
76
|
+
onPressIn,
|
|
77
|
+
onPressMove,
|
|
78
|
+
onPressOut,
|
|
79
|
+
pressRetentionOffset,
|
|
80
|
+
tracksState,
|
|
81
|
+
unstable_pressDelay
|
|
82
|
+
]);
|
|
83
|
+
const handlers = usePressability(config);
|
|
84
|
+
const registry = useStyleRegistry();
|
|
85
|
+
const state = {
|
|
86
|
+
pressed: pressed || testOnly_pressed === true,
|
|
87
|
+
hovered,
|
|
88
|
+
focused
|
|
89
|
+
};
|
|
90
|
+
const viewProps = {
|
|
91
|
+
...rest,
|
|
92
|
+
...mergeHandlers(rest, handlers),
|
|
93
|
+
focusable: disabled !== true && focusable !== false,
|
|
94
|
+
style: [
|
|
95
|
+
disabled !== true && pointerCursorStyle,
|
|
96
|
+
typeof style === "function" ? style(state) : style,
|
|
97
|
+
cancelable === false && notCancelableStyle
|
|
98
|
+
],
|
|
99
|
+
children: typeof children === "function" ? children(state) : children
|
|
100
|
+
};
|
|
101
|
+
if (disabled === true) viewProps["aria-disabled"] = true;
|
|
102
|
+
return useViewElement(viewProps, hitSlopClass(registry, hitSlop));
|
|
103
|
+
});
|
|
104
|
+
export { Pressable };
|
|
105
|
+
|
|
106
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/Pressable/index.tsx"],"sourcesContent":["import { memo, useMemo, useState, type NamedExoticComponent, type ReactElement } from 'react'\n\nimport { pointerCursorStyle, usePressability } from '../../events/press'\nimport { mergeHandlers } from '../../events/press/mergeHandlers'\nimport type { PressabilityConfig } from '../../events/press/types'\nimport { hitSlopClass } from '../../render/hitSlop'\nimport { useStyleRegistry } from '../../style/StyleRegistryContext'\nimport { useViewElement } from '../View'\nimport type { ViewProps } from '../View/types'\nimport type { PressableProps, PressableStateCallbackType } from './types'\n\nexport type {\n PressableAndroidRippleConfig,\n PressableInstance,\n PressableProps,\n PressableStateCallbackType,\n} from './types'\n\nconst notCancelableStyle = Object.freeze({ touchAction: 'none' })\n\n// Safari before 15.4 has no :focus-visible. There, any focus counts.\nconst isFocusVisible = (element: Element): boolean => {\n try {\n return element.matches(':focus-visible')\n } catch {\n return true\n }\n}\n\nexport const Pressable: NamedExoticComponent<PressableProps> = memo(function Pressable(\n props: PressableProps,\n): ReactElement {\n const {\n android_disableSound,\n android_ripple: _androidRipple,\n blockNativeResponder,\n cancelable,\n children,\n delayHoverIn,\n delayHoverOut,\n delayLongPress,\n disabled,\n focusable,\n hitSlop,\n onBlur,\n onFocus,\n onHoverIn,\n onHoverOut,\n onLongPress,\n onPress,\n onPressIn,\n onPressMove,\n onPressOut,\n pressRetentionOffset,\n style,\n testOnly_pressed,\n unstable_pressDelay,\n ...rest\n } = props\n\n const [pressed, setPressed] = useState(false)\n const [hovered, setHovered] = useState(false)\n const [focused, setFocused] = useState(false)\n // As on native, the state re-renders only a Pressable that reads it.\n const tracksState = typeof children === 'function' || typeof style === 'function'\n\n const config = useMemo<PressabilityConfig>(\n () => ({\n cancelable,\n disabled,\n hitSlop,\n pressRectOffset: pressRetentionOffset,\n android_disableSound,\n delayHoverIn,\n delayHoverOut,\n delayLongPress,\n delayPressIn: unstable_pressDelay,\n blockNativeResponder,\n onLongPress,\n onPress,\n onPressMove,\n onPressIn: (event) => {\n if (tracksState) setPressed(true)\n onPressIn?.(event)\n },\n onPressOut: (event) => {\n if (tracksState) setPressed(false)\n onPressOut?.(event)\n },\n onHoverIn: (event) => {\n if (tracksState) setHovered(true)\n onHoverIn?.(event)\n },\n onHoverOut: (event) => {\n if (tracksState) setHovered(false)\n onHoverOut?.(event)\n },\n onFocus: (event) => {\n if (tracksState && event.target === event.currentTarget) {\n setFocused(isFocusVisible(event.currentTarget))\n }\n onFocus?.(event)\n },\n onBlur: (event) => {\n if (tracksState && event.target === event.currentTarget) setFocused(false)\n onBlur?.(event)\n },\n }),\n [\n android_disableSound,\n blockNativeResponder,\n cancelable,\n delayHoverIn,\n delayHoverOut,\n delayLongPress,\n disabled,\n hitSlop,\n onBlur,\n onFocus,\n onHoverIn,\n onHoverOut,\n onLongPress,\n onPress,\n onPressIn,\n onPressMove,\n onPressOut,\n pressRetentionOffset,\n tracksState,\n unstable_pressDelay,\n ],\n )\n const handlers = usePressability(config)\n const registry = useStyleRegistry()\n\n const state: PressableStateCallbackType = {\n pressed: pressed || testOnly_pressed === true,\n hovered,\n focused,\n }\n\n const viewProps: ViewProps = {\n ...rest,\n ...mergeHandlers(rest, handlers),\n focusable: disabled !== true && focusable !== false,\n style: [\n disabled !== true && pointerCursorStyle,\n typeof style === 'function' ? style(state) : style,\n cancelable === false && notCancelableStyle,\n ],\n children: typeof children === 'function' ? children(state) : children,\n }\n if (disabled === true) viewProps['aria-disabled'] = true\n\n return useViewElement(viewProps, hitSlopClass(registry, hitSl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A;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CACA,MAAM,WAAW,gBAAgB,MAAM;CACvC,MAAM,WAAW,iBAAiB;CAElC,MAAM,QAAoC;EACxC,SAAS,WAAW,qBAAqB;EACzC;EACA;CACF;CAEA,MAAM,YAAuB;EAC3B,GAAG;EACH,GAAG,cAAc,MAAM,QAAQ;EAC/B,WAAW,aAAa,QAAQ,cAAc;EAC9C,OAAO;GACL,aAAa,QAAQ;GACrB,OAAO,UAAU,aAAa,MAAM,KAAK,IAAI;GAC7C,eAAe,SAAS;EAC1B;EACA,UAAU,OAAO,aAAa,aAAa,SAAS,KAAK,IAAI;CAC/D;CACA,IAAI,aAAa,MAAM,UAAU,mBAAmB;CAEpD,OAAO,eAAe,WAAW,aAAa,UAAU,OAAO,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ViewStyle } from "../../apis/StyleSheet/types.js";
|
|
2
|
+
import { RectOrSize } from "../../events/press/types.js";
|
|
3
|
+
import { BlurEvent, FocusEvent as FocusEvent$1, GestureResponderEvent, MouseEvent as MouseEvent$1 } from "../../events/types.js";
|
|
4
|
+
import { StyleProp } from "../../style/types.js";
|
|
5
|
+
import { HostInstance, ViewProps } from "../View/types.js";
|
|
6
|
+
import { ReactNode } from "react";
|
|
7
|
+
export interface PressableStateCallbackType {
|
|
8
|
+
readonly pressed: boolean;
|
|
9
|
+
readonly hovered: boolean;
|
|
10
|
+
readonly focused: boolean;
|
|
11
|
+
}
|
|
12
|
+
export type PressableAndroidRippleConfig = {
|
|
13
|
+
color?: string | undefined;
|
|
14
|
+
borderless?: boolean | undefined;
|
|
15
|
+
radius?: number | undefined;
|
|
16
|
+
foreground?: boolean | undefined;
|
|
17
|
+
};
|
|
18
|
+
export type PressableInstance = HostInstance;
|
|
19
|
+
export interface PressableProps extends Omit<ViewProps, "children" | "style" | "onBlur" | "onFocus"> {
|
|
20
|
+
children?: ReactNode | ((state: PressableStateCallbackType) => ReactNode) | undefined;
|
|
21
|
+
style?: StyleProp<ViewStyle> | ((state: PressableStateCallbackType) => StyleProp<ViewStyle>) | undefined;
|
|
22
|
+
cancelable?: boolean | undefined;
|
|
23
|
+
delayHoverIn?: number | undefined;
|
|
24
|
+
delayHoverOut?: number | undefined;
|
|
25
|
+
delayLongPress?: number | undefined;
|
|
26
|
+
disabled?: boolean | undefined;
|
|
27
|
+
hitSlop?: RectOrSize | undefined;
|
|
28
|
+
pressRetentionOffset?: RectOrSize | undefined;
|
|
29
|
+
onBlur?: ((event: BlurEvent) => unknown) | undefined;
|
|
30
|
+
onFocus?: ((event: FocusEvent$1) => unknown) | undefined;
|
|
31
|
+
onHoverIn?: ((event: MouseEvent$1) => unknown) | undefined;
|
|
32
|
+
onHoverOut?: ((event: MouseEvent$1) => unknown) | undefined;
|
|
33
|
+
onLongPress?: ((event: GestureResponderEvent) => unknown) | undefined;
|
|
34
|
+
onPress?: ((event: GestureResponderEvent) => unknown) | undefined;
|
|
35
|
+
onPressIn?: ((event: GestureResponderEvent) => unknown) | undefined;
|
|
36
|
+
onPressMove?: ((event: GestureResponderEvent) => unknown) | undefined;
|
|
37
|
+
onPressOut?: ((event: GestureResponderEvent) => unknown) | undefined;
|
|
38
|
+
blockNativeResponder?: boolean | undefined;
|
|
39
|
+
android_disableSound?: boolean | undefined;
|
|
40
|
+
android_ripple?: PressableAndroidRippleConfig | undefined;
|
|
41
|
+
testOnly_pressed?: boolean | undefined;
|
|
42
|
+
unstable_pressDelay?: number | undefined;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { StyleSheet } from "../../apis/StyleSheet/index.js";
|
|
2
|
+
import { toCSSColor } from "../../style/color.js";
|
|
3
|
+
import { useStyleRegistry } from "../../style/StyleRegistryContext.js";
|
|
4
|
+
import { View } from "../View/index.js";
|
|
5
|
+
import { pullOffset, releasesRefresh } from "./pull.js";
|
|
6
|
+
import { useEffect, useLayoutEffect, useRef } from "react";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
// src/components/RefreshControl/index.tsx
|
|
9
|
+
const ARC = "#000000";
|
|
10
|
+
const DISC = "#FFFFFF";
|
|
11
|
+
const ARC_LENGTH = 2 * Math.PI * 8.75;
|
|
12
|
+
const INDICATOR_CLASS = "rn-refresh";
|
|
13
|
+
const RULES = [
|
|
14
|
+
"@keyframes rn-refresh-spin{to{transform:rotate(360deg)}}",
|
|
15
|
+
`.${INDICATOR_CLASS}{position:absolute;top:0;left:50%;z-index:1;display:flex;width:40px;height:40px;margin-left:-20px;border-radius:50%;box-shadow:0 1px 4px rgba(0,0,0,.3);pointer-events:none;opacity:0;transform:translateY(calc(var(--rn-refresh-top) - 100%));transition:transform .2s ease-out,opacity .2s}`,
|
|
16
|
+
`.${INDICATOR_CLASS}[data-size=large]{width:56px;height:56px;margin-left:-28px}`,
|
|
17
|
+
`.${INDICATOR_CLASS}[data-refreshing]{opacity:1;transform:translateY(calc(var(--rn-refresh-top) + 64px - 100%))}`,
|
|
18
|
+
`.${INDICATOR_CLASS}>svg{width:100%;height:100%}`,
|
|
19
|
+
`.${INDICATOR_CLASS}[data-refreshing]>svg{animation:rn-refresh-spin .75s linear infinite}`,
|
|
20
|
+
`.${INDICATOR_CLASS} circle{stroke-dasharray:0 ${ARC_LENGTH}}`,
|
|
21
|
+
`.${INDICATOR_CLASS}[data-refreshing] circle{stroke-dasharray:${ARC_LENGTH * .75} ${ARC_LENGTH}}`,
|
|
22
|
+
`@media (prefers-reduced-motion:reduce){.${INDICATOR_CLASS}{transition:none}}`
|
|
23
|
+
];
|
|
24
|
+
const frameOf = (element) => {
|
|
25
|
+
let toScreen = new DOMMatrix();
|
|
26
|
+
for (let node = element; node !== null; node = node.parentElement) {
|
|
27
|
+
const { transform } = getComputedStyle(node);
|
|
28
|
+
if (transform !== "none") toScreen = new DOMMatrix(transform).multiply(toScreen);
|
|
29
|
+
}
|
|
30
|
+
return toScreen.inverse();
|
|
31
|
+
};
|
|
32
|
+
function RefreshControl(props) {
|
|
33
|
+
const { children, colors, enabled = true, onRefresh, progressBackgroundColor, progressViewOffset = 0, refreshing, size = "default", style, tintColor, title, titleColor: _titleColor, ...rest } = props;
|
|
34
|
+
const indicatorClass = useStyleRegistry().staticClass(INDICATOR_CLASS, RULES);
|
|
35
|
+
const indicator = useRef(null);
|
|
36
|
+
const latest = useRef({
|
|
37
|
+
enabled,
|
|
38
|
+
refreshing,
|
|
39
|
+
onRefresh
|
|
40
|
+
});
|
|
41
|
+
useLayoutEffect(() => {
|
|
42
|
+
latest.current = {
|
|
43
|
+
enabled,
|
|
44
|
+
refreshing,
|
|
45
|
+
onRefresh
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
const element = indicator.current;
|
|
50
|
+
const area = element?.parentElement;
|
|
51
|
+
if (!element || !area) return;
|
|
52
|
+
const svg = element.firstElementChild;
|
|
53
|
+
const arc = svg.firstElementChild;
|
|
54
|
+
let gesture = null;
|
|
55
|
+
let releaseTimer;
|
|
56
|
+
const scrollTop = () => {
|
|
57
|
+
const scroller = area.firstElementChild;
|
|
58
|
+
return scroller instanceof HTMLElement && scroller !== element ? scroller.scrollTop : 0;
|
|
59
|
+
};
|
|
60
|
+
const draw = (distance) => {
|
|
61
|
+
const offset = pullOffset(distance);
|
|
62
|
+
const progress = Math.min(1, offset / 64);
|
|
63
|
+
element.style.transition = "none";
|
|
64
|
+
element.style.opacity = String(Math.min(1, offset / element.offsetHeight));
|
|
65
|
+
element.style.transform = `translateY(calc(var(--rn-refresh-top) + ${offset}px - 100%))`;
|
|
66
|
+
svg.style.transform = `rotate(${progress * 270}deg)`;
|
|
67
|
+
arc.style.strokeDasharray = `${progress * .8 * ARC_LENGTH} ${ARC_LENGTH}`;
|
|
68
|
+
};
|
|
69
|
+
const clear = () => {
|
|
70
|
+
element.style.transition = "";
|
|
71
|
+
element.style.opacity = "";
|
|
72
|
+
element.style.transform = "";
|
|
73
|
+
svg.style.transform = "";
|
|
74
|
+
arc.style.strokeDasharray = "";
|
|
75
|
+
};
|
|
76
|
+
const touchOf = (event) => Array.from(event.changedTouches).find((touch) => touch.identifier === gesture?.id);
|
|
77
|
+
const onStart = (event) => {
|
|
78
|
+
const touch = event.touches[0];
|
|
79
|
+
const { enabled: on, refreshing: busy } = latest.current;
|
|
80
|
+
gesture = event.touches.length === 1 && touch !== void 0 && on && !busy && scrollTop() <= 0 ? {
|
|
81
|
+
id: touch.identifier,
|
|
82
|
+
x: touch.clientX,
|
|
83
|
+
y: touch.clientY,
|
|
84
|
+
pulling: false,
|
|
85
|
+
distance: 0,
|
|
86
|
+
toLocal: frameOf(area)
|
|
87
|
+
} : null;
|
|
88
|
+
};
|
|
89
|
+
const onMove = (event) => {
|
|
90
|
+
const touch = touchOf(event);
|
|
91
|
+
if (gesture === null || touch === void 0) return;
|
|
92
|
+
const { a, b, c, d } = gesture.toLocal;
|
|
93
|
+
const screenX = touch.clientX - gesture.x;
|
|
94
|
+
const screenY = touch.clientY - gesture.y;
|
|
95
|
+
const dx = a * screenX + c * screenY;
|
|
96
|
+
const dy = b * screenX + d * screenY;
|
|
97
|
+
if (!gesture.pulling) {
|
|
98
|
+
if (dx === 0 && dy === 0) return;
|
|
99
|
+
if (dy <= 0 || Math.abs(dx) > dy || scrollTop() > 0 || !event.cancelable) {
|
|
100
|
+
gesture = null;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
gesture.pulling = true;
|
|
104
|
+
}
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
gesture.distance = Math.max(0, dy);
|
|
107
|
+
draw(gesture.distance);
|
|
108
|
+
};
|
|
109
|
+
const onEnd = (event) => {
|
|
110
|
+
if (gesture === null || touchOf(event) === void 0) return;
|
|
111
|
+
const { pulling, distance } = gesture;
|
|
112
|
+
gesture = null;
|
|
113
|
+
if (!pulling) return;
|
|
114
|
+
const refresh = event.type === "touchend" && releasesRefresh(distance);
|
|
115
|
+
if (refresh) element.setAttribute("data-refreshing", "");
|
|
116
|
+
clear();
|
|
117
|
+
if (!refresh) return;
|
|
118
|
+
latest.current.onRefresh?.();
|
|
119
|
+
releaseTimer = setTimeout(() => {
|
|
120
|
+
if (!latest.current.refreshing) element.removeAttribute("data-refreshing");
|
|
121
|
+
}, 0);
|
|
122
|
+
};
|
|
123
|
+
area.addEventListener("touchstart", onStart, { passive: true });
|
|
124
|
+
area.addEventListener("touchmove", onMove, { passive: false });
|
|
125
|
+
area.addEventListener("touchend", onEnd);
|
|
126
|
+
area.addEventListener("touchcancel", onEnd);
|
|
127
|
+
return () => {
|
|
128
|
+
area.removeEventListener("touchstart", onStart);
|
|
129
|
+
area.removeEventListener("touchmove", onMove);
|
|
130
|
+
area.removeEventListener("touchend", onEnd);
|
|
131
|
+
area.removeEventListener("touchcancel", onEnd);
|
|
132
|
+
clearTimeout(releaseTimer);
|
|
133
|
+
clear();
|
|
134
|
+
};
|
|
135
|
+
}, []);
|
|
136
|
+
const indicatorStyle = {
|
|
137
|
+
"--rn-refresh-top": `${progressViewOffset}px`,
|
|
138
|
+
backgroundColor: toCSSColor(progressBackgroundColor) ?? DISC
|
|
139
|
+
};
|
|
140
|
+
const arcColor = toCSSColor(colors?.[0]) ?? toCSSColor(tintColor) ?? ARC;
|
|
141
|
+
return /* @__PURE__ */ jsxs(View, {
|
|
142
|
+
...rest,
|
|
143
|
+
"aria-busy": refreshing,
|
|
144
|
+
style: [styles.area, style],
|
|
145
|
+
children: [children, /* @__PURE__ */ jsx("div", {
|
|
146
|
+
ref: indicator,
|
|
147
|
+
"aria-hidden": !refreshing,
|
|
148
|
+
"aria-label": title,
|
|
149
|
+
className: indicatorClass,
|
|
150
|
+
"data-refreshing": refreshing ? "" : void 0,
|
|
151
|
+
"data-size": size === "large" ? "large" : void 0,
|
|
152
|
+
role: "progressbar",
|
|
153
|
+
style: indicatorStyle,
|
|
154
|
+
children: /* @__PURE__ */ jsx("svg", {
|
|
155
|
+
"aria-hidden": true,
|
|
156
|
+
viewBox: "0 0 40 40",
|
|
157
|
+
children: /* @__PURE__ */ jsx("circle", {
|
|
158
|
+
cx: "20",
|
|
159
|
+
cy: "20",
|
|
160
|
+
fill: "none",
|
|
161
|
+
r: "8.75",
|
|
162
|
+
stroke: arcColor,
|
|
163
|
+
strokeLinecap: "round",
|
|
164
|
+
strokeWidth: "2.5"
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
})]
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
const styles = StyleSheet.create({ area: {
|
|
171
|
+
position: "relative",
|
|
172
|
+
overflow: "hidden"
|
|
173
|
+
} });
|
|
174
|
+
export { RefreshControl };
|
|
175
|
+
|
|
176
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/RefreshControl/index.tsx"],"sourcesContent":["import { type CSSProperties, type ReactElement, useEffect, useLayoutEffect, useRef } from 'react'\n\nimport { StyleSheet } from '../../apis/StyleSheet'\nimport { toCSSColor } from '../../style/color'\nimport { useStyleRegistry } from '../../style/StyleRegistryContext'\nimport { View } from '../View'\nimport { PULL_TARGET, pullOffset, releasesRefresh } from './pull'\nimport type { RefreshControlProps } from './types'\n\nexport type { RefreshControlProps } from './types'\n\n// Android's defaults: a black arc on a white disc.\nconst ARC = '#000000'\nconst DISC = '#FFFFFF'\n\nconst ARC_LENGTH = 2 * Math.PI * 8.75\n\nconst INDICATOR_CLASS = 'rn-refresh'\n// React sets only `data-refreshing`, `data-size`, and `--rn-refresh-top`. The rules place the\n// indicator, and a pull writes its own inline values over them.\nconst RULES = [\n '@keyframes rn-refresh-spin{to{transform:rotate(360deg)}}',\n `.${INDICATOR_CLASS}{position:absolute;top:0;left:50%;z-index:1;display:flex;width:40px;height:40px;margin-left:-20px;border-radius:50%;box-shadow:0 1px 4px rgba(0,0,0,.3);pointer-events:none;opacity:0;transform:translateY(calc(var(--rn-refresh-top) - 100%));transition:transform .2s ease-out,opacity .2s}`,\n `.${INDICATOR_CLASS}[data-size=large]{width:56px;height:56px;margin-left:-28px}`,\n `.${INDICATOR_CLASS}[data-refreshing]{opacity:1;transform:translateY(calc(var(--rn-refresh-top) + ${PULL_TARGET}px - 100%))}`,\n `.${INDICATOR_CLASS}>svg{width:100%;height:100%}`,\n `.${INDICATOR_CLASS}[data-refreshing]>svg{animation:rn-refresh-spin .75s linear infinite}`,\n `.${INDICATOR_CLASS} circle{stroke-dasharray:0 ${ARC_LENGTH}}`,\n `.${INDICATOR_CLASS}[data-refreshing] circle{stroke-dasharray:${ARC_LENGTH * 0.75} ${ARC_LENGTH}}`,\n `@media (prefers-reduced-motion:reduce){.${INDICATOR_CLASS}{transition:none}}`,\n]\n\ntype Gesture = {\n id: number\n x: number\n y: number\n pulling: boolean\n distance: number\n toLocal: DOMMatrixReadOnly\n}\n\n// Maps a finger movement into the frame of the element, as Android does for its touch events. An\n// inverted FlatList flips the element, so the pull starts at the visual bottom and goes up.\nconst frameOf = (element: Element): DOMMatrixReadOnly => {\n let toScreen = new DOMMatrix()\n for (let node: Element | null = element; node !== null; node = node.parentElement) {\n const { transform } = getComputedStyle(node)\n if (transform !== 'none') toScreen = new DOMMatrix(transform).multiply(toScreen)\n }\n return toScreen.inverse()\n}\n\nexport function RefreshControl(props: RefreshControlProps): ReactElement {\n const {\n children,\n colors,\n enabled = true,\n onRefresh,\n progressBackgroundColor,\n progressViewOffset = 0,\n refreshing,\n size = 'default',\n style,\n tintColor,\n title,\n titleColor: _titleColor,\n ...rest\n } = props\n\n const registry = useStyleRegistry()\n const indicatorClass = registry.staticClass(INDICATOR_CLASS, RULES)\n const indicator = useRef<HTMLDivElement>(null)\n const latest = useRef({ enabled, refreshing, onRefresh })\n\n useLayoutEffect(() => {\n latest.current = { enabled, refreshing, onRefresh }\n })\n\n useEffect(() => {\n const element = indicator.current\n const area = element?.parentElement\n if (!element || !area) return\n const svg = element.firstElementChild as SVGElement\n const arc = svg.firstElementChild as SVGElement\n let gesture: Gesture | null = null\n let releaseTimer: ReturnType<typeof setTimeout> | undefined\n\n const scrollTop = (): number => {\n const scroller = area.firstElementChild\n return scroller instanceof HTMLElement && scroller !== element ? scroller.scrollTop : 0\n }\n\n const draw = (distance: number): void => {\n const offset = pullOffset(distance)\n const progress = Math.min(1, offset / PULL_TARGET)\n element.style.transition = 'none'\n element.style.opacity = String(Math.min(1, offset / element.offsetHeight))\n element.style.transform = `translateY(calc(var(--rn-refresh-top) + ${offset}px - 100%))`\n svg.style.transform = `rotate(${progress * 270}deg)`\n arc.style.strokeDasharray = `${progress * 0.8 * ARC_LENGTH} ${ARC_LENGTH}`\n }\n\n const clear = (): void => {\n element.style.transition = ''\n element.style.opacity = ''\n element.style.transform = ''\n svg.style.transform = ''\n arc.style.strokeDasharray = ''\n }\n\n const touchOf = (event: TouchEvent): Touch | undefined =>\n Array.from(event.changedTouches).find((touch) => touch.identifier === gesture?.id)\n\n const onStart = (event: TouchEvent): void => {\n const touch = event.touches[0]\n const { enabled: on, refreshing: busy } = latest.current\n gesture =\n event.touches.length === 1 && touch !== undefined && on && !busy && scrollTop() <= 0\n ? {\n id: touch.identifier,\n x: touch.clientX,\n y: touch.clientY,\n pulling: false,\n distance: 0,\n toLocal: frameOf(area),\n }\n : null\n }\n\n const onMove = (event: TouchEvent): void => {\n const touch = touchOf(event)\n if (gesture === null || touch === undefined) return\n const { a, b, c, d } = gesture.toLocal\n const screenX = touch.clientX - gesture.x\n const screenY = touch.clientY - gesture.y\n const dx = a * screenX + c * screenY\n const dy = b * screenX + d * screenY\n if (!gesture.pulling) {\n if (dx === 0 && dy === 0) return\n // The first move decides: once the browser scrolls, it makes the later moves uncancelable.\n if (dy <= 0 || Math.abs(dx) > dy || scrollTop() > 0 || !event.cancelable) {\n gesture = null\n return\n }\n gesture.pulling = true\n }\n event.preventDefault()\n gesture.distance = Math.max(0, dy)\n draw(gesture.distance)\n }\n\n const onEnd = (event: TouchEvent): void => {\n if (gesture === null || touchOf(event) === undefined) return\n const { pulling, distance } = gesture\n gesture = null\n if (!pulling) return\n const refresh = event.type === 'touchend' && releasesRefresh(distance)\n // The indicator moves from the finger to its rest at once. React renders an update from a\n // touchend before a timer runs, so `refreshing` from `onRefresh` arrives first. When the app\n // doesn't set it, the indicator goes back, as on native.\n if (refresh) element.setAttribute('data-refreshing', '')\n clear()\n if (!refresh) return\n void latest.current.onRefresh?.()\n releaseTimer = setTimeout(() => {\n if (!latest.current.refreshing) element.removeAttribute('data-refreshing')\n }, 0)\n }\n\n area.addEventListener('touchstart', onStart, { passive: true })\n area.addEventListener('touchmove', onMove, { passive: false })\n area.addEventListener('touchend', onEnd)\n area.addEventListener('touchcancel', onEnd)\n return () => {\n area.removeEventListener('touchstart', onStart)\n area.removeEventListener('touchmove', onMove)\n area.removeEventListener('touchend', onEnd)\n area.removeEventListener('touchcancel', onEnd)\n clearTimeout(releaseTimer)\n clear()\n }\n }, [])\n\n const indicatorStyle = {\n '--rn-refresh-top': `${progressViewOffset}px`,\n backgroundColor: toCSSColor(progressBackgroundColor) ?? DISC,\n } as CSSProperties\n const arcColor = toCSSColor(colors?.[0]) ?? toCSSColor(tintColor) ?? ARC\n\n return (\n <View {...rest} aria-busy={refreshing} style={[styles.area, style]}>\n {children}\n <div\n ref={indicator}\n aria-hidden={!refreshing}\n aria-label={title}\n className={indicatorClass}\n data-refreshing={refreshing ? '' : undefined}\n data-size={size === 'large' ? 'large' : undefined}\n role=\"progressbar\"\n style={indicatorStyle}\n >\n <svg aria-hidden viewBox=\"0 0 40 40\">\n <circle\n cx=\"20\"\n cy=\"20\"\n fill=\"none\"\n r=\"8.75\"\n stroke={arcColor}\n strokeLinecap=\"round\"\n strokeWidth=\"2.5\"\n />\n </svg>\n </div>\n </View>\n )\n}\n\nconst styles = StyleSheet.create({\n area: { position: 'relative', overflow: 'hidden' },\n})\n"],"mappings":";;;;;;;;AAYA,MAAM,M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AS,KAAK;CAErE,OACE,qBAAC,MAAD;EAAM,GAAI;EAAM,aAAW;EAAY,OAAO,CAAC,OAAO,MAAM,KAAK;EAAjE,UAAA,CACG,UACD,oBAAC,OAAD;GACE,KAAK;GACL,eAAa,CAAC;GACd,cAAY;GACZ,WAAW;GACX,mBAAiB,aAAa,KAAK,KAAA;GACnC,aAAW,SAAS,UAAU,UAAU,KAAA;GACxC,MAAK;GACL,OAAO;GAEP,UAAA,oBAAC,OAAD;IAAK,eAAA;IAAY,SAAQ;IACvB,UAAA,oBAAC,UAAD;KACE,IAAG;KACH,IAAG;KACH,MAAK;KACL,GAAE;KACF,QAAQ;KACR,eAAc;KACd,aAAY;IACb,CAAA;GACE,CAAA;EACF,CAAA,CACD;;AAEV;AAEA,MAAM,SAAS,WAAW,OAAO,EAC/B,MAAM;CAAE,UAAU;CAAY,UAAU;AAAS,EACnD,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const DRAG_RATE = .5;
|
|
2
|
+
/**
|
|
3
|
+
* The distance of the indicator for a finger distance. It follows the finger at half the speed,
|
|
4
|
+
* and slows down past the target, so it never goes past twice the target.
|
|
5
|
+
*/
|
|
6
|
+
const pullOffset = (distance) => {
|
|
7
|
+
const travel = Math.max(0, distance) * DRAG_RATE;
|
|
8
|
+
if (travel <= 64) return travel;
|
|
9
|
+
const extra = travel - 64;
|
|
10
|
+
return 64 + 64 * extra / (extra + 64);
|
|
11
|
+
};
|
|
12
|
+
/** A release after this finger distance refreshes. */
|
|
13
|
+
const releasesRefresh = (distance) => distance * DRAG_RATE > 64;
|
|
14
|
+
export { pullOffset, releasesRefresh };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=pull.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pull.js","names":[],"sources":["../../../src/components/RefreshControl/pull.ts"],"sourcesContent":["// The numbers of Android's SwipeRefreshLayout, in CSS pixels.\n\n// How far the indicator moves before a release refreshes.\nexport const PULL_TARGET = 64\n\n// The indicator moves half the finger distance.\nconst DRAG_RATE = 0.5\n\n/**\n * The distance of the indicator for a finger distance. It follows the finger at half the speed,\n * and slows down past the target, so it never goes past twice the target.\n */\nexport const pullOffset = (distance: number): number => {\n const travel = Math.max(0, distance) * DRAG_RATE\n if (travel <= PULL_TARGET) return travel\n const extra = travel - PULL_TARGET\n return PULL_TARGET + (PULL_TARGET * extra) / (extra + PULL_TARGET)\n}\n\n/** A release after this finger distance refreshes. */\nexport const releasesRefresh = (distance: number): boolean => distance * DRAG_RATE > PULL_TARGET\n"],"mappings":"AAMA,MAAM,YAAY;;;;;AAMlB,MAAa,cAAc,aAA6B;CACtD,MAAM,SAAS,KAAK,IAAI,GAAG,QAAQ,IAAI;CACvC,IAAI,UAAA,IAAuB,OAAO;CAClC,MAAM,QAAQ,SAAA;CACd,OAAA,KAAA,KAAoC,SAAU,QAAA;AAChD;;AAGA,MAAa,mBAAmB,aAA8B,WAAW,YAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ViewProps } from "../View/types.js";
|
|
2
|
+
export interface RefreshControlProps extends ViewProps {
|
|
3
|
+
refreshing: boolean;
|
|
4
|
+
onRefresh?: (() => void | Promise<void>) | undefined;
|
|
5
|
+
progressViewOffset?: number | undefined;
|
|
6
|
+
colors?: ReadonlyArray<string> | undefined;
|
|
7
|
+
enabled?: boolean | undefined;
|
|
8
|
+
progressBackgroundColor?: string | undefined;
|
|
9
|
+
size?: "default" | "large" | undefined;
|
|
10
|
+
tintColor?: string | undefined;
|
|
11
|
+
title?: string | undefined;
|
|
12
|
+
titleColor?: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { NativeScrollEvent, NativeScrollPoint, NativeScrollRectangle, NativeScrollSize, ScrollEvent, ScrollToOptions, ScrollViewInstance, ScrollViewProps } from "./types.js";
|
|
2
|
+
import { ReactElement } from "react";
|
|
3
|
+
export declare function ScrollView(props: ScrollViewProps): ReactElement;
|
|
4
|
+
export type { NativeScrollEvent, NativeScrollPoint, NativeScrollRectangle, NativeScrollSize, ScrollEvent, ScrollToOptions, ScrollViewInstance, ScrollViewProps };
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|