Skip to content

Commit df01d87

Browse files
Merge branch 'v4.0.0-beta.7' of https://github.com/GetStream/stream-chat-react-native into mads/dependency-updates
2 parents e3e3702 + 1223684 commit df01d87

File tree

200 files changed

+2895
-9699
lines changed

Some content is hidden

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

200 files changed

+2895
-9699
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ This repo includes 4 example apps. One made with Expo, one Native JavaScript cod
4646

4747
- [Expo example](./examples/ExpoMessaging)
4848
- [Native example](./examples/NativeMessaging)
49-
- [Typescript example](./examples/TypescriptMessaging)
49+
- [Typescript example](./examples/TypeScriptMessaging)
5050
- [Fully featured messaging application](./examples/SampleApp)
5151

5252
Besides, our team maintains a dedicated repository for fully-fledged sample applications and demos at [GetStream/react-native-samples](https://github.com/GetStream/react-native-samples). Please consider checking following sample applications:
7.64 KB
Loading
17.3 KB
Loading

docusaurus/docs/reactnative/basics/troubleshooting.mdx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,17 @@ dependencies {
246246
}
247247
```
248248

249+
## Blank screen when channel gets delete
250+
251+
When a channel is deleted, and if some user is active on that channel, a blank screen appears by default (as per the default logic) as we return `null` in this case. It might be confusing for end user to see a blank screen and appropriate UX would be to navigate back to channel list screen. You can implement such UX by listening to `channel.deleted` event on channel screen, and navigate to channel list screen with appropriate notification on app.
252+
253+
````tsx
254+
client.on('channel.deleted', (event) => {
255+
if (event.cid === channel.cid) {
256+
// add your action here
257+
}
258+
}),
259+
249260
## Touchables not working
250261

251262
If you are having trouble with pressing, swiping, or otherwise interacting with components it is likely the result of [React Native Gesture Handler](https://docs.swmansion.com/react-native-gesture-handler/docs/) not being properly setup.
@@ -255,7 +266,7 @@ This includes ensuring you import `react-native-gesture-handler` at the top of y
255266

256267
```tsx
257268
import 'react-native-gesture-handler';
258-
```
269+
````
259270

260271
And for Android you additionally need to update `MainActivity.java` to override the method for creating the `ReactRootView`.
261272

docusaurus/docs/reactnative/basics/upgrade_helper.mdx

Lines changed: 76 additions & 3 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.

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"

0 commit comments

Comments
 (0)