stream-chat-react-native-core 9.0.0-beta.36 → 9.0.0-beta.37

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 (44) hide show
  1. package/lib/commonjs/version.json +1 -1
  2. package/lib/module/version.json +1 -1
  3. package/package.json +1 -1
  4. package/src/version.json +1 -1
  5. package/lib/commonjs/components/BottomSheetCompatibility/BottomSheetModal.js +0 -8
  6. package/lib/commonjs/components/BottomSheetCompatibility/BottomSheetModal.js.map +0 -1
  7. package/lib/commonjs/components/ChannelList/utils.js +0 -51
  8. package/lib/commonjs/components/ChannelList/utils.js.map +0 -1
  9. package/lib/commonjs/components/KeyboardCompatibleView/KeyboardCompatibleViewFC.js +0 -215
  10. package/lib/commonjs/components/KeyboardCompatibleView/KeyboardCompatibleViewFC.js.map +0 -1
  11. package/lib/commonjs/components/MessageInput/components/NativeAttachmentPicker.js +0 -8
  12. package/lib/commonjs/components/MessageInput/components/NativeAttachmentPicker.js.map +0 -1
  13. package/lib/commonjs/components/MessageList/utils/getLastReceivedMessageFlashList.js +0 -15
  14. package/lib/commonjs/components/MessageList/utils/getLastReceivedMessageFlashList.js.map +0 -1
  15. package/lib/commonjs/components/docs/data.js +0 -476
  16. package/lib/commonjs/components/docs/data.js.map +0 -1
  17. package/lib/module/components/BottomSheetCompatibility/BottomSheetModal.js +0 -8
  18. package/lib/module/components/BottomSheetCompatibility/BottomSheetModal.js.map +0 -1
  19. package/lib/module/components/ChannelList/utils.js +0 -51
  20. package/lib/module/components/ChannelList/utils.js.map +0 -1
  21. package/lib/module/components/KeyboardCompatibleView/KeyboardCompatibleViewFC.js +0 -215
  22. package/lib/module/components/KeyboardCompatibleView/KeyboardCompatibleViewFC.js.map +0 -1
  23. package/lib/module/components/MessageInput/components/NativeAttachmentPicker.js +0 -8
  24. package/lib/module/components/MessageInput/components/NativeAttachmentPicker.js.map +0 -1
  25. package/lib/module/components/MessageList/utils/getLastReceivedMessageFlashList.js +0 -15
  26. package/lib/module/components/MessageList/utils/getLastReceivedMessageFlashList.js.map +0 -1
  27. package/lib/module/components/docs/data.js +0 -476
  28. package/lib/module/components/docs/data.js.map +0 -1
  29. package/lib/typescript/components/BottomSheetCompatibility/BottomSheetModal.d.ts +0 -8
  30. package/lib/typescript/components/BottomSheetCompatibility/BottomSheetModal.d.ts.map +0 -1
  31. package/lib/typescript/components/ChannelList/utils.d.ts +0 -22
  32. package/lib/typescript/components/ChannelList/utils.d.ts.map +0 -1
  33. package/lib/typescript/components/KeyboardCompatibleView/KeyboardCompatibleViewFC.d.ts +0 -10
  34. package/lib/typescript/components/KeyboardCompatibleView/KeyboardCompatibleViewFC.d.ts.map +0 -1
  35. package/lib/typescript/components/MessageInput/components/NativeAttachmentPicker.d.ts +0 -8
  36. package/lib/typescript/components/MessageInput/components/NativeAttachmentPicker.d.ts.map +0 -1
  37. package/lib/typescript/components/MessageList/utils/getLastReceivedMessageFlashList.d.ts +0 -3
  38. package/lib/typescript/components/MessageList/utils/getLastReceivedMessageFlashList.d.ts.map +0 -1
  39. package/src/components/BottomSheetCompatibility/BottomSheetModal.tsx +0 -16
  40. package/src/components/ChannelList/utils.ts +0 -76
  41. package/src/components/KeyboardCompatibleView/KeyboardCompatibleViewFC.tsx +0 -248
  42. package/src/components/MessageInput/components/NativeAttachmentPicker.tsx +0 -12
  43. package/src/components/MessageList/utils/getLastReceivedMessageFlashList.ts +0 -20
  44. package/src/components/docs/data.js +0 -524
@@ -1,76 +0,0 @@
1
- import type { Channel, ChannelSort, StreamChat } from 'stream-chat';
2
-
3
- import { findLastPinnedChannelIndex, shouldConsiderPinnedChannels } from './hooks/utils';
4
-
5
- type MoveParameters = {
6
- channels: Array<Channel>;
7
- channelToMove: Channel;
8
- /**
9
- * If the index of the channel within `channels` list which is being moved upwards
10
- * (`channelToMove`) is known, you can supply it to skip extra calculation.
11
- */
12
- channelToMoveIndexWithinChannels?: number;
13
- sort?: ChannelSort;
14
- };
15
-
16
- export const moveChannelUp = ({
17
- channels,
18
- channelToMove,
19
- channelToMoveIndexWithinChannels,
20
- sort,
21
- }: MoveParameters) => {
22
- // get index of channel to move up
23
- const targetChannelIndex =
24
- channelToMoveIndexWithinChannels ??
25
- channels.findIndex((channel) => channel.cid === channelToMove.cid);
26
-
27
- const targetChannelExistsWithinList = targetChannelIndex >= 0;
28
- const targetChannelAlreadyAtTheTop = targetChannelIndex === 0;
29
-
30
- // pinned channels should not move within the list based on recent activity, channels which
31
- // receive messages and are not pinned should move upwards but only under the last pinned channel
32
- // in the list
33
- const considerPinnedChannels = shouldConsiderPinnedChannels(sort);
34
-
35
- if (targetChannelAlreadyAtTheTop) {
36
- return channels;
37
- }
38
-
39
- const newChannels = [...channels];
40
-
41
- // target channel index is known, remove it from the list
42
- if (targetChannelExistsWithinList) {
43
- newChannels.splice(targetChannelIndex, 1);
44
- }
45
-
46
- // as position of pinned channels has to stay unchanged, we need to
47
- // find last pinned channel in the list to move the target channel after
48
- let lastPinnedChannelIndex: number | null = null;
49
- if (considerPinnedChannels) {
50
- lastPinnedChannelIndex = findLastPinnedChannelIndex({ channels: newChannels });
51
- }
52
-
53
- // re-insert it at the new place (to specific index if pinned channels are considered)
54
- newChannels.splice(
55
- typeof lastPinnedChannelIndex === 'number' ? lastPinnedChannelIndex + 1 : 0,
56
- 0,
57
- channelToMove,
58
- );
59
-
60
- return newChannels;
61
- };
62
-
63
- type GetParameters = {
64
- client: StreamChat;
65
- id: string;
66
- type: string;
67
- };
68
-
69
- export const getChannel = async ({ client, id, type }: GetParameters) => {
70
- const channel = client.channel(type, id);
71
- await channel.watch();
72
- return channel;
73
- };
74
-
75
- export const DEFAULT_QUERY_CHANNELS_LIMIT = 10;
76
- export const MAX_QUERY_CHANNELS_LIMIT = 30;
@@ -1,248 +0,0 @@
1
- import React, { useEffect, useRef, useState } from 'react';
2
- import {
3
- AppState,
4
- AppStateStatus,
5
- EmitterSubscription,
6
- Keyboard,
7
- KeyboardAvoidingViewProps,
8
- KeyboardEvent,
9
- KeyboardEventListener,
10
- KeyboardMetrics,
11
- LayoutAnimation,
12
- LayoutChangeEvent,
13
- LayoutRectangle,
14
- Platform,
15
- StyleSheet,
16
- View,
17
- } from 'react-native';
18
-
19
- import { KeyboardProvider } from '../../contexts/keyboardContext/KeyboardContext';
20
-
21
- /**
22
- * View that moves out of the way when the keyboard appears by automatically
23
- * adjusting its height, position, or bottom padding.
24
- *
25
- * Following piece of code has been mostly copied from KeyboardAvoidingView component, with few additional tweaks.
26
- */
27
- export const KeyboardCompatibleView = ({
28
- behavior = Platform.OS === 'ios' ? 'padding' : 'position',
29
- children,
30
- contentContainerStyle,
31
- enabled = true,
32
- keyboardVerticalOffset = Platform.OS === 'ios' ? 86.5 : -300,
33
- style,
34
- ...props
35
- }: KeyboardAvoidingViewProps) => {
36
- const frame = useRef<LayoutRectangle>(undefined);
37
- const initialFrameHeight = useRef(0);
38
- const keyboardEvent = useRef<KeyboardEvent>(undefined);
39
- const subscriptions = useRef<EmitterSubscription[]>([]);
40
- const viewRef = useRef<View | null>(null);
41
-
42
- const [appState, setAppState] = useState<AppStateStatus>(AppState.currentState);
43
- const [bottom, setBottom] = useState(0);
44
- const [isKeyboardOpen, setIsKeyboardOpen] = useState(false);
45
-
46
- useEffect(() => {
47
- const handleAppStateChange = (nextAppState: AppStateStatus) => {
48
- if (appState.match(/inactive|background/) && nextAppState === 'active') {
49
- setKeyboardListeners();
50
- }
51
-
52
- if (nextAppState.match(/inactive|background/)) {
53
- unsetKeyboardListeners();
54
- }
55
-
56
- setAppState(nextAppState);
57
- };
58
-
59
- const onKeyboardChange: KeyboardEventListener = (event) => {
60
- keyboardEvent.current = event;
61
- };
62
-
63
- const setKeyboardListeners = () => {
64
- if (Platform.OS === 'ios') {
65
- subscriptions.current = [
66
- Keyboard.addListener('keyboardWillChangeFrame', onKeyboardChange),
67
- Keyboard.addListener('keyboardDidHide', () => {
68
- setIsKeyboardOpen(false);
69
- }),
70
- Keyboard.addListener('keyboardDidShow', () => {
71
- setIsKeyboardOpen(true);
72
- }),
73
- ];
74
- } else {
75
- subscriptions.current = [
76
- Keyboard.addListener('keyboardDidHide', (event) => {
77
- onKeyboardChange(event);
78
- setIsKeyboardOpen(false);
79
- }),
80
- Keyboard.addListener('keyboardDidShow', (event) => {
81
- onKeyboardChange(event);
82
- setIsKeyboardOpen(true);
83
- }),
84
- ];
85
- }
86
- };
87
-
88
- const unsetKeyboardListeners = () => {
89
- subscriptions.current = subscriptions.current.filter((subscription) => {
90
- subscription.remove();
91
- return false;
92
- });
93
- };
94
-
95
- const subscription = AppState.addEventListener('change', handleAppStateChange);
96
- setKeyboardListeners();
97
-
98
- return () => {
99
- // Following if-else condition to avoid deprecated warning coming RN 0.65
100
- if (subscription?.remove) {
101
- subscription?.remove();
102
- }
103
- // @ts-ignore
104
- else if (AppState.removeEventListener) {
105
- // @ts-ignore
106
- AppState.removeEventListener('change', handleAppStateChange);
107
- }
108
-
109
- unsetKeyboardListeners();
110
- };
111
- // eslint-disable-next-line react-hooks/exhaustive-deps
112
- }, []);
113
-
114
- useEffect(() => {
115
- updateBottomIfNecessary();
116
- // eslint-disable-next-line react-hooks/exhaustive-deps
117
- }, [keyboardEvent.current]);
118
-
119
- const dismissKeyboard: () => Promise<void> | undefined = () => {
120
- if (!isKeyboardOpen) {
121
- return;
122
- }
123
-
124
- return new Promise((resolve) => {
125
- const subscription = Keyboard.addListener('keyboardDidHide', () => {
126
- resolve();
127
- subscription.remove();
128
- });
129
-
130
- Keyboard.dismiss();
131
- });
132
- };
133
-
134
- const onLayout: (event: LayoutChangeEvent) => void = (event) => {
135
- frame.current = event.nativeEvent.layout;
136
- if (!initialFrameHeight.current) {
137
- // save the initial frame height, before the keyboard is visible
138
- initialFrameHeight.current = frame.current.height;
139
- }
140
-
141
- updateBottomIfNecessary();
142
- };
143
-
144
- const relativeKeyboardHeight = (keyboardFrame: KeyboardMetrics) => {
145
- if (!frame.current || !keyboardFrame) {
146
- return 0;
147
- }
148
-
149
- const keyboardY = keyboardFrame.screenY - keyboardVerticalOffset;
150
-
151
- // Calculate the displacement needed for the view such that it
152
- // no longer overlaps with the keyboard
153
- return Math.max(frame.current.y + frame.current.height - keyboardY, 0);
154
- };
155
-
156
- const updateBottomIfNecessary = () => {
157
- if (!keyboardEvent.current) {
158
- setBottom(0);
159
- return;
160
- }
161
-
162
- const { duration, easing, endCoordinates } = keyboardEvent.current;
163
- const height = relativeKeyboardHeight(endCoordinates);
164
-
165
- if (bottom === height) {
166
- return;
167
- }
168
-
169
- if (duration && easing) {
170
- LayoutAnimation.configureNext({
171
- // We have to pass the duration equal to minimal accepted duration defined here: RCTLayoutAnimation.m
172
- duration: duration > 10 ? duration : 10,
173
- update: {
174
- duration: duration > 10 ? duration : 10,
175
- type: LayoutAnimation.Types[easing] || 'keyboard',
176
- },
177
- });
178
- }
179
- setBottom(height);
180
- };
181
-
182
- const bottomHeight = enabled ? bottom : 0;
183
- switch (behavior) {
184
- case 'height':
185
- // eslint-disable-next-line no-case-declarations
186
- let heightStyle;
187
- if (frame.current && bottom > 0) {
188
- // Note that we only apply a height change when there is keyboard present,
189
- // i.e. this.state.bottom is greater than 0. If we remove that condition,
190
- // this.frame.height will never go back to its original value.
191
- // When height changes, we need to disable flex.
192
- heightStyle = {
193
- flex: 0,
194
- height: initialFrameHeight.current - bottomHeight,
195
- };
196
- }
197
- return (
198
- <KeyboardProvider value={{ dismissKeyboard }}>
199
- <View
200
- onLayout={onLayout}
201
- ref={viewRef}
202
- style={StyleSheet.compose(style, heightStyle)}
203
- {...props}
204
- >
205
- {children}
206
- </View>
207
- </KeyboardProvider>
208
- );
209
-
210
- case 'position':
211
- return (
212
- <KeyboardProvider value={{ dismissKeyboard }}>
213
- <View onLayout={onLayout} ref={viewRef} style={style} {...props}>
214
- <View
215
- style={StyleSheet.compose(contentContainerStyle, {
216
- bottom: bottomHeight,
217
- })}
218
- >
219
- {children}
220
- </View>
221
- </View>
222
- </KeyboardProvider>
223
- );
224
-
225
- case 'padding':
226
- return (
227
- <KeyboardProvider value={{ dismissKeyboard }}>
228
- <View
229
- onLayout={onLayout}
230
- ref={viewRef}
231
- style={StyleSheet.compose(style, { paddingBottom: bottomHeight })}
232
- {...props}
233
- >
234
- {children}
235
- </View>
236
- </KeyboardProvider>
237
- );
238
-
239
- default:
240
- return (
241
- <KeyboardProvider value={{ dismissKeyboard }}>
242
- <View onLayout={onLayout} ref={viewRef} style={style} {...props}>
243
- {children}
244
- </View>
245
- </KeyboardProvider>
246
- );
247
- }
248
- };
@@ -1,12 +0,0 @@
1
- import { LayoutRectangle } from 'react-native';
2
-
3
- type NativeAttachmentPickerProps = {
4
- onRequestedClose: () => void;
5
- attachButtonLayoutRectangle?: LayoutRectangle;
6
- };
7
-
8
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
9
- export const NativeAttachmentPicker = (_props: NativeAttachmentPickerProps) => {
10
- // TODO: V9: Temporarily removed, will delete the entire component later
11
- return null;
12
- };
@@ -1,20 +0,0 @@
1
- import { LocalMessage } from 'stream-chat';
2
-
3
- import { MessageStatusTypes } from '../../../utils/utils';
4
-
5
- export const getLastReceivedMessageFlashList = (messages: LocalMessage[]) => {
6
- /**
7
- * There are no status on dates so they will be skipped
8
- */
9
- for (let i = messages.length - 1; i >= 0; i--) {
10
- const message = messages[i];
11
- if (
12
- message?.status === MessageStatusTypes.RECEIVED ||
13
- message?.status === MessageStatusTypes.SENDING
14
- ) {
15
- return message;
16
- }
17
- }
18
-
19
- return;
20
- };