Skip to content

Commit 2badc51

Browse files
committed
refactor!: introduce WithComponents context provider
1 parent d28257f commit 2badc51

File tree

66 files changed

+869
-2436
lines changed

Some content is hidden

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

66 files changed

+869
-2436
lines changed

package/foobar.db-journal

-16.5 KB
Binary file not shown.

package/src/components/Attachment/FileAttachment.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import { openUrlSafely } from './utils/openUrlSafely';
77

88
import { FileIconProps } from '../../components/Attachment/FileIcon';
99

10+
import {
11+
ComponentOverrides,
12+
useComponentsContext,
13+
} from '../../contexts/componentsContext/ComponentsContext';
1014
import {
1115
MessageContextValue,
1216
useMessageContext,
@@ -21,7 +25,8 @@ export type FileAttachmentPropsWithContext = Pick<
2125
MessageContextValue,
2226
'onLongPress' | 'onPress' | 'onPressIn' | 'preventPress'
2327
> &
24-
Pick<MessagesContextValue, 'additionalPressableProps' | 'FilePreview'> & {
28+
Pick<Required<ComponentOverrides>, 'FilePreview'> &
29+
Pick<MessagesContextValue, 'additionalPressableProps'> & {
2530
/** The attachment to render */
2631
attachment: Attachment;
2732
attachmentIconSize?: FileIconProps['size'];
@@ -101,9 +106,10 @@ export type FileAttachmentProps = Partial<Omit<FileAttachmentPropsWithContext, '
101106
export const FileAttachment = (props: FileAttachmentProps) => {
102107
const { FilePreview: PropFilePreview } = props;
103108
const { onLongPress, onPress, onPressIn, preventPress } = useMessageContext();
104-
const { additionalPressableProps, FilePreview: ContextFilePreview } = useMessagesContext();
109+
const { FilePreview: ComponentsFilePreview } = useComponentsContext();
110+
const { additionalPressableProps } = useMessagesContext();
105111

106-
const FilePreview = PropFilePreview || ContextFilePreview;
112+
const FilePreview = PropFilePreview || ComponentsFilePreview;
107113

108114
return (
109115
<FileAttachmentWithContext

package/src/components/Attachment/FileAttachmentGroup.tsx

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
11
import React from 'react';
22
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
33

4-
import { Attachment as AttachmentDefault } from './Attachment';
5-
4+
import { useComponentsContext } from '../../contexts/componentsContext/ComponentsContext';
65
import {
76
MessageContextValue,
87
useMessageContext,
98
} from '../../contexts/messageContext/MessageContext';
10-
11-
import {
12-
MessagesContextValue,
13-
useMessagesContext,
14-
} from '../../contexts/messagesContext/MessagesContext';
159
import { useTheme } from '../../contexts/themeContext/ThemeContext';
1610
import { primitives } from '../../theme';
1711

18-
export type FileAttachmentGroupPropsWithContext = Pick<MessageContextValue, 'files' | 'message'> &
19-
Pick<MessagesContextValue, 'Attachment'> & {
20-
styles?: Partial<{
21-
attachmentContainer: StyleProp<ViewStyle>;
22-
container: StyleProp<ViewStyle>;
23-
}>;
24-
};
12+
export type FileAttachmentGroupPropsWithContext = Pick<MessageContextValue, 'files' | 'message'> & {
13+
styles?: Partial<{
14+
attachmentContainer: StyleProp<ViewStyle>;
15+
container: StyleProp<ViewStyle>;
16+
}>;
17+
};
2518

2619
const FileAttachmentGroupWithContext = (props: FileAttachmentGroupPropsWithContext) => {
27-
const { Attachment, files, message, styles: stylesProp = {} } = props;
20+
const { files, message, styles: stylesProp = {} } = props;
21+
const { Attachment } = useComponentsContext();
2822

2923
const {
3024
theme: {
@@ -75,8 +69,6 @@ export const FileAttachmentGroup = (props: FileAttachmentGroupProps) => {
7569

7670
const { files: contextFiles, message } = useMessageContext();
7771

78-
const { Attachment = AttachmentDefault, AudioAttachment } = useMessagesContext();
79-
8072
const files = propFiles || contextFiles;
8173

8274
if (!files.length) {
@@ -86,8 +78,6 @@ export const FileAttachmentGroup = (props: FileAttachmentGroupProps) => {
8678
return (
8779
<MemoizedFileAttachmentGroup
8880
{...{
89-
Attachment,
90-
AudioAttachment,
9181
files,
9282
message,
9383
}}

package/src/components/Attachment/FilePreview.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ import { StyleProp, StyleSheet, Text, TextStyle, View, ViewStyle } from 'react-n
33

44
import type { Attachment } from 'stream-chat';
55

6-
import { FileIcon as FileIconDefault, FileIconProps } from '../../components/Attachment/FileIcon';
7-
import {
8-
MessagesContextValue,
9-
useMessagesContext,
10-
} from '../../contexts/messagesContext/MessagesContext';
6+
import type { FileIconProps } from '../../components/Attachment/FileIcon';
7+
import { useComponentsContext } from '../../contexts/componentsContext/ComponentsContext';
118
import { useTheme } from '../../contexts/themeContext/ThemeContext';
129
import { primitives } from '../../theme';
1310
import { getDurationLabelFromDuration, getFileSizeDisplayText } from '../../utils/utils';
1411

15-
export type FilePreviewProps = Partial<Pick<MessagesContextValue, 'FileAttachmentIcon'>> & {
12+
export type FilePreviewProps = {
1613
/** The attachment to render */
1714
attachment: Attachment;
1815
attachmentIconSize?: FileIconProps['size'];
@@ -30,14 +27,12 @@ export type FilePreviewProps = Partial<Pick<MessagesContextValue, 'FileAttachmen
3027
export const FilePreview = (props: FilePreviewProps) => {
3128
const {
3229
attachment,
33-
FileAttachmentIcon: PropFileAttachmentIcon,
3430
attachmentIconSize,
3531
styles: stylesProp = {},
3632
titleNumberOfLines = 2,
3733
indicator,
3834
} = props;
39-
const { FileAttachmentIcon: ContextFileAttachmentIcon } = useMessagesContext();
40-
const FileAttachmentIcon = PropFileAttachmentIcon || ContextFileAttachmentIcon || FileIconDefault;
35+
const { FileAttachmentIcon } = useComponentsContext();
4136

4237
const styles = useStyles();
4338

0 commit comments

Comments
 (0)