Skip to content

Commit 1929dc5

Browse files
Merge branch 'develop' of https://github.com/GetStream/stream-chat-react-native into vishal/resize-image-url-fix
# Conflicts: # package/package.json # package/yarn.lock
2 parents 74aa571 + da1863d commit 1929dc5

File tree

185 files changed

+3634
-7502
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+3634
-7502
lines changed

.github/workflows/check-pr.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,3 @@ jobs:
2525
run: yarn lerna-workspaces run lint && cd docusaurus && npx prettier --check '**/*.mdx'
2626
- name: Test
2727
run: yarn test:unit
28-
- name: Chonkbot
29-
uses: tpbowden/[email protected]
30-
with:
31-
token: ${{ secrets.GITHUB_TOKEN }}
7.64 KB
Loading
17.3 KB
Loading

docusaurus/docs/reactnative/basics/upgrade_helper.mdx

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,42 @@ prop as mentioned in [example](../guides/message_actions_customization.mdx#how-t
203203

204204
## Update The Dependencies
205205

206-
Since v4, peer dependency `react-native-blur` has been removed from the SDK. Blur background of overlay has been
207-
replaced with opacity based background instead. So unless this dependency is used explicitely within application, it
208-
can be safely removed.
206+
- Since v4, peer dependency `react-native-blur` has been removed from the SDK. Blur background of overlay has been
207+
replaced with opacity based background instead. So unless this dependency is used explicitely within application, it
208+
can be safely removed.
209209

210210
```sh
211211
yarn remove react-native-blur
212212
npx pod-install
213213
```
214214

215+
- Minimum required version of `stream-chat` is 6.0.0. So if you have installed `stream-chat` dependency explicitely,
216+
please make sure to upgrade it to [`v6.0.0`](https://github.com/GetStream/stream-chat-js/releases/tag/v6.0.0)
217+
218+
## Refactor Typescript Generics
219+
220+
Until now StreamChat client and Chat components accepted 7 different generics as provided in following example:
221+
222+
```tsx
223+
const client = StreamChat.getInstance<
224+
ChatAttachment,
225+
ChatChannel,
226+
CustomCommands,
227+
ChatEvent,
228+
UserMessage,
229+
CustomReaction,
230+
ChatUser
231+
>('YOUR_API_KEY', 'API_KEY_SECRET');
232+
```
233+
234+
These 7 generics have been replaced now with 1 single generics for the sake of simplicity.
235+
236+
```tsx
237+
const client = StreamChat.getInstance<StreamChatGenerics>('YOUR_API_KEY');
238+
```
239+
240+
Please refer to our typescript guide for details of [Generics](../customization/typescript.mdx#generics).
241+
215242
## Whats new in v4?
216243

217244
### Optimized Image Attachments
@@ -286,6 +313,52 @@ user won't be able to see a cropped image on UI. In this version, we render imag
286313
</TabItem>
287314
</Tabs>
288315

316+
### Refactor Generics to a Single Generic
317+
318+
The Typescript generics have been simplified to a single generic instead of 7 different generics (as in previous versions of SDK) which should be passed to the component or StreamChat client.
319+
320+
```tsx
321+
const client = StreamChat.getInstance<StreamChatGenerics>('YOUR_API_KEY');
322+
```
323+
324+
where `StreamChatGenerics` can be defined as;
325+
326+
```tsx
327+
type StreamChatGenerics = {
328+
attachmentType: LocalAttachmentType;
329+
channelType: LocalChannelType;
330+
commandType: LocalCommandType;
331+
eventType: LocalEventType;
332+
messageType: LocalMessageType;
333+
reactionType: LocalReactionType;
334+
userType: LocalUserType;
335+
};
336+
```
337+
338+
:::note
339+
`LocalAttachmentType`, `LocalChannelType` etc. are type deifinitions for their respective key as per your application types necessities.
340+
341+
Eg:
342+
343+
```tsx
344+
type LocalAttachmentType = {
345+
file_size?: number;
346+
mime_type?: string;
347+
};
348+
type LocalChannelType = Record<string, unknown>;
349+
type LocalCommandType = string;
350+
type LocalEventType = Record<string, unknown>;
351+
type LocalMessageType = Record<string, unknown>;
352+
type LocalReactionType = Record<string, unknown>;
353+
type LocalUserType = {
354+
image?: string;
355+
};
356+
```
357+
358+
:::
359+
360+
A seperate guide has been added to documentation for details of [Generics](../customization/typescript.mdx#generics)
361+
289362
### Slow Mode Feature
290363

291364
Slow mode helps reduce noise on a channel by limiting users to a maximum of 1 message per cooldown interval.
@@ -344,15 +417,20 @@ You can override these capabilities on UI level by providing [`overrideOwnCapabi
344417
}}
345418
```
346419

347-
### UI/UX Changes and Performance Improvements
420+
### Replaced next/prev Giphy Navigation With Shuffle
421+
422+
Next and previous buttons on giphy message have been replaced with shuffle button, since Giphy
423+
api doesn't support pagination and it resulted into confusing user experience.
348424

349-
- Images will be rendered
425+
### Dropped BlurView Package
350426

351427
- Background for the overlay which opens up when user long-presses on a message, has been replaced with
352428
opacity based background instead of [BlurView](https://github.com/Kureev/react-native-blur) [#874](https://github.com/GetStream/stream-chat-react-native/pull/874)
353429
This dependency caused a lot of issues due to its underlying native [BlurView](https://github.com/Dimezis/BlurView) dependency.
354430
Thus we decided to get rid of this hurdle by dropping this peer dependency.
355431

432+
### Performance Improvements
433+
356434
- `react-native-reanimated` based animations have been removed from Message component for performance reason [#987](https://github.com/GetStream/stream-chat-react-native/pull/987).
357435
- Long press animation on message UI has been removed
358436
- `animatedLongPress` prop has been removed from `Channel` component.

docusaurus/docs/reactnative/customization/typescript.mdx

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,48 @@ In many cases TypeScript can use [inference](https://www.typescriptlang.org/docs
2121

2222
It is important that the proper generics be applied to the `stream-chat-js` client when it is instantiated.
2323
The [documentation on `stream-chat-js` TypeScript](https://github.com/GetStream/stream-chat-js#typescript-v2xx) has examples of how this can be done in detail.
24-
The client takes seven optional generics that correspond to the seven customizable fields that currently exist in `stream-chat-js`.
24+
The client a generic type that defines seven customizable fields that currently exist in [`stream-chat-js`](https://github.com/GetStream/stream-chat-js#typescript-v2xx).
2525

2626
```tsx
27-
const client = StreamChat.getInstance<
28-
AttachmentType,
29-
ChannelType,
30-
CommandType,
31-
EventType,
32-
MessageType,
33-
ReactionType,
34-
UserType
35-
>('YOUR_API_KEY');
27+
const client = StreamChat.getInstance<StreamChatGenerics>('YOUR_API_KEY');
3628
```
3729

30+
where `StreamChatGenerics` can be defined as a type with the seven generics that correspond to the seven customizable fields as follows:
31+
32+
```tsx
33+
type StreamChatGenerics = {
34+
attachmentType: LocalAttachmentType;
35+
channelType: LocalChannelType;
36+
commandType: LocalCommandType;
37+
eventType: LocalEventType;
38+
messageType: LocalMessageType;
39+
reactionType: LocalReactionType;
40+
userType: LocalUserType;
41+
};
42+
```
43+
44+
:::note
45+
`LocalAttachmentType`, `LocalChannelType` etc. are type definitions for their respective key as per your application types necessities.
46+
47+
Eg:
48+
49+
```tsx
50+
type LocalAttachmentType = {
51+
file_size?: number;
52+
mime_type?: string;
53+
};
54+
type LocalChannelType = Record<string, unknown>;
55+
type LocalCommandType = string;
56+
type LocalEventType = Record<string, unknown>;
57+
type LocalMessageType = Record<string, unknown>;
58+
type LocalReactionType = Record<string, unknown>;
59+
type LocalUserType = {
60+
image?: string;
61+
};
62+
```
63+
64+
:::
65+
3866
The seven customizable fields these generics extend are provided via `stream-chat-js`.
3967

4068
1. [`Attachment`](https://github.com/GetStream/stream-chat-js/blob/0e29bea1e773f15599564b5174d4fabbd3bcb495/src/types.ts#L1471)
@@ -45,13 +73,10 @@ The seven customizable fields these generics extend are provided via `stream-cha
4573
6. [`Reaction`](https://github.com/GetStream/stream-chat-js/blob/0e29bea1e773f15599564b5174d4fabbd3bcb495/src/types.ts#L1854)
4674
7. [`User`](https://github.com/GetStream/stream-chat-js/blob/0e29bea1e773f15599564b5174d4fabbd3bcb495/src/types.ts#L2004)
4775

48-
All seven generics contain defaults in the `stream-chat-react-native` repo that you can extend for custom data.
76+
All seven generics contain defaults in the `stream-chat-react-native` repo that you can extend for custom data such as custom types for Channels, Messages, etc.
4977

5078
```tsx
51-
type DefaultAttachmentType = Record<string, unknown> & {
52-
file_size?: number | string;
53-
mime_type?: string;
54-
};
79+
type DefaultAttachmentType = Record<string, unknown>;
5580
type DefaultChannelType = Record<string, unknown> & {
5681
image?: string;
5782
};
@@ -64,19 +89,23 @@ type DefaultUserType = Record<string, unknown> & {
6489
};
6590
```
6691

67-
Additional fields on the defaults i.e. `file_size`, `mime_type`, and `image` are custom fields used by `stream-chat-react-native` already within the SDK.
68-
When wanting to set a subset of generics the preceding and interceding generics must also be set in order for the TypeScript compiler to correctly understand intent.
92+
Additional fields on the defaults, i.e. `image`, are custom fields used by `stream-chat-react-native` already within the SDK.
93+
When wanting to set a subset of generics, the preceding and interceding generics must also be set for the TypeScript compiler to understand intent correctly.
6994

70-
To set `ChannelType` and `MessageType` for `AttachmentType`, `CommandType`, and `EventType` must also be set.
95+
```tsx
96+
type StreamChatGenerics = {
97+
attachmentType: DefaultAttachmentType;
98+
channelType: DefaultChannelType;
99+
commandType: DefaultCommandType;
100+
eventType: DefaultEventType;
101+
messageType: DefaultMessageType;
102+
reactionType: DefaultReactionType;
103+
userType: DefaultUserType;
104+
};
105+
```
71106

72107
```tsx
73-
const client = StreamChat.getInstance<
74-
DefaultAttachmentType,
75-
{ image?: string; nickName?: string },
76-
DefaultCommandType,
77-
DefaultEventType,
78-
{ isAdminMessage?: boolean }
79-
>('YOUR_API_KEY');
108+
const client = StreamChat.getInstance<StreamChatGenerics>('YOUR_API_KEY');
80109
```
81110

82111
:::note
@@ -92,7 +121,7 @@ The [TypeScript Example App](https://github.com/GetStream/stream-chat-react-nati
92121
Core to understanding this usage is [how generics can be applied to JSX elements](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#generic-type-arguments-in-jsx-elements).
93122

94123
In many cases the use of a single prop such as `client` or `channel` allows TypeScript to infer the generics on an element.
95-
In this case `LocalAttachmentType` is inferred from `channel` and passed to the props type for a custom Attachment component.
124+
In this case `channelType` within `StreamChatGenerics` is inferred from `channel` and passed to the props type for a custom Attachment component.
96125

97126
<img src={inference} alt='TypeScript Inference' />
98127

@@ -101,13 +130,7 @@ In these cases the generics must be applied to the component directly.
101130
`MessageList` for instance could have the previous generics used on `client` applied to it in a similar manner.
102131

103132
```tsx
104-
<MessageList<
105-
DefaultAttachmentType,
106-
{ image?: string; nickName?: string },
107-
DefaultCommandType,
108-
DefaultEventType,
109-
{ isAdminMessage?: boolean }
110-
>
133+
<MessageList<StreamChatGenerics>
111134
onThreadSelect={thread => {
112135
/** Set thread and navigate to thread screen */
113136
}}
@@ -124,13 +147,7 @@ Hooks, including those to access contexts, also require generics to be applied t
124147
`useChannelContext` for instance would have the previous generics applied to it to get a correctly typed return for `channel`.
125148

126149
```tsx
127-
const { channel } = useChannelContext<
128-
DefaultAttachmentType,
129-
{ image?: string; nickName?: string },
130-
DefaultCommandType,
131-
DefaultEventType,
132-
{ isAdminMessage?: boolean }
133-
>();
150+
const { channel } = useChannelContext<StreamChatGenerics>();
134151
```
135152

136153
## Partial inference
@@ -144,12 +161,5 @@ The lack of partial inference is particularly relevant if Higher Order Component
144161
The `withChannelContext` HOC accepts the generics similarly to the `useChannelContext` hook, but because partial inference is not supported the props for the wrapped component must also be explicitly provided.
145162

146163
```tsx {2}
147-
withChannelContext<
148-
MyComponentProps,
149-
DefaultAttachmentType,
150-
{ image?: string; nickName?: string },
151-
DefaultCommandType,
152-
DefaultEventType,
153-
{ isAdminMessage?: boolean }
154-
>(MyComponent);
164+
withChannelContext<MyComponentProps, StreamChatGenerics>(MyComponent);
155165
```

examples/ExpoMessaging/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6203,10 +6203,10 @@ [email protected]:
62036203
version "0.0.0"
62046204
uid ""
62056205

6206-
stream-chat@^5.1.2:
6207-
version "5.1.2"
6208-
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-5.1.2.tgz#c55d3078505d957a6b0db18e3af25ebbec7b8746"
6209-
integrity sha512-Hqxj6iJdV10YG2hZXRhkVtVm6lEUuRK+AuTmtw639CTo3RokQiBTZ7+hYCqayhIFAX2Lrt6Drfqiol8lmcreag==
6206+
stream-chat@6.0.0:
6207+
version "6.0.0"
6208+
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-6.0.0.tgz#39ec7cefc911a1cbb4debccce142222b05167f4d"
6209+
integrity sha512-zpzpiMsR2eTYS7UluimGwVcA4vsaP/GQtEUufwlZWhxS07GaSd9SCIDYbJlmdtV47TfiMDOcDKRrm50adkBlBQ==
62106210
dependencies:
62116211
"@babel/runtime" "^7.16.3"
62126212
"@types/jsonwebtoken" "^8.5.6"

examples/NativeMessaging/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6985,10 +6985,10 @@ [email protected]:
69856985
version "0.0.0"
69866986
uid ""
69876987

6988-
stream-chat@^5.1.2:
6989-
version "5.1.2"
6990-
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-5.1.2.tgz#c55d3078505d957a6b0db18e3af25ebbec7b8746"
6991-
integrity sha512-Hqxj6iJdV10YG2hZXRhkVtVm6lEUuRK+AuTmtw639CTo3RokQiBTZ7+hYCqayhIFAX2Lrt6Drfqiol8lmcreag==
6988+
stream-chat@6.0.0:
6989+
version "6.0.0"
6990+
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-6.0.0.tgz#39ec7cefc911a1cbb4debccce142222b05167f4d"
6991+
integrity sha512-zpzpiMsR2eTYS7UluimGwVcA4vsaP/GQtEUufwlZWhxS07GaSd9SCIDYbJlmdtV47TfiMDOcDKRrm50adkBlBQ==
69926992
dependencies:
69936993
"@babel/runtime" "^7.16.3"
69946994
"@types/jsonwebtoken" "^8.5.6"

examples/SampleApp/App.tsx

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,8 @@ import { UserSelectorScreen } from './src/screens/UserSelectorScreen';
3030
import type { StreamChat } from 'stream-chat';
3131

3232
import type {
33-
LocalAttachmentType,
34-
LocalChannelType,
35-
LocalCommandType,
36-
LocalEventType,
37-
LocalMessageType,
38-
LocalReactionType,
39-
LocalUserType,
4033
StackNavigatorParamList,
34+
StreamChatGenerics,
4135
UserSelectorParamList,
4236
} from './src/types';
4337

@@ -97,43 +91,14 @@ const DrawerNavigator: React.FC = () => (
9791
);
9892

9993
const DrawerNavigatorWrapper: React.FC<{
100-
chatClient: StreamChat<
101-
LocalAttachmentType,
102-
LocalChannelType,
103-
LocalCommandType,
104-
LocalEventType,
105-
LocalMessageType,
106-
LocalReactionType,
107-
LocalUserType
108-
>;
94+
chatClient: StreamChat<StreamChatGenerics>;
10995
}> = ({ chatClient }) => {
11096
const { bottom } = useSafeAreaInsets();
11197
const streamChatTheme = useStreamChatTheme();
11298

11399
return (
114-
<OverlayProvider<
115-
LocalAttachmentType,
116-
LocalChannelType,
117-
LocalCommandType,
118-
LocalEventType,
119-
LocalMessageType,
120-
LocalReactionType,
121-
LocalUserType
122-
>
123-
bottomInset={bottom}
124-
value={{ style: streamChatTheme }}
125-
>
126-
<Chat<
127-
LocalAttachmentType,
128-
LocalChannelType,
129-
LocalCommandType,
130-
LocalEventType,
131-
LocalMessageType,
132-
LocalReactionType,
133-
LocalUserType
134-
>
135-
client={chatClient}
136-
>
100+
<OverlayProvider<StreamChatGenerics> bottomInset={bottom} value={{ style: streamChatTheme }}>
101+
<Chat<StreamChatGenerics> client={chatClient}>
137102
<AppOverlayProvider>
138103
<UserSearchProvider>
139104
<DrawerNavigator />

0 commit comments

Comments
 (0)