stream-chat-react-native-core 4.7.0 → 4.7.1-beta.1
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/Attachment/Card.js +61 -21
- package/lib/commonjs/components/Attachment/Card.js.map +1 -1
- package/lib/commonjs/components/AutoCompleteInput/AutoCompleteSuggestionList.js +1 -1
- package/lib/commonjs/components/AutoCompleteInput/AutoCompleteSuggestionList.js.map +1 -1
- package/lib/commonjs/components/MessageInput/SendMessageDisallowedIndicator.js +2 -2
- package/lib/commonjs/components/MessageInput/SendMessageDisallowedIndicator.js.map +1 -1
- package/lib/commonjs/components/Reply/Reply.js +12 -12
- package/lib/commonjs/components/Reply/Reply.js.map +1 -1
- package/lib/commonjs/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js +2 -2
- package/lib/commonjs/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js.map +1 -1
- package/lib/commonjs/contexts/attachmentPickerContext/AttachmentPickerContext.js +14 -4
- package/lib/commonjs/contexts/attachmentPickerContext/AttachmentPickerContext.js.map +1 -1
- package/lib/commonjs/contexts/channelContext/ChannelContext.js +14 -4
- package/lib/commonjs/contexts/channelContext/ChannelContext.js.map +1 -1
- package/lib/commonjs/contexts/channelsContext/ChannelsContext.js +14 -4
- package/lib/commonjs/contexts/channelsContext/ChannelsContext.js.map +1 -1
- package/lib/commonjs/contexts/channelsStateContext/ChannelsStateContext.js +15 -9
- package/lib/commonjs/contexts/channelsStateContext/ChannelsStateContext.js.map +1 -1
- package/lib/commonjs/contexts/chatContext/ChatContext.js +14 -4
- package/lib/commonjs/contexts/chatContext/ChatContext.js.map +1 -1
- package/lib/commonjs/contexts/imageGalleryContext/ImageGalleryContext.js +14 -4
- package/lib/commonjs/contexts/imageGalleryContext/ImageGalleryContext.js.map +1 -1
- package/lib/commonjs/contexts/keyboardContext/KeyboardContext.js +2 -2
- package/lib/commonjs/contexts/keyboardContext/KeyboardContext.js.map +1 -1
- package/lib/commonjs/contexts/messageContext/MessageContext.js +14 -4
- package/lib/commonjs/contexts/messageContext/MessageContext.js.map +1 -1
- package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +14 -4
- package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
- package/lib/commonjs/contexts/messageOverlayContext/MessageOverlayContext.js +14 -4
- package/lib/commonjs/contexts/messageOverlayContext/MessageOverlayContext.js.map +1 -1
- package/lib/commonjs/contexts/messageOverlayContext/hooks/useResettableState.test.js +4 -4
- package/lib/commonjs/contexts/messageOverlayContext/hooks/useResettableState.test.js.map +1 -1
- package/lib/commonjs/contexts/messagesContext/MessagesContext.js +14 -4
- package/lib/commonjs/contexts/messagesContext/MessagesContext.js.map +1 -1
- package/lib/commonjs/contexts/overlayContext/OverlayContext.js +13 -3
- package/lib/commonjs/contexts/overlayContext/OverlayContext.js.map +1 -1
- package/lib/commonjs/contexts/overlayContext/OverlayProvider.js +12 -12
- package/lib/commonjs/contexts/overlayContext/OverlayProvider.js.map +1 -1
- package/lib/commonjs/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js +13 -3
- package/lib/commonjs/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js.map +1 -1
- package/lib/commonjs/contexts/paginatedMessageListContext/PaginatedMessageListContext.js +14 -4
- package/lib/commonjs/contexts/paginatedMessageListContext/PaginatedMessageListContext.js.map +1 -1
- package/lib/commonjs/contexts/suggestionsContext/SuggestionsContext.js +14 -4
- package/lib/commonjs/contexts/suggestionsContext/SuggestionsContext.js.map +1 -1
- package/lib/commonjs/contexts/themeContext/ThemeContext.js +13 -7
- package/lib/commonjs/contexts/themeContext/ThemeContext.js.map +1 -1
- package/lib/commonjs/contexts/themeContext/utils/theme.js +9 -0
- package/lib/commonjs/contexts/themeContext/utils/theme.js.map +1 -1
- package/lib/commonjs/contexts/threadContext/ThreadContext.js +14 -4
- package/lib/commonjs/contexts/threadContext/ThreadContext.js.map +1 -1
- package/lib/commonjs/contexts/translationContext/TranslationContext.js +15 -6
- package/lib/commonjs/contexts/translationContext/TranslationContext.js.map +1 -1
- package/lib/commonjs/contexts/typingContext/TypingContext.js +14 -4
- package/lib/commonjs/contexts/typingContext/TypingContext.js.map +1 -1
- package/lib/commonjs/contexts/utils/defaultBaseContextValue.js +7 -0
- package/lib/commonjs/contexts/utils/defaultBaseContextValue.js.map +1 -0
- package/lib/commonjs/contexts/utils/isTestEnvironment.js +11 -0
- package/lib/commonjs/contexts/utils/isTestEnvironment.js.map +1 -0
- package/lib/commonjs/mock-builders/mock.js +30 -5
- package/lib/commonjs/mock-builders/mock.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/Attachment/Card.js +61 -21
- package/lib/module/components/Attachment/Card.js.map +1 -1
- package/lib/module/components/AutoCompleteInput/AutoCompleteSuggestionList.js +1 -1
- package/lib/module/components/AutoCompleteInput/AutoCompleteSuggestionList.js.map +1 -1
- package/lib/module/components/MessageInput/SendMessageDisallowedIndicator.js +2 -2
- package/lib/module/components/MessageInput/SendMessageDisallowedIndicator.js.map +1 -1
- package/lib/module/components/Reply/Reply.js +12 -12
- package/lib/module/components/Reply/Reply.js.map +1 -1
- package/lib/module/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js +2 -2
- package/lib/module/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js.map +1 -1
- package/lib/module/contexts/attachmentPickerContext/AttachmentPickerContext.js +14 -4
- package/lib/module/contexts/attachmentPickerContext/AttachmentPickerContext.js.map +1 -1
- package/lib/module/contexts/channelContext/ChannelContext.js +14 -4
- package/lib/module/contexts/channelContext/ChannelContext.js.map +1 -1
- package/lib/module/contexts/channelsContext/ChannelsContext.js +14 -4
- package/lib/module/contexts/channelsContext/ChannelsContext.js.map +1 -1
- package/lib/module/contexts/channelsStateContext/ChannelsStateContext.js +15 -9
- package/lib/module/contexts/channelsStateContext/ChannelsStateContext.js.map +1 -1
- package/lib/module/contexts/chatContext/ChatContext.js +14 -4
- package/lib/module/contexts/chatContext/ChatContext.js.map +1 -1
- package/lib/module/contexts/imageGalleryContext/ImageGalleryContext.js +14 -4
- package/lib/module/contexts/imageGalleryContext/ImageGalleryContext.js.map +1 -1
- package/lib/module/contexts/keyboardContext/KeyboardContext.js +2 -2
- package/lib/module/contexts/keyboardContext/KeyboardContext.js.map +1 -1
- package/lib/module/contexts/messageContext/MessageContext.js +14 -4
- package/lib/module/contexts/messageContext/MessageContext.js.map +1 -1
- package/lib/module/contexts/messageInputContext/MessageInputContext.js +14 -4
- package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
- package/lib/module/contexts/messageOverlayContext/MessageOverlayContext.js +14 -4
- package/lib/module/contexts/messageOverlayContext/MessageOverlayContext.js.map +1 -1
- package/lib/module/contexts/messageOverlayContext/hooks/useResettableState.test.js +4 -4
- package/lib/module/contexts/messageOverlayContext/hooks/useResettableState.test.js.map +1 -1
- package/lib/module/contexts/messagesContext/MessagesContext.js +14 -4
- package/lib/module/contexts/messagesContext/MessagesContext.js.map +1 -1
- package/lib/module/contexts/overlayContext/OverlayContext.js +13 -3
- package/lib/module/contexts/overlayContext/OverlayContext.js.map +1 -1
- package/lib/module/contexts/overlayContext/OverlayProvider.js +12 -12
- package/lib/module/contexts/overlayContext/OverlayProvider.js.map +1 -1
- package/lib/module/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js +13 -3
- package/lib/module/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js.map +1 -1
- package/lib/module/contexts/paginatedMessageListContext/PaginatedMessageListContext.js +14 -4
- package/lib/module/contexts/paginatedMessageListContext/PaginatedMessageListContext.js.map +1 -1
- package/lib/module/contexts/suggestionsContext/SuggestionsContext.js +14 -4
- package/lib/module/contexts/suggestionsContext/SuggestionsContext.js.map +1 -1
- package/lib/module/contexts/themeContext/ThemeContext.js +13 -7
- package/lib/module/contexts/themeContext/ThemeContext.js.map +1 -1
- package/lib/module/contexts/themeContext/utils/theme.js +9 -0
- package/lib/module/contexts/themeContext/utils/theme.js.map +1 -1
- package/lib/module/contexts/threadContext/ThreadContext.js +14 -4
- package/lib/module/contexts/threadContext/ThreadContext.js.map +1 -1
- package/lib/module/contexts/translationContext/TranslationContext.js +15 -6
- package/lib/module/contexts/translationContext/TranslationContext.js.map +1 -1
- package/lib/module/contexts/typingContext/TypingContext.js +14 -4
- package/lib/module/contexts/typingContext/TypingContext.js.map +1 -1
- package/lib/module/contexts/utils/defaultBaseContextValue.js +7 -0
- package/lib/module/contexts/utils/defaultBaseContextValue.js.map +1 -0
- package/lib/module/contexts/utils/isTestEnvironment.js +11 -0
- package/lib/module/contexts/utils/isTestEnvironment.js.map +1 -0
- package/lib/module/mock-builders/mock.js +30 -5
- package/lib/module/mock-builders/mock.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/contexts/__tests__/index.test.d.ts +1 -0
- package/lib/typescript/contexts/keyboardContext/KeyboardContext.d.ts +6 -2
- package/lib/typescript/contexts/themeContext/ThemeContext.d.ts +5 -2
- package/lib/typescript/contexts/themeContext/utils/theme.d.ts +6 -0
- package/lib/typescript/contexts/utils/defaultBaseContextValue.d.ts +1 -0
- package/lib/typescript/contexts/utils/isTestEnvironment.d.ts +1 -0
- package/lib/typescript/mock-builders/mock.d.ts +2 -2
- package/package.json +1 -1
- package/src/components/Attachment/Card.tsx +29 -6
- package/src/components/Attachment/__tests__/Attachment.test.js +0 -14
- package/src/components/Attachment/__tests__/Giphy.test.js +9 -5
- package/src/components/AutoCompleteInput/AutoCompleteSuggestionList.tsx +1 -0
- package/src/components/ImageGallery/components/__tests__/ImageGalleryHeader.test.tsx +5 -3
- package/src/components/MessageInput/SendMessageDisallowedIndicator.tsx +1 -0
- package/src/components/MessageInput/__tests__/FileUploadPreview.test.js +1 -1
- package/src/components/Reply/Reply.tsx +6 -3
- package/src/contexts/__tests__/index.test.tsx +103 -0
- package/src/contexts/activeChannelsRefContext/ActiveChannelsRefContext.tsx +1 -0
- package/src/contexts/attachmentPickerContext/AttachmentPickerContext.tsx +18 -4
- package/src/contexts/channelContext/ChannelContext.tsx +18 -2
- package/src/contexts/channelsContext/ChannelsContext.tsx +18 -2
- package/src/contexts/channelsStateContext/ChannelsStateContext.tsx +19 -10
- package/src/contexts/chatContext/ChatContext.tsx +15 -2
- package/src/contexts/imageGalleryContext/ImageGalleryContext.tsx +18 -3
- package/src/contexts/keyboardContext/KeyboardContext.tsx +2 -1
- package/src/contexts/messageContext/MessageContext.tsx +19 -2
- package/src/contexts/messageInputContext/MessageInputContext.tsx +20 -2
- package/src/contexts/messageOverlayContext/MessageOverlayContext.tsx +19 -3
- package/src/contexts/messageOverlayContext/hooks/useResettableState.test.tsx +1 -0
- package/src/contexts/messagesContext/MessagesContext.tsx +19 -2
- package/src/contexts/overlayContext/OverlayContext.tsx +17 -2
- package/src/contexts/overlayContext/OverlayProvider.tsx +1 -0
- package/src/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.tsx +18 -3
- package/src/contexts/paginatedMessageListContext/PaginatedMessageListContext.tsx +15 -3
- package/src/contexts/suggestionsContext/SuggestionsContext.tsx +19 -2
- package/src/contexts/suggestionsContext/__tests__/Suggestions.test.js +1 -0
- package/src/contexts/themeContext/ThemeContext.tsx +19 -5
- package/src/contexts/themeContext/utils/theme.ts +15 -0
- package/src/contexts/threadContext/ThreadContext.tsx +16 -2
- package/src/contexts/translationContext/TranslationContext.tsx +18 -4
- package/src/contexts/typingContext/TypingContext.tsx +17 -2
- package/src/contexts/utils/defaultBaseContextValue.ts +1 -0
- package/src/contexts/utils/isTestEnvironment.ts +1 -0
- package/src/mock-builders/mock.js +16 -3
- package/src/version.json +1 -1
|
@@ -19,7 +19,10 @@ import type { EmptyStateProps } from '../../components/Indicators/EmptyStateIndi
|
|
|
19
19
|
import type { LoadingErrorProps } from '../../components/Indicators/LoadingErrorIndicator';
|
|
20
20
|
import type { LoadingProps } from '../../components/Indicators/LoadingIndicator';
|
|
21
21
|
import type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';
|
|
22
|
+
import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
|
|
23
|
+
|
|
22
24
|
import { getDisplayName } from '../utils/getDisplayName';
|
|
25
|
+
import { isTestEnvironment } from '../utils/isTestEnvironment';
|
|
23
26
|
|
|
24
27
|
export type ChannelsContextValue<
|
|
25
28
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
@@ -207,7 +210,9 @@ export type ChannelsContextValue<
|
|
|
207
210
|
PreviewUnreadCount?: React.ComponentType<ChannelPreviewUnreadCountProps<StreamChatGenerics>>;
|
|
208
211
|
};
|
|
209
212
|
|
|
210
|
-
export const ChannelsContext = React.createContext(
|
|
213
|
+
export const ChannelsContext = React.createContext(
|
|
214
|
+
DEFAULT_BASE_CONTEXT_VALUE as ChannelsContextValue,
|
|
215
|
+
);
|
|
211
216
|
|
|
212
217
|
export const ChannelsProvider = <
|
|
213
218
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
@@ -224,8 +229,19 @@ export const ChannelsProvider = <
|
|
|
224
229
|
|
|
225
230
|
export const useChannelsContext = <
|
|
226
231
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
227
|
-
>() =>
|
|
232
|
+
>() => {
|
|
233
|
+
const contextValue = useContext(
|
|
234
|
+
ChannelsContext,
|
|
235
|
+
) as unknown as ChannelsContextValue<StreamChatGenerics>;
|
|
228
236
|
|
|
237
|
+
if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
|
|
238
|
+
throw new Error(
|
|
239
|
+
`The useChannelsContext hook was called outside of the ChannelsContext provider. Make sure you have configured ChannelList component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel-list`,
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return contextValue;
|
|
244
|
+
};
|
|
229
245
|
/**
|
|
230
246
|
* Typescript currently does not support partial inference so if ChatContext
|
|
231
247
|
* typing is desired while using the HOC withChannelContext the Props for the
|
|
@@ -15,7 +15,10 @@ import type { ChannelContextValue } from '../channelContext/ChannelContext';
|
|
|
15
15
|
import type { PaginatedMessageListContextValue } from '../paginatedMessageListContext/PaginatedMessageListContext';
|
|
16
16
|
import type { ThreadContextValue } from '../threadContext/ThreadContext';
|
|
17
17
|
import type { TypingContextValue } from '../typingContext/TypingContext';
|
|
18
|
+
import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
|
|
19
|
+
|
|
18
20
|
import { getDisplayName } from '../utils/getDisplayName';
|
|
21
|
+
import { isTestEnvironment } from '../utils/isTestEnvironment';
|
|
19
22
|
|
|
20
23
|
export type ChannelState<
|
|
21
24
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
@@ -131,15 +134,9 @@ function reducer(state: ChannelsState, action: Action) {
|
|
|
131
134
|
}
|
|
132
135
|
}
|
|
133
136
|
|
|
134
|
-
const ChannelsStateContext = React.createContext(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
},
|
|
138
|
-
setState: () => {
|
|
139
|
-
// do nothing.
|
|
140
|
-
},
|
|
141
|
-
state: {},
|
|
142
|
-
} as unknown as ChannelsStateContextValue);
|
|
137
|
+
const ChannelsStateContext = React.createContext(
|
|
138
|
+
DEFAULT_BASE_CONTEXT_VALUE as ChannelsStateContextValue,
|
|
139
|
+
);
|
|
143
140
|
|
|
144
141
|
export const ChannelsStateProvider = <
|
|
145
142
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
@@ -187,7 +184,19 @@ export const ChannelsStateProvider = <
|
|
|
187
184
|
|
|
188
185
|
export const useChannelsStateContext = <
|
|
189
186
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
190
|
-
>() =>
|
|
187
|
+
>() => {
|
|
188
|
+
const contextValue = useContext(
|
|
189
|
+
ChannelsStateContext,
|
|
190
|
+
) as unknown as ChannelsStateContextValue<StreamChatGenerics>;
|
|
191
|
+
|
|
192
|
+
if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
|
|
193
|
+
throw new Error(
|
|
194
|
+
`The useChannelStateContext hook was called outside the ChannelStateContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return contextValue;
|
|
199
|
+
};
|
|
191
200
|
|
|
192
201
|
export const withChannelsStateContext = <
|
|
193
202
|
P extends UnknownType,
|
|
@@ -3,7 +3,10 @@ import React, { PropsWithChildren, useContext } from 'react';
|
|
|
3
3
|
import type { AppSettingsAPIResponse, Channel, Mute, StreamChat } from 'stream-chat';
|
|
4
4
|
|
|
5
5
|
import type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';
|
|
6
|
+
import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
|
|
7
|
+
|
|
6
8
|
import { getDisplayName } from '../utils/getDisplayName';
|
|
9
|
+
import { isTestEnvironment } from '../utils/isTestEnvironment';
|
|
7
10
|
|
|
8
11
|
export type ChatContextValue<
|
|
9
12
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
@@ -58,7 +61,7 @@ export type ChatContextValue<
|
|
|
58
61
|
channel?: Channel<StreamChatGenerics>;
|
|
59
62
|
};
|
|
60
63
|
|
|
61
|
-
export const ChatContext = React.createContext(
|
|
64
|
+
export const ChatContext = React.createContext(DEFAULT_BASE_CONTEXT_VALUE as ChatContextValue);
|
|
62
65
|
|
|
63
66
|
export const ChatProvider = <
|
|
64
67
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
@@ -75,7 +78,17 @@ export const ChatProvider = <
|
|
|
75
78
|
|
|
76
79
|
export const useChatContext = <
|
|
77
80
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
78
|
-
>() =>
|
|
81
|
+
>() => {
|
|
82
|
+
const contextValue = useContext(ChatContext) as unknown as ChatContextValue<StreamChatGenerics>;
|
|
83
|
+
|
|
84
|
+
if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
|
|
85
|
+
throw new Error(
|
|
86
|
+
`The useChatContext hook was called outside the ChatContext Provider. Make sure you have configured Chat component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#chat`,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return contextValue;
|
|
91
|
+
};
|
|
79
92
|
|
|
80
93
|
/**
|
|
81
94
|
* Typescript currently does not support partial inference so if ChatContext
|
|
@@ -2,7 +2,10 @@ import React, { PropsWithChildren, useContext, useState } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import type { MessageType } from '../../components/MessageList/hooks/useMessageList';
|
|
4
4
|
import type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';
|
|
5
|
+
import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
|
|
6
|
+
|
|
5
7
|
import { getDisplayName } from '../utils/getDisplayName';
|
|
8
|
+
import { isTestEnvironment } from '../utils/isTestEnvironment';
|
|
6
9
|
|
|
7
10
|
export type ImageGalleryContextValue<
|
|
8
11
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
@@ -13,8 +16,8 @@ export type ImageGalleryContextValue<
|
|
|
13
16
|
image?: { messageId?: string; url?: string };
|
|
14
17
|
};
|
|
15
18
|
|
|
16
|
-
export const ImageGalleryContext = React.createContext
|
|
17
|
-
|
|
19
|
+
export const ImageGalleryContext = React.createContext(
|
|
20
|
+
DEFAULT_BASE_CONTEXT_VALUE as ImageGalleryContextValue,
|
|
18
21
|
);
|
|
19
22
|
|
|
20
23
|
export const ImageGalleryProvider = <
|
|
@@ -43,7 +46,19 @@ export const ImageGalleryProvider = <
|
|
|
43
46
|
|
|
44
47
|
export const useImageGalleryContext = <
|
|
45
48
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
46
|
-
>() =>
|
|
49
|
+
>() => {
|
|
50
|
+
const contextValue = useContext(
|
|
51
|
+
ImageGalleryContext,
|
|
52
|
+
) as unknown as ImageGalleryContextValue<StreamChatGenerics>;
|
|
53
|
+
|
|
54
|
+
if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`The useImageGalleryContext hook was called outside the ImageGalleryContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return contextValue as ImageGalleryContextValue<StreamChatGenerics>;
|
|
61
|
+
};
|
|
47
62
|
|
|
48
63
|
export const withImageGalleryContext = <
|
|
49
64
|
P extends UnknownType,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { useContext } from 'react';
|
|
2
|
+
|
|
2
3
|
import { Keyboard } from 'react-native';
|
|
3
4
|
|
|
4
5
|
import type { DefaultStreamChatGenerics } from '../../types/types';
|
|
@@ -8,7 +9,7 @@ export type KeyboardContextValue = {
|
|
|
8
9
|
dismissKeyboard: () => void;
|
|
9
10
|
};
|
|
10
11
|
|
|
11
|
-
export const KeyboardContext = React.createContext
|
|
12
|
+
export const KeyboardContext = React.createContext({
|
|
12
13
|
dismissKeyboard: Keyboard.dismiss,
|
|
13
14
|
});
|
|
14
15
|
|
|
@@ -11,7 +11,10 @@ import type { GroupType, MessageType } from '../../components/MessageList/hooks/
|
|
|
11
11
|
import type { ChannelContextValue } from '../../contexts/channelContext/ChannelContext';
|
|
12
12
|
import type { MessageContentType } from '../../contexts/messagesContext/MessagesContext';
|
|
13
13
|
import type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';
|
|
14
|
+
import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
|
|
15
|
+
|
|
14
16
|
import { getDisplayName } from '../utils/getDisplayName';
|
|
17
|
+
import { isTestEnvironment } from '../utils/isTestEnvironment';
|
|
15
18
|
|
|
16
19
|
export type Alignment = 'right' | 'left';
|
|
17
20
|
|
|
@@ -102,7 +105,9 @@ export type MessageContextValue<
|
|
|
102
105
|
showAvatar?: boolean;
|
|
103
106
|
} & Pick<ChannelContextValue<StreamChatGenerics>, 'channel' | 'disabled' | 'members'>;
|
|
104
107
|
|
|
105
|
-
export const MessageContext = React.createContext(
|
|
108
|
+
export const MessageContext = React.createContext(
|
|
109
|
+
DEFAULT_BASE_CONTEXT_VALUE as MessageContextValue,
|
|
110
|
+
);
|
|
106
111
|
|
|
107
112
|
export const MessageProvider = <
|
|
108
113
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
@@ -119,7 +124,19 @@ export const MessageProvider = <
|
|
|
119
124
|
|
|
120
125
|
export const useMessageContext = <
|
|
121
126
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
122
|
-
>() =>
|
|
127
|
+
>() => {
|
|
128
|
+
const contextValue = useContext(
|
|
129
|
+
MessageContext,
|
|
130
|
+
) as unknown as MessageContextValue<StreamChatGenerics>;
|
|
131
|
+
|
|
132
|
+
if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
|
|
133
|
+
throw new Error(
|
|
134
|
+
`The useMessageContext hook was called outside of the MessageContext provider. Make sure you have configured MessageList component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#message-list`,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return contextValue;
|
|
139
|
+
};
|
|
123
140
|
|
|
124
141
|
/**
|
|
125
142
|
* Typescript currently does not support partial inference so if MessageContext
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { PropsWithChildren, useContext, useEffect, useRef, useState } from 'react';
|
|
2
|
+
|
|
2
3
|
import { Alert, Keyboard } from 'react-native';
|
|
3
4
|
|
|
4
5
|
import type { TextInput, TextInputProps } from 'react-native';
|
|
@@ -52,7 +53,10 @@ import { useChatContext } from '../chatContext/ChatContext';
|
|
|
52
53
|
import { useOwnCapabilitiesContext } from '../ownCapabilitiesContext/OwnCapabilitiesContext';
|
|
53
54
|
import { useThreadContext } from '../threadContext/ThreadContext';
|
|
54
55
|
import { useTranslationContext } from '../translationContext/TranslationContext';
|
|
56
|
+
import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
|
|
57
|
+
|
|
55
58
|
import { getDisplayName } from '../utils/getDisplayName';
|
|
59
|
+
import { isTestEnvironment } from '../utils/isTestEnvironment';
|
|
56
60
|
|
|
57
61
|
export type FileUpload = {
|
|
58
62
|
file: File;
|
|
@@ -393,7 +397,9 @@ export type MessageInputContextValue<
|
|
|
393
397
|
> = LocalMessageInputContext<StreamChatGenerics> &
|
|
394
398
|
Omit<InputMessageInputContextValue<StreamChatGenerics>, 'sendMessage'>;
|
|
395
399
|
|
|
396
|
-
export const MessageInputContext = React.createContext(
|
|
400
|
+
export const MessageInputContext = React.createContext(
|
|
401
|
+
DEFAULT_BASE_CONTEXT_VALUE as MessageInputContextValue,
|
|
402
|
+
);
|
|
397
403
|
|
|
398
404
|
export const MessageInputProvider = <
|
|
399
405
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
@@ -1129,7 +1135,19 @@ export const MessageInputProvider = <
|
|
|
1129
1135
|
|
|
1130
1136
|
export const useMessageInputContext = <
|
|
1131
1137
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
1132
|
-
>() =>
|
|
1138
|
+
>() => {
|
|
1139
|
+
const contextValue = useContext(
|
|
1140
|
+
MessageInputContext,
|
|
1141
|
+
) as unknown as MessageInputContextValue<StreamChatGenerics>;
|
|
1142
|
+
|
|
1143
|
+
if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
|
|
1144
|
+
throw new Error(
|
|
1145
|
+
`The useMessageInputContext hook was called outside of the MessageInputContext provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel`,
|
|
1146
|
+
);
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
return contextValue;
|
|
1150
|
+
};
|
|
1133
1151
|
|
|
1134
1152
|
/**
|
|
1135
1153
|
* Typescript currently does not support partial inference so if MessageInputContext
|
|
@@ -18,7 +18,10 @@ import type { ReactionData } from '../../utils/utils';
|
|
|
18
18
|
import type { Alignment, MessageContextValue } from '../messageContext/MessageContext';
|
|
19
19
|
import type { MessagesContextValue } from '../messagesContext/MessagesContext';
|
|
20
20
|
import type { OwnCapabilitiesContextValue } from '../ownCapabilitiesContext/OwnCapabilitiesContext';
|
|
21
|
+
import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
|
|
22
|
+
|
|
21
23
|
import { getDisplayName } from '../utils/getDisplayName';
|
|
24
|
+
import { isTestEnvironment } from '../utils/isTestEnvironment';
|
|
22
25
|
|
|
23
26
|
export type MessageOverlayData<
|
|
24
27
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
@@ -71,7 +74,9 @@ export type MessageOverlayContextValue<
|
|
|
71
74
|
data?: MessageOverlayData<StreamChatGenerics>;
|
|
72
75
|
};
|
|
73
76
|
|
|
74
|
-
export const MessageOverlayContext = React.createContext(
|
|
77
|
+
export const MessageOverlayContext = React.createContext(
|
|
78
|
+
DEFAULT_BASE_CONTEXT_VALUE as MessageOverlayContextValue,
|
|
79
|
+
);
|
|
75
80
|
|
|
76
81
|
export const MessageOverlayProvider = <
|
|
77
82
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
@@ -91,8 +96,19 @@ export const MessageOverlayProvider = <
|
|
|
91
96
|
|
|
92
97
|
export const useMessageOverlayContext = <
|
|
93
98
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
94
|
-
>() =>
|
|
95
|
-
|
|
99
|
+
>() => {
|
|
100
|
+
const contextValue = useContext(
|
|
101
|
+
MessageOverlayContext,
|
|
102
|
+
) as unknown as MessageOverlayContextValue<StreamChatGenerics>;
|
|
103
|
+
|
|
104
|
+
if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
`The useMessageOverlayContext hook was called outside the MessageOverlayContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return contextValue;
|
|
111
|
+
};
|
|
96
112
|
|
|
97
113
|
/**
|
|
98
114
|
* Typescript currently does not support partial inference so if MessageOverlayContext
|
|
@@ -49,7 +49,10 @@ import type { SuggestionCommand } from '../suggestionsContext/SuggestionsContext
|
|
|
49
49
|
import type { DeepPartial } from '../themeContext/ThemeContext';
|
|
50
50
|
import type { Theme } from '../themeContext/utils/theme';
|
|
51
51
|
import type { TDateTimeParserInput } from '../translationContext/TranslationContext';
|
|
52
|
+
import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
|
|
53
|
+
|
|
52
54
|
import { getDisplayName } from '../utils/getDisplayName';
|
|
55
|
+
import { isTestEnvironment } from '../utils/isTestEnvironment';
|
|
53
56
|
|
|
54
57
|
export type MessageContentType = 'attachments' | 'files' | 'gallery' | 'quoted_reply' | 'text';
|
|
55
58
|
|
|
@@ -462,7 +465,9 @@ export type MessagesContextValue<
|
|
|
462
465
|
targetedMessage?: string;
|
|
463
466
|
};
|
|
464
467
|
|
|
465
|
-
export const MessagesContext = React.createContext(
|
|
468
|
+
export const MessagesContext = React.createContext(
|
|
469
|
+
DEFAULT_BASE_CONTEXT_VALUE as MessagesContextValue,
|
|
470
|
+
);
|
|
466
471
|
|
|
467
472
|
export const MessagesProvider = <
|
|
468
473
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
@@ -479,7 +484,19 @@ export const MessagesProvider = <
|
|
|
479
484
|
|
|
480
485
|
export const useMessagesContext = <
|
|
481
486
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
482
|
-
>() =>
|
|
487
|
+
>() => {
|
|
488
|
+
const contextValue = useContext(
|
|
489
|
+
MessagesContext,
|
|
490
|
+
) as unknown as MessagesContextValue<StreamChatGenerics>;
|
|
491
|
+
|
|
492
|
+
if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
|
|
493
|
+
throw new Error(
|
|
494
|
+
`The useMessagesContext hook was called outside of the MessagesContext provider. Make sure you have configured MessageList component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#message-list`,
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
return contextValue;
|
|
499
|
+
};
|
|
483
500
|
|
|
484
501
|
/**
|
|
485
502
|
* Typescript currently does not support partial inference so if MessagesContext
|
|
@@ -13,7 +13,10 @@ import type { AttachmentPickerContextValue } from '../attachmentPickerContext/At
|
|
|
13
13
|
import type { MessageOverlayContextValue } from '../messageOverlayContext/MessageOverlayContext';
|
|
14
14
|
import type { DeepPartial } from '../themeContext/ThemeContext';
|
|
15
15
|
import type { Theme } from '../themeContext/utils/theme';
|
|
16
|
+
import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
|
|
17
|
+
|
|
16
18
|
import { getDisplayName } from '../utils/getDisplayName';
|
|
19
|
+
import { isTestEnvironment } from '../utils/isTestEnvironment';
|
|
17
20
|
|
|
18
21
|
export type Overlay = 'alert' | 'gallery' | 'message' | 'none';
|
|
19
22
|
|
|
@@ -24,7 +27,9 @@ export type OverlayContextValue = {
|
|
|
24
27
|
translucentStatusBar?: boolean;
|
|
25
28
|
};
|
|
26
29
|
|
|
27
|
-
export const OverlayContext = React.createContext
|
|
30
|
+
export const OverlayContext = React.createContext(
|
|
31
|
+
DEFAULT_BASE_CONTEXT_VALUE as OverlayContextValue,
|
|
32
|
+
);
|
|
28
33
|
|
|
29
34
|
export type OverlayProviderProps<
|
|
30
35
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
@@ -73,7 +78,17 @@ export type OverlayProviderProps<
|
|
|
73
78
|
value?: Partial<OverlayContextValue>;
|
|
74
79
|
};
|
|
75
80
|
|
|
76
|
-
export const useOverlayContext = () =>
|
|
81
|
+
export const useOverlayContext = () => {
|
|
82
|
+
const contextValue = useContext(OverlayContext);
|
|
83
|
+
|
|
84
|
+
if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
|
|
85
|
+
throw new Error(
|
|
86
|
+
`The useOverlayContext hook was called outside the OverlayContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return contextValue;
|
|
91
|
+
};
|
|
77
92
|
|
|
78
93
|
export const withOverlayContext = <
|
|
79
94
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import React, { PropsWithChildren, useContext } from 'react';
|
|
2
2
|
|
|
3
|
+
import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
|
|
4
|
+
|
|
5
|
+
import { isTestEnvironment } from '../utils/isTestEnvironment';
|
|
6
|
+
|
|
3
7
|
export const allOwnCapabilities = {
|
|
4
8
|
banChannelMembers: 'ban-channel-members',
|
|
5
9
|
deleteAnyMessage: 'delete-any-message',
|
|
@@ -21,7 +25,9 @@ export const allOwnCapabilities = {
|
|
|
21
25
|
export type OwnCapability = keyof typeof allOwnCapabilities;
|
|
22
26
|
|
|
23
27
|
export type OwnCapabilitiesContextValue = Record<OwnCapability, boolean>;
|
|
24
|
-
export const OwnCapabilitiesContext = React.createContext(
|
|
28
|
+
export const OwnCapabilitiesContext = React.createContext(
|
|
29
|
+
DEFAULT_BASE_CONTEXT_VALUE as OwnCapabilitiesContextValue,
|
|
30
|
+
);
|
|
25
31
|
|
|
26
32
|
export const OwnCapabilitiesProvider = ({
|
|
27
33
|
children,
|
|
@@ -34,5 +40,14 @@ export const OwnCapabilitiesProvider = ({
|
|
|
34
40
|
</OwnCapabilitiesContext.Provider>
|
|
35
41
|
);
|
|
36
42
|
|
|
37
|
-
export const useOwnCapabilitiesContext = () =>
|
|
38
|
-
useContext(OwnCapabilitiesContext)
|
|
43
|
+
export const useOwnCapabilitiesContext = () => {
|
|
44
|
+
const contextValue = useContext(OwnCapabilitiesContext);
|
|
45
|
+
|
|
46
|
+
if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`The useOwnCapabilitiesContext hook was called outside the Channel Component. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel`,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return contextValue;
|
|
53
|
+
};
|
|
@@ -3,7 +3,10 @@ import React, { PropsWithChildren, useContext } from 'react';
|
|
|
3
3
|
import type { ChannelState } from 'stream-chat';
|
|
4
4
|
|
|
5
5
|
import type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';
|
|
6
|
+
import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
|
|
7
|
+
|
|
6
8
|
import { getDisplayName } from '../utils/getDisplayName';
|
|
9
|
+
import { isTestEnvironment } from '../utils/isTestEnvironment';
|
|
7
10
|
|
|
8
11
|
export type PaginatedMessageListContextValue<
|
|
9
12
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
@@ -43,7 +46,7 @@ export type PaginatedMessageListContextValue<
|
|
|
43
46
|
};
|
|
44
47
|
|
|
45
48
|
export const PaginatedMessageListContext = React.createContext(
|
|
46
|
-
|
|
49
|
+
DEFAULT_BASE_CONTEXT_VALUE as PaginatedMessageListContextValue,
|
|
47
50
|
);
|
|
48
51
|
|
|
49
52
|
export const PaginatedMessageListProvider = <
|
|
@@ -63,11 +66,20 @@ export const PaginatedMessageListProvider = <
|
|
|
63
66
|
|
|
64
67
|
export const usePaginatedMessageListContext = <
|
|
65
68
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
66
|
-
>() =>
|
|
67
|
-
useContext(
|
|
69
|
+
>() => {
|
|
70
|
+
const contextValue = useContext(
|
|
68
71
|
PaginatedMessageListContext,
|
|
69
72
|
) as unknown as PaginatedMessageListContextValue<StreamChatGenerics>;
|
|
70
73
|
|
|
74
|
+
if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`The usePaginatedMessageListContext hook was called outside of the PaginatedMessageList provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return contextValue;
|
|
81
|
+
};
|
|
82
|
+
|
|
71
83
|
/**
|
|
72
84
|
* Typescript currently does not support partial inference so if MessageListContextValue
|
|
73
85
|
* typing is desired while using the HOC withMessageListContext the Props for the
|
|
@@ -7,7 +7,10 @@ import type { AutoCompleteSuggestionItemProps } from '../../components/AutoCompl
|
|
|
7
7
|
import type { AutoCompleteSuggestionListProps } from '../../components/AutoCompleteInput/AutoCompleteSuggestionList';
|
|
8
8
|
import type { Emoji } from '../../emoji-data/compiled';
|
|
9
9
|
import type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';
|
|
10
|
+
import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
|
|
11
|
+
|
|
10
12
|
import { getDisplayName } from '../utils/getDisplayName';
|
|
13
|
+
import { isTestEnvironment } from '../utils/isTestEnvironment';
|
|
11
14
|
|
|
12
15
|
export type SuggestionComponentType = 'command' | 'emoji' | 'mention';
|
|
13
16
|
|
|
@@ -80,7 +83,9 @@ export type SuggestionsContextValue<
|
|
|
80
83
|
suggestionsViewActive?: boolean;
|
|
81
84
|
};
|
|
82
85
|
|
|
83
|
-
export const SuggestionsContext = React.createContext(
|
|
86
|
+
export const SuggestionsContext = React.createContext(
|
|
87
|
+
DEFAULT_BASE_CONTEXT_VALUE as SuggestionsContextValue,
|
|
88
|
+
);
|
|
84
89
|
|
|
85
90
|
/**
|
|
86
91
|
* This provider component exposes the properties stored within the SuggestionsContext.
|
|
@@ -130,7 +135,19 @@ export const SuggestionsProvider = <
|
|
|
130
135
|
|
|
131
136
|
export const useSuggestionsContext = <
|
|
132
137
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
133
|
-
>() =>
|
|
138
|
+
>() => {
|
|
139
|
+
const contextValue = useContext(
|
|
140
|
+
SuggestionsContext,
|
|
141
|
+
) as unknown as SuggestionsContextValue<StreamChatGenerics>;
|
|
142
|
+
|
|
143
|
+
if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
|
|
144
|
+
throw new Error(
|
|
145
|
+
`The useSuggestionsContext hook was called outside of the SuggestionsContext provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel`,
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return contextValue;
|
|
150
|
+
};
|
|
134
151
|
|
|
135
152
|
export const withSuggestionsContext = <
|
|
136
153
|
P extends UnknownType,
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import React, { useContext, useMemo } from 'react';
|
|
1
|
+
import React, { PropsWithChildren, useContext, useMemo } from 'react';
|
|
2
2
|
|
|
3
3
|
import merge from 'lodash/merge';
|
|
4
4
|
|
|
5
5
|
import { defaultTheme, Theme } from './utils/theme';
|
|
6
6
|
|
|
7
|
+
import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
|
|
8
|
+
import { isTestEnvironment } from '../utils/isTestEnvironment';
|
|
9
|
+
|
|
7
10
|
export type DeepPartial<T> = {
|
|
8
11
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
9
12
|
};
|
|
@@ -18,6 +21,10 @@ export type MergedThemesParams = {
|
|
|
18
21
|
theme?: Theme;
|
|
19
22
|
};
|
|
20
23
|
|
|
24
|
+
export type ThemeContextValue = {
|
|
25
|
+
theme: Theme;
|
|
26
|
+
};
|
|
27
|
+
|
|
21
28
|
export const mergeThemes = (params: MergedThemesParams) => {
|
|
22
29
|
const { style, theme } = params;
|
|
23
30
|
const finalTheme = (
|
|
@@ -33,11 +40,13 @@ export const mergeThemes = (params: MergedThemesParams) => {
|
|
|
33
40
|
return finalTheme;
|
|
34
41
|
};
|
|
35
42
|
|
|
36
|
-
export const ThemeContext = React.createContext(
|
|
43
|
+
export const ThemeContext = React.createContext(DEFAULT_BASE_CONTEXT_VALUE as Theme);
|
|
44
|
+
|
|
45
|
+
export const ThemeProvider: React.FC<
|
|
46
|
+
PropsWithChildren<ThemeProviderInputValue & Partial<ThemeContextValue>>
|
|
47
|
+
> = (props) => {
|
|
48
|
+
const { children, mergedStyle, style, theme } = props;
|
|
37
49
|
|
|
38
|
-
export const ThemeProvider: React.FC<ThemeProviderInputValue> = (props) => {
|
|
39
|
-
const { children, mergedStyle, style } = props;
|
|
40
|
-
const { theme } = useTheme();
|
|
41
50
|
const modifiedTheme = useMemo(() => {
|
|
42
51
|
if (mergedStyle) {
|
|
43
52
|
return mergedStyle;
|
|
@@ -52,5 +61,10 @@ export const ThemeProvider: React.FC<ThemeProviderInputValue> = (props) => {
|
|
|
52
61
|
export const useTheme = () => {
|
|
53
62
|
const theme = useContext(ThemeContext);
|
|
54
63
|
|
|
64
|
+
if (theme === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
`The useThemeContext hook was called outside the ThemeContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
55
69
|
return { theme };
|
|
56
70
|
};
|
|
@@ -377,6 +377,12 @@ export type Theme = {
|
|
|
377
377
|
title: TextStyle;
|
|
378
378
|
};
|
|
379
379
|
noURI: ViewStyle;
|
|
380
|
+
playButtonStyle: {
|
|
381
|
+
durationTextStyle: TextStyle;
|
|
382
|
+
roundedView: ViewStyle;
|
|
383
|
+
videoContainer: ViewStyle;
|
|
384
|
+
};
|
|
385
|
+
playIcon: IconProps;
|
|
380
386
|
};
|
|
381
387
|
container: ViewStyle;
|
|
382
388
|
content: {
|
|
@@ -859,6 +865,15 @@ export const defaultTheme: Theme = {
|
|
|
859
865
|
borderLeftWidth: 2,
|
|
860
866
|
paddingLeft: 8,
|
|
861
867
|
},
|
|
868
|
+
playButtonStyle: {
|
|
869
|
+
durationTextStyle: {},
|
|
870
|
+
roundedView: {},
|
|
871
|
+
videoContainer: {},
|
|
872
|
+
},
|
|
873
|
+
playIcon: {
|
|
874
|
+
height: 24,
|
|
875
|
+
width: 24,
|
|
876
|
+
},
|
|
862
877
|
},
|
|
863
878
|
container: {},
|
|
864
879
|
content: {
|