@legendapp/list 3.0.0-beta.9 → 3.0.1

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.
Files changed (48) hide show
  1. package/.DS_Store +0 -0
  2. package/CHANGELOG.md +27 -1
  3. package/README.md +8 -2
  4. package/animated.d.ts +659 -5
  5. package/animated.js +2 -2
  6. package/animated.mjs +1 -1
  7. package/keyboard-legacy.d.ts +226 -0
  8. package/keyboard-legacy.js +456 -0
  9. package/keyboard-legacy.mjs +435 -0
  10. package/keyboard.d.ts +261 -9
  11. package/keyboard.js +114 -135
  12. package/keyboard.mjs +115 -137
  13. package/package.json +55 -5
  14. package/{types-1Hgg1rTO.d.mts → react-native.d.ts} +269 -284
  15. package/react-native.js +6471 -0
  16. package/react-native.mjs +6442 -0
  17. package/{types-1Hgg1rTO.d.ts → react-native.web.d.ts} +330 -283
  18. package/react-native.web.js +7125 -0
  19. package/react-native.web.mjs +7096 -0
  20. package/react.d.ts +771 -0
  21. package/react.js +7125 -0
  22. package/react.mjs +7096 -0
  23. package/reanimated.d.ts +681 -8
  24. package/reanimated.js +225 -38
  25. package/reanimated.mjs +227 -40
  26. package/section-list.d.ts +682 -7
  27. package/section-list.js +85 -3854
  28. package/section-list.mjs +83 -3853
  29. package/animated.d.mts +0 -9
  30. package/index.d.mts +0 -23
  31. package/index.d.ts +0 -23
  32. package/index.js +0 -3935
  33. package/index.mjs +0 -3907
  34. package/index.native.d.mts +0 -23
  35. package/index.native.d.ts +0 -23
  36. package/index.native.js +0 -3739
  37. package/index.native.mjs +0 -3711
  38. package/keyboard-controller.d.mts +0 -12
  39. package/keyboard-controller.d.ts +0 -12
  40. package/keyboard-controller.js +0 -69
  41. package/keyboard-controller.mjs +0 -48
  42. package/keyboard.d.mts +0 -13
  43. package/reanimated.d.mts +0 -18
  44. package/section-list.d.mts +0 -113
  45. package/section-list.native.d.mts +0 -113
  46. package/section-list.native.d.ts +0 -113
  47. package/section-list.native.js +0 -3897
  48. package/section-list.native.mjs +0 -3876
package/keyboard.mjs CHANGED
@@ -1,160 +1,138 @@
1
1
  import * as React from 'react';
2
- import { forwardRef, useRef, useCallback } from 'react';
3
- import { Platform } from 'react-native';
4
- import { useKeyboardHandler } from 'react-native-keyboard-controller';
5
- import { useAnimatedRef, useSharedValue, useAnimatedScrollHandler, runOnJS, useAnimatedProps, useAnimatedStyle } from 'react-native-reanimated';
2
+ import { useRef, useEffect, useMemo, useCallback, useLayoutEffect } from 'react';
3
+ import { KeyboardChatScrollView, KeyboardController } from 'react-native-keyboard-controller';
4
+ import { useSharedValue } from 'react-native-reanimated';
5
+ import { internal } from '@legendapp/list/react-native';
6
6
  import { AnimatedLegendList } from '@legendapp/list/reanimated';
7
7
 
8
8
  // src/integrations/keyboard.tsx
9
-
10
- // src/utils/helpers.ts
11
- function isFunction(obj) {
12
- return typeof obj === "function";
9
+ var { typedForwardRef, useCombinedRef } = internal;
10
+ if (typeof __DEV__ !== "undefined" && __DEV__ && !KeyboardChatScrollView) {
11
+ console.warn(
12
+ "[legend-list] KeyboardAwareLegendList requires a recent react-native-keyboard-controller with KeyboardChatScrollView. Please upgrade react-native-keyboard-controller to at least 1.21.7."
13
+ );
13
14
  }
14
-
15
- // src/hooks/useCombinedRef.ts
16
- var useCombinedRef = (...refs) => {
17
- const callback = useCallback((element) => {
18
- for (const ref of refs) {
19
- if (!ref) {
20
- continue;
15
+ function useKeyboardChatComposerInset(listRef, composerRef, initialHeight = 0) {
16
+ const contentInsetEndAdjustment = useSharedValue(initialHeight);
17
+ const lastHeightRef = useRef(void 0);
18
+ const reportHeight = useCallback(
19
+ (height) => {
20
+ var _a;
21
+ if (Number.isFinite(height) && height !== lastHeightRef.current) {
22
+ lastHeightRef.current = height;
23
+ contentInsetEndAdjustment.value = height;
24
+ (_a = listRef.current) == null ? void 0 : _a.reportContentInset({ bottom: height });
21
25
  }
22
- if (isFunction(ref)) {
23
- ref(element);
24
- } else {
25
- ref.current = element;
26
+ },
27
+ [contentInsetEndAdjustment, listRef]
28
+ );
29
+ useLayoutEffect(() => {
30
+ var _a;
31
+ (_a = composerRef.current) == null ? void 0 : _a.measure((_x, _y, _width, height) => {
32
+ reportHeight(height);
33
+ });
34
+ }, [composerRef, reportHeight]);
35
+ const onComposerLayout = useCallback(
36
+ (event) => {
37
+ reportHeight(event.nativeEvent.layout.height);
38
+ },
39
+ [reportHeight]
40
+ );
41
+ return { contentInsetEndAdjustment, onComposerLayout };
42
+ }
43
+ function useKeyboardScrollToEnd({ freeze: freezeProp, listRef }) {
44
+ const internalFreeze = useSharedValue(false);
45
+ const freeze = freezeProp != null ? freezeProp : internalFreeze;
46
+ const scrollMessageToEnd = useCallback(
47
+ async ({ animated, closeKeyboard }) => {
48
+ const listRefCurrent = listRef.current;
49
+ if (listRefCurrent) {
50
+ freeze.set(true);
51
+ const dismissPromise = closeKeyboard && KeyboardController.dismiss();
52
+ const scrollPromise = listRefCurrent.scrollToEnd({ animated });
53
+ await Promise.all([scrollPromise, dismissPromise]);
54
+ freeze.set(false);
26
55
  }
27
- }
28
- }, refs);
29
- return callback;
30
- };
31
-
32
- // src/integrations/keyboard.tsx
33
- var KeyboardAvoidingLegendList = forwardRef(function KeyboardAvoidingLegendList2(props, forwardedRef) {
56
+ },
57
+ [freeze, listRef]
58
+ );
59
+ return {
60
+ freeze,
61
+ scrollMessageToEnd
62
+ };
63
+ }
64
+ var KeyboardAwareLegendList = typedForwardRef(function KeyboardAwareLegendList2(props, forwardedRef) {
34
65
  const {
35
- contentInset: contentInsetProp,
36
- horizontal,
37
- onScroll: onScrollProp,
38
- safeAreaInsetBottom = 0,
66
+ anchoredEndSpace,
67
+ applyWorkaroundForContentInsetHitTestBug,
68
+ contentInsetEndAdjustment,
69
+ freeze,
70
+ keyboardLiftBehavior,
71
+ keyboardOffset,
39
72
  ...rest
40
73
  } = props;
41
74
  const refLegendList = useRef(null);
42
75
  const combinedRef = useCombinedRef(forwardedRef, refLegendList);
43
- const scrollViewRef = useAnimatedRef();
44
- const scrollOffsetY = useSharedValue(0);
45
- const animatedOffsetY = useSharedValue(null);
46
- const scrollOffsetAtKeyboardStart = useSharedValue(0);
47
- const keyboardInset = useSharedValue(0);
48
- const keyboardHeight = useSharedValue(0);
49
- const isOpening = useSharedValue(false);
50
- const didInteractive = useSharedValue(false);
51
- const scrollHandler = useAnimatedScrollHandler(
52
- (event) => {
53
- scrollOffsetY.value = event.contentOffset[horizontal ? "x" : "y"];
54
- if (onScrollProp) {
55
- runOnJS(onScrollProp)(event);
76
+ const blankSpace = useSharedValue(0);
77
+ useEffect(() => {
78
+ if (!anchoredEndSpace) {
79
+ blankSpace.value = 0;
80
+ }
81
+ }, [anchoredEndSpace, blankSpace]);
82
+ const anchoredEndSpaceWithBlankSpace = useMemo(() => {
83
+ if (!anchoredEndSpace) {
84
+ return void 0;
85
+ }
86
+ return {
87
+ ...anchoredEndSpace,
88
+ includeInEndInset: true,
89
+ onSizeChanged: (size) => {
90
+ var _a;
91
+ blankSpace.value = size;
92
+ (_a = anchoredEndSpace.onSizeChanged) == null ? void 0 : _a.call(anchoredEndSpace, size);
56
93
  }
57
- },
58
- [onScrollProp, horizontal]
59
- );
60
- const setScrollProcessingEnabled = useCallback(
61
- (enabled) => {
62
- var _a;
63
- (_a = refLegendList.current) == null ? void 0 : _a.setScrollProcessingEnabled(enabled);
64
- },
65
- [refLegendList]
66
- );
67
- useKeyboardHandler(
68
- // biome-ignore assist/source/useSortedKeys: prefer start/move/end
69
- {
70
- onStart: (event) => {
71
- "worklet";
72
- if (!didInteractive.get()) {
73
- if (event.height > 0) {
74
- keyboardHeight.set(event.height - safeAreaInsetBottom);
75
- }
76
- isOpening.set(event.progress > 0);
77
- scrollOffsetAtKeyboardStart.value = scrollOffsetY.value;
78
- animatedOffsetY.set(scrollOffsetY.value);
79
- runOnJS(setScrollProcessingEnabled)(false);
80
- }
81
- },
82
- onInteractive: () => {
83
- "worklet";
84
- if (!didInteractive.get()) {
85
- didInteractive.set(true);
86
- }
87
- },
88
- onMove: (event) => {
89
- "worklet";
90
- if (!didInteractive.get()) {
91
- const vIsOpening = isOpening.get();
92
- const vKeyboardHeight = keyboardHeight.get();
93
- const vProgress = vIsOpening ? event.progress : 1 - event.progress;
94
- const targetOffset = scrollOffsetAtKeyboardStart.value + (vIsOpening ? vKeyboardHeight : -vKeyboardHeight) * vProgress;
95
- scrollOffsetY.value = targetOffset;
96
- animatedOffsetY.set(targetOffset);
97
- if (!horizontal) {
98
- keyboardInset.value = Math.max(0, event.height - safeAreaInsetBottom);
99
- }
100
- }
101
- },
102
- onEnd: (event) => {
103
- "worklet";
104
- const wasInteractive = didInteractive.get();
105
- if (wasInteractive && event.progress === 0 && event.target > 0) {
106
- return;
107
- }
108
- if (!wasInteractive) {
109
- const vIsOpening = isOpening.get();
110
- const vKeyboardHeight = keyboardHeight.get();
111
- const targetOffset = scrollOffsetAtKeyboardStart.value + (vIsOpening ? vKeyboardHeight : -vKeyboardHeight) * (vIsOpening ? event.progress : 1 - event.progress);
112
- scrollOffsetY.value = targetOffset;
113
- animatedOffsetY.set(targetOffset);
114
- runOnJS(setScrollProcessingEnabled)(true);
115
- }
116
- didInteractive.set(false);
117
- if (!horizontal) {
118
- keyboardInset.value = Math.max(0, event.height - safeAreaInsetBottom);
94
+ };
95
+ }, [anchoredEndSpace, blankSpace]);
96
+ const onContentInsetChange = useCallback((insets) => {
97
+ var _a;
98
+ (_a = refLegendList.current) == null ? void 0 : _a.reportContentInset(insets);
99
+ }, []);
100
+ const memoList = useCallback(
101
+ (scrollProps) => {
102
+ return /* @__PURE__ */ React.createElement(
103
+ KeyboardChatScrollView,
104
+ {
105
+ ...scrollProps,
106
+ applyWorkaroundForContentInsetHitTestBug,
107
+ blankSpace,
108
+ extraContentPadding: contentInsetEndAdjustment,
109
+ freeze,
110
+ keyboardLiftBehavior,
111
+ offset: keyboardOffset,
112
+ onContentInsetChange
119
113
  }
120
- }
114
+ );
121
115
  },
122
- [scrollViewRef, safeAreaInsetBottom]
116
+ [
117
+ applyWorkaroundForContentInsetHitTestBug,
118
+ blankSpace,
119
+ contentInsetEndAdjustment,
120
+ freeze,
121
+ keyboardLiftBehavior,
122
+ keyboardOffset,
123
+ onContentInsetChange
124
+ ]
123
125
  );
124
- const animatedProps = useAnimatedProps(() => {
125
- "worklet";
126
- var _a, _b, _c, _d;
127
- const baseProps = {
128
- contentOffset: animatedOffsetY.value === null ? void 0 : {
129
- x: 0,
130
- y: animatedOffsetY.value
131
- }
132
- };
133
- return Platform.OS === "ios" ? Object.assign(baseProps, {
134
- contentInset: {
135
- bottom: ((_a = contentInsetProp == null ? void 0 : contentInsetProp.bottom) != null ? _a : 0) + (horizontal ? 0 : keyboardInset.value),
136
- left: (_b = contentInsetProp == null ? void 0 : contentInsetProp.left) != null ? _b : 0,
137
- right: (_c = contentInsetProp == null ? void 0 : contentInsetProp.right) != null ? _c : 0,
138
- top: (_d = contentInsetProp == null ? void 0 : contentInsetProp.top) != null ? _d : 0
139
- }
140
- }) : baseProps;
141
- });
142
- const style = Platform.OS !== "ios" ? useAnimatedStyle(() => ({
143
- marginBottom: keyboardInset.value
144
- })) : void 0;
126
+ const AnimatedLegendListInternal = AnimatedLegendList;
145
127
  return /* @__PURE__ */ React.createElement(
146
- AnimatedLegendList,
128
+ AnimatedLegendListInternal,
147
129
  {
148
- ...rest,
149
- animatedProps,
150
- keyboardDismissMode: "interactive",
151
- onScroll: scrollHandler,
130
+ anchoredEndSpace: anchoredEndSpaceWithBlankSpace,
152
131
  ref: combinedRef,
153
- refScrollView: scrollViewRef,
154
- scrollIndicatorInsets: { bottom: 0, top: 0 },
155
- style
132
+ renderScrollComponent: memoList,
133
+ ...rest
156
134
  }
157
135
  );
158
136
  });
159
137
 
160
- export { KeyboardAvoidingLegendList, KeyboardAvoidingLegendList as LegendList };
138
+ export { KeyboardAwareLegendList, useKeyboardChatComposerInset, useKeyboardScrollToEnd };
package/package.json CHANGED
@@ -1,13 +1,63 @@
1
1
  {
2
2
  "name": "@legendapp/list",
3
- "version": "3.0.0-beta.9",
3
+ "version": "3.0.1",
4
4
  "description": "Legend List is a drop-in replacement for FlatList with much better performance and supporting dynamically sized items.",
5
5
  "sideEffects": false,
6
6
  "private": false,
7
- "main": "./index.js",
8
- "module": "./index.mjs",
9
- "types": "./index.d.ts",
10
- "react-native": "./index.native.js",
7
+ "exports": {
8
+ "./animated": {
9
+ "types": "./animated.d.ts",
10
+ "import": "./animated.mjs",
11
+ "require": "./animated.js",
12
+ "default": "./animated.js"
13
+ },
14
+ "./keyboard": {
15
+ "types": "./keyboard.d.ts",
16
+ "import": "./keyboard.mjs",
17
+ "require": "./keyboard.js",
18
+ "default": "./keyboard.js"
19
+ },
20
+ "./keyboard-legacy": {
21
+ "types": "./keyboard-legacy.d.ts",
22
+ "import": "./keyboard-legacy.mjs",
23
+ "require": "./keyboard-legacy.js",
24
+ "default": "./keyboard-legacy.js"
25
+ },
26
+ "./reanimated": {
27
+ "types": "./reanimated.d.ts",
28
+ "import": "./reanimated.mjs",
29
+ "require": "./reanimated.js",
30
+ "default": "./reanimated.js"
31
+ },
32
+ "./react-native": {
33
+ "types": "./react-native.d.ts",
34
+ "browser": {
35
+ "import": "./react-native.web.mjs",
36
+ "require": "./react-native.web.js",
37
+ "default": "./react-native.web.js"
38
+ },
39
+ "react-native": {
40
+ "import": "./react-native.mjs",
41
+ "require": "./react-native.js",
42
+ "default": "./react-native.js"
43
+ },
44
+ "import": "./react-native.web.mjs",
45
+ "require": "./react-native.web.js",
46
+ "default": "./react-native.web.js"
47
+ },
48
+ "./section-list": {
49
+ "types": "./section-list.d.ts",
50
+ "import": "./section-list.mjs",
51
+ "require": "./section-list.js",
52
+ "default": "./section-list.js"
53
+ },
54
+ "./react": {
55
+ "types": "./react.d.ts",
56
+ "import": "./react.mjs",
57
+ "require": "./react.js",
58
+ "default": "./react.js"
59
+ }
60
+ },
11
61
  "files": [
12
62
  "**"
13
63
  ],