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.
Files changed (64) hide show
  1. package/lib/commonjs/components/Channel/Channel.js +296 -293
  2. package/lib/commonjs/components/Channel/Channel.js.map +1 -1
  3. package/lib/commonjs/components/Channel/hooks/useMessageListPagination.js +133 -147
  4. package/lib/commonjs/components/Channel/hooks/useMessageListPagination.js.map +1 -1
  5. package/lib/commonjs/components/KeyboardCompatibleView/KeyboardCompatibleView.js +7 -12
  6. package/lib/commonjs/components/KeyboardCompatibleView/KeyboardCompatibleView.js.map +1 -1
  7. package/lib/commonjs/components/MessageList/MessageList.js +167 -179
  8. package/lib/commonjs/components/MessageList/MessageList.js.map +1 -1
  9. package/lib/commonjs/components/MessageList/hooks/useMessageList.js +60 -37
  10. package/lib/commonjs/components/MessageList/hooks/useMessageList.js.map +1 -1
  11. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +450 -459
  12. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  13. package/lib/commonjs/contexts/messagesContext/MessagesContext.js.map +1 -1
  14. package/lib/commonjs/hooks/index.js +11 -0
  15. package/lib/commonjs/hooks/index.js.map +1 -1
  16. package/lib/commonjs/hooks/useStableCallback.js +13 -0
  17. package/lib/commonjs/hooks/useStableCallback.js.map +1 -0
  18. package/lib/commonjs/version.json +1 -1
  19. package/lib/module/components/Channel/Channel.js +296 -293
  20. package/lib/module/components/Channel/Channel.js.map +1 -1
  21. package/lib/module/components/Channel/hooks/useMessageListPagination.js +133 -147
  22. package/lib/module/components/Channel/hooks/useMessageListPagination.js.map +1 -1
  23. package/lib/module/components/KeyboardCompatibleView/KeyboardCompatibleView.js +7 -12
  24. package/lib/module/components/KeyboardCompatibleView/KeyboardCompatibleView.js.map +1 -1
  25. package/lib/module/components/MessageList/MessageList.js +167 -179
  26. package/lib/module/components/MessageList/MessageList.js.map +1 -1
  27. package/lib/module/components/MessageList/hooks/useMessageList.js +60 -37
  28. package/lib/module/components/MessageList/hooks/useMessageList.js.map +1 -1
  29. package/lib/module/contexts/messageInputContext/MessageInputContext.js +450 -459
  30. package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  31. package/lib/module/contexts/messagesContext/MessagesContext.js.map +1 -1
  32. package/lib/module/hooks/index.js +11 -0
  33. package/lib/module/hooks/index.js.map +1 -1
  34. package/lib/module/hooks/useStableCallback.js +13 -0
  35. package/lib/module/hooks/useStableCallback.js.map +1 -0
  36. package/lib/module/version.json +1 -1
  37. package/lib/typescript/components/Channel/Channel.d.ts.map +1 -1
  38. package/lib/typescript/components/Channel/hooks/useMessageListPagination.d.ts +3 -3
  39. package/lib/typescript/components/Channel/hooks/useMessageListPagination.d.ts.map +1 -1
  40. package/lib/typescript/components/KeyboardCompatibleView/KeyboardCompatibleView.d.ts +3 -0
  41. package/lib/typescript/components/KeyboardCompatibleView/KeyboardCompatibleView.d.ts.map +1 -1
  42. package/lib/typescript/components/MessageList/MessageList.d.ts.map +1 -1
  43. package/lib/typescript/components/MessageList/hooks/useMessageList.d.ts +4 -0
  44. package/lib/typescript/components/MessageList/hooks/useMessageList.d.ts.map +1 -1
  45. package/lib/typescript/contexts/messageInputContext/MessageInputContext.d.ts.map +1 -1
  46. package/lib/typescript/contexts/messagesContext/MessagesContext.d.ts +1 -1
  47. package/lib/typescript/contexts/messagesContext/MessagesContext.d.ts.map +1 -1
  48. package/lib/typescript/hooks/index.d.ts +1 -0
  49. package/lib/typescript/hooks/index.d.ts.map +1 -1
  50. package/lib/typescript/hooks/useStableCallback.d.ts +26 -0
  51. package/lib/typescript/hooks/useStableCallback.d.ts.map +1 -0
  52. package/package.json +1 -1
  53. package/src/components/Channel/Channel.tsx +462 -431
  54. package/src/components/Channel/__tests__/Channel.test.js +8 -3
  55. package/src/components/Channel/hooks/useMessageListPagination.tsx +152 -147
  56. package/src/components/KeyboardCompatibleView/KeyboardCompatibleView.tsx +6 -4
  57. package/src/components/MessageList/MessageList.tsx +147 -112
  58. package/src/components/MessageList/hooks/useMessageList.ts +69 -38
  59. package/src/contexts/messageInputContext/MessageInputContext.tsx +293 -267
  60. package/src/contexts/messageInputContext/__tests__/pickFile.test.tsx +2 -1
  61. package/src/contexts/messagesContext/MessagesContext.tsx +1 -0
  62. package/src/hooks/index.ts +1 -0
  63. package/src/hooks/useStableCallback.ts +37 -0
  64. 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, 2]])(
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
 
@@ -322,6 +322,7 @@ export type MessagesContextValue<
322
322
  messageInput?: string;
323
323
  threadMessages?: ChannelState<StreamChatGenerics>['threads'][string];
324
324
  },
325
+ throttled?: boolean,
325
326
  ) => void;
326
327
  /**
327
328
  * Custom UI component to display enriched url preview.
@@ -3,3 +3,4 @@ export * from './useStreami18n';
3
3
  export * from './useViewport';
4
4
  export * from './useScreenDimensions';
5
5
  export * from './useStateStore';
6
+ export * from './useStableCallback';
@@ -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
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "6.7.3-beta.1"
2
+ "version": "6.7.3-beta.3"
3
3
  }