stream-chat-react-native-core 6.7.3-beta.1 → 6.7.3-beta.3
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/lib/commonjs/components/Channel/Channel.js +296 -293
- package/lib/commonjs/components/Channel/Channel.js.map +1 -1
- package/lib/commonjs/components/Channel/hooks/useMessageListPagination.js +133 -147
- package/lib/commonjs/components/Channel/hooks/useMessageListPagination.js.map +1 -1
- package/lib/commonjs/components/KeyboardCompatibleView/KeyboardCompatibleView.js +7 -12
- package/lib/commonjs/components/KeyboardCompatibleView/KeyboardCompatibleView.js.map +1 -1
- package/lib/commonjs/components/MessageList/MessageList.js +167 -179
- package/lib/commonjs/components/MessageList/MessageList.js.map +1 -1
- package/lib/commonjs/components/MessageList/hooks/useMessageList.js +60 -37
- package/lib/commonjs/components/MessageList/hooks/useMessageList.js.map +1 -1
- package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +450 -459
- package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
- package/lib/commonjs/contexts/messagesContext/MessagesContext.js.map +1 -1
- package/lib/commonjs/hooks/index.js +11 -0
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/useStableCallback.js +13 -0
- package/lib/commonjs/hooks/useStableCallback.js.map +1 -0
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/Channel/Channel.js +296 -293
- package/lib/module/components/Channel/Channel.js.map +1 -1
- package/lib/module/components/Channel/hooks/useMessageListPagination.js +133 -147
- package/lib/module/components/Channel/hooks/useMessageListPagination.js.map +1 -1
- package/lib/module/components/KeyboardCompatibleView/KeyboardCompatibleView.js +7 -12
- package/lib/module/components/KeyboardCompatibleView/KeyboardCompatibleView.js.map +1 -1
- package/lib/module/components/MessageList/MessageList.js +167 -179
- package/lib/module/components/MessageList/MessageList.js.map +1 -1
- package/lib/module/components/MessageList/hooks/useMessageList.js +60 -37
- package/lib/module/components/MessageList/hooks/useMessageList.js.map +1 -1
- package/lib/module/contexts/messageInputContext/MessageInputContext.js +450 -459
- package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
- package/lib/module/contexts/messagesContext/MessagesContext.js.map +1 -1
- package/lib/module/hooks/index.js +11 -0
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useStableCallback.js +13 -0
- package/lib/module/hooks/useStableCallback.js.map +1 -0
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/Channel/Channel.d.ts.map +1 -1
- package/lib/typescript/components/Channel/hooks/useMessageListPagination.d.ts +3 -3
- package/lib/typescript/components/Channel/hooks/useMessageListPagination.d.ts.map +1 -1
- package/lib/typescript/components/KeyboardCompatibleView/KeyboardCompatibleView.d.ts +3 -0
- package/lib/typescript/components/KeyboardCompatibleView/KeyboardCompatibleView.d.ts.map +1 -1
- package/lib/typescript/components/MessageList/MessageList.d.ts.map +1 -1
- package/lib/typescript/components/MessageList/hooks/useMessageList.d.ts +4 -0
- package/lib/typescript/components/MessageList/hooks/useMessageList.d.ts.map +1 -1
- package/lib/typescript/contexts/messageInputContext/MessageInputContext.d.ts.map +1 -1
- package/lib/typescript/contexts/messagesContext/MessagesContext.d.ts +1 -1
- package/lib/typescript/contexts/messagesContext/MessagesContext.d.ts.map +1 -1
- package/lib/typescript/hooks/index.d.ts +1 -0
- package/lib/typescript/hooks/index.d.ts.map +1 -1
- package/lib/typescript/hooks/useStableCallback.d.ts +26 -0
- package/lib/typescript/hooks/useStableCallback.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/components/Channel/Channel.tsx +462 -431
- package/src/components/Channel/__tests__/Channel.test.js +8 -3
- package/src/components/Channel/hooks/useMessageListPagination.tsx +152 -147
- package/src/components/KeyboardCompatibleView/KeyboardCompatibleView.tsx +6 -4
- package/src/components/MessageList/MessageList.tsx +147 -112
- package/src/components/MessageList/hooks/useMessageList.ts +69 -38
- package/src/contexts/messageInputContext/MessageInputContext.tsx +293 -267
- package/src/contexts/messageInputContext/__tests__/pickFile.test.tsx +2 -1
- package/src/contexts/messagesContext/MessagesContext.tsx +1 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useStableCallback.ts +37 -0
- package/src/version.json +1 -1
|
@@ -61,7 +61,7 @@ describe("MessageInputContext's pickFile", () => {
|
|
|
61
61
|
maxNumberOfFiles: 2,
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
it.each([[3,
|
|
64
|
+
it.each([[3, 1]])(
|
|
65
65
|
'run pickFile when numberOfUploads is %d and alert is triggered %d number of times',
|
|
66
66
|
async (numberOfUploads, numberOfTimesCalled) => {
|
|
67
67
|
const { rerender, result } = renderHook(() => useMessageInputContext(), {
|
|
@@ -87,6 +87,7 @@ describe("MessageInputContext's pickFile", () => {
|
|
|
87
87
|
});
|
|
88
88
|
|
|
89
89
|
expect(Alert.alert).toHaveBeenCalledTimes(numberOfTimesCalled);
|
|
90
|
+
expect(Alert.alert).toHaveBeenCalledWith('Maximum number of files reached');
|
|
90
91
|
},
|
|
91
92
|
);
|
|
92
93
|
|
package/src/hooks/index.ts
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useCallback, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
export type StableCallback<A extends unknown[], R> = (...args: A) => R;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A utility hook implementing a stable callback. It takes in an unstable method that
|
|
7
|
+
* is supposed to be invoked somewhere deeper in the DOM tree without making it
|
|
8
|
+
* change its reference every time the parent component rerenders. It will also return
|
|
9
|
+
* the value of the callback if it does return one.
|
|
10
|
+
* A common use-case would be having a function whose invocation depends on state
|
|
11
|
+
* somewhere high up in the DOM tree and wanting to use the same function deeper
|
|
12
|
+
* down, for example in a leaf node and simply using useCallback results in
|
|
13
|
+
* cascading dependency hell. If we wrap it in useStableCallback, we would be able
|
|
14
|
+
* to:
|
|
15
|
+
* - Use the same function as a dependency of another hook (since it is stable)
|
|
16
|
+
* - Still invoke it and get the latest state
|
|
17
|
+
*
|
|
18
|
+
* **Caveats:**
|
|
19
|
+
* - Never wrap a function that is supposed to return a React.ReactElement in
|
|
20
|
+
* useStableCallback, since React will not know that the DOM needs to be updated
|
|
21
|
+
* whenever the callback value changes (for example, renderItem from FlatList must
|
|
22
|
+
* never be wrapped in this hook)
|
|
23
|
+
* - Always prefer using a standard useCallback/stable function wherever possible
|
|
24
|
+
* (the purpose of useStableCallback is to bridge the gap between top level contexts
|
|
25
|
+
* and cascading rereders in downstream components - **not** as an escape hatch)
|
|
26
|
+
* @param callback - the callback we want to stabilize
|
|
27
|
+
*/
|
|
28
|
+
export const useStableCallback = <A extends unknown[], R>(
|
|
29
|
+
callback: StableCallback<A, R>,
|
|
30
|
+
): StableCallback<A, R> => {
|
|
31
|
+
const ref = useRef(callback);
|
|
32
|
+
ref.current = callback;
|
|
33
|
+
|
|
34
|
+
return useCallback<StableCallback<A, R>>((...args) => {
|
|
35
|
+
return ref.current(...args);
|
|
36
|
+
}, []);
|
|
37
|
+
};
|
package/src/version.json
CHANGED