@unif/react-native-chat 3.2.1 → 3.2.2

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 (23) hide show
  1. package/lib/module/components/Attachments/AttachmentItem.js +203 -72
  2. package/lib/module/components/Attachments/AttachmentItem.js.map +1 -1
  3. package/lib/module/components/Attachments/Attachments.js +6 -18
  4. package/lib/module/components/Attachments/Attachments.js.map +1 -1
  5. package/lib/module/components/Attachments/constants.js +6 -2
  6. package/lib/module/components/Attachments/constants.js.map +1 -1
  7. package/lib/module/components/Attachments/styles.js +116 -23
  8. package/lib/module/components/Attachments/styles.js.map +1 -1
  9. package/lib/typescript/src/components/Attachments/AttachmentItem.d.ts +1 -1
  10. package/lib/typescript/src/components/Attachments/AttachmentItem.d.ts.map +1 -1
  11. package/lib/typescript/src/components/Attachments/Attachments.d.ts.map +1 -1
  12. package/lib/typescript/src/components/Attachments/constants.d.ts +5 -2
  13. package/lib/typescript/src/components/Attachments/constants.d.ts.map +1 -1
  14. package/lib/typescript/src/components/Attachments/styles.d.ts +103 -11
  15. package/lib/typescript/src/components/Attachments/styles.d.ts.map +1 -1
  16. package/lib/typescript/src/components/Attachments/types.d.ts +1 -0
  17. package/lib/typescript/src/components/Attachments/types.d.ts.map +1 -1
  18. package/package.json +1 -1
  19. package/src/components/Attachments/AttachmentItem.tsx +267 -76
  20. package/src/components/Attachments/Attachments.tsx +10 -20
  21. package/src/components/Attachments/constants.ts +9 -2
  22. package/src/components/Attachments/styles.ts +114 -20
  23. package/src/components/Attachments/types.ts +1 -0
@@ -1,7 +1,6 @@
1
- import { useState } from 'react';
2
1
  import { ScrollView, View } from 'react-native';
3
- import { space, useThemedStyles } from '@unif/react-native-design';
4
- import { CARD_WIDTH, ROW_IMAGE_SIZE } from './constants';
2
+ import { useThemedStyles } from '@unif/react-native-design';
3
+ import { CARD_WIDTH, MIXED_IMAGE_SIZE, ROW_IMAGE_SIZE } from './constants';
5
4
  import { createStyles } from './styles';
6
5
  import { AttachmentItem } from './AttachmentItem';
7
6
  import type { AttachmentsProps } from './types';
@@ -16,15 +15,6 @@ export function Attachments({
16
15
  testID,
17
16
  }: AttachmentsProps) {
18
17
  const styles = useThemedStyles(createStyles);
19
- const [availableWidth, setAvailableWidth] = useState(0);
20
- const columns = Math.max(
21
- 1,
22
- Math.floor((availableWidth + space[2]) / (CARD_WIDTH + space[2]))
23
- );
24
- const cardWidth =
25
- layout === 'grid' && availableWidth > 0
26
- ? (availableWidth - space[2] * (columns - 1)) / columns
27
- : Math.min(CARD_WIDTH, availableWidth || CARD_WIDTH);
28
18
  const content = items.map((item) => {
29
19
  const row =
30
20
  layout === 'list' || (layout === 'mixed' && item.kind !== 'image');
@@ -33,9 +23,14 @@ export function Attachments({
33
23
  key={item.id}
34
24
  item={item}
35
25
  row={row}
36
- width={cardWidth}
26
+ mixed={layout === 'mixed'}
27
+ width={CARD_WIDTH}
37
28
  imageSize={
38
- row ? ROW_IMAGE_SIZE : Math.max(1, cardWidth - space[2] * 2 - 2)
29
+ row
30
+ ? layout === 'mixed'
31
+ ? MIXED_IMAGE_SIZE
32
+ : ROW_IMAGE_SIZE
33
+ : CARD_WIDTH
39
34
  }
40
35
  showProgressLabel={showProgressLabel}
41
36
  onPreview={onPreview}
@@ -49,10 +44,8 @@ export function Attachments({
49
44
  <ScrollView
50
45
  horizontal
51
46
  keyboardShouldPersistTaps="handled"
47
+ showsHorizontalScrollIndicator={false}
52
48
  contentContainerStyle={styles.carousel}
53
- onLayout={({ nativeEvent: { layout: measured } }) =>
54
- setAvailableWidth(measured.width)
55
- }
56
49
  >
57
50
  {content}
58
51
  </ScrollView>
@@ -60,9 +53,6 @@ export function Attachments({
60
53
  <View
61
54
  testID={testID ? `${testID}-content` : undefined}
62
55
  style={styles.collection}
63
- onLayout={({ nativeEvent: { layout: measured } }) =>
64
- setAvailableWidth(measured.width)
65
- }
66
56
  >
67
57
  {content}
68
58
  </View>
@@ -1,8 +1,15 @@
1
+ import { icon, r } from '@unif/react-native-design';
1
2
  import type { IconName } from '@unif/react-native-design';
2
3
  import type { ChatAttachmentItem } from './types';
3
4
 
4
- export const CARD_WIDTH = 144;
5
- export const ROW_IMAGE_SIZE = 56;
5
+ export const CARD_WIDTH = r(76);
6
+ export const ROW_IMAGE_SIZE = icon.xl;
7
+ export const MIXED_IMAGE_SIZE = r(36);
8
+ export const ATTACHMENT_STATUS_SIZE = r(40);
9
+ export const ATTACHMENT_STATUS_OWNER_SIZE = Math.max(
10
+ 44,
11
+ ATTACHMENT_STATUS_SIZE
12
+ );
6
13
  export const ATTACHMENT_ICONS: Record<
7
14
  NonNullable<ChatAttachmentItem['kind']>,
8
15
  IconName
@@ -1,6 +1,19 @@
1
1
  import { StyleSheet } from 'react-native';
2
- import { radius, space, type } from '@unif/react-native-design';
2
+ import {
3
+ fontMono,
4
+ fw,
5
+ icon,
6
+ r,
7
+ radius,
8
+ space,
9
+ type,
10
+ } from '@unif/react-native-design';
3
11
  import type { ColorTokens } from '@unif/react-native-design';
12
+ import {
13
+ ATTACHMENT_STATUS_OWNER_SIZE,
14
+ ATTACHMENT_STATUS_SIZE,
15
+ CARD_WIDTH,
16
+ } from './constants';
4
17
 
5
18
  export const createStyles = (colors: ColorTokens) =>
6
19
  StyleSheet.create({
@@ -9,45 +22,126 @@ export const createStyles = (colors: ColorTokens) =>
9
22
  flexDirection: 'row',
10
23
  flexWrap: 'wrap',
11
24
  alignItems: 'flex-start',
12
- gap: space[2],
25
+ gap: space[3],
26
+ },
27
+ carousel: { gap: space[3], alignItems: 'flex-start' },
28
+ tileOwner: { position: 'relative', minWidth: 0 },
29
+ tile: {
30
+ borderWidth: StyleSheet.hairlineWidth,
31
+ borderColor: colors.outline,
32
+ borderRadius: radius.md,
33
+ backgroundColor: colors.surfaceContainerHigh,
34
+ overflow: 'hidden',
35
+ },
36
+ tileFailed: { borderColor: colors.error, borderWidth: 2 },
37
+ documentName: {
38
+ position: 'absolute',
39
+ left: space[1],
40
+ right: space[1],
41
+ bottom: space[1],
42
+ fontSize: type.micro,
43
+ color: colors.foreground,
44
+ textAlign: 'center',
45
+ backgroundColor: colors.surfaceContainerHigh,
13
46
  },
14
- carousel: { gap: space[2], alignItems: 'flex-start' },
15
47
  item: {
16
- gap: space[2],
17
- padding: space[2],
48
+ gap: space[4],
49
+ padding: space[4],
18
50
  borderWidth: 1,
19
51
  borderColor: colors.outline,
20
52
  borderRadius: radius.md,
21
53
  backgroundColor: colors.surface,
22
54
  },
23
55
  row: { width: '100%', flexDirection: 'row', alignItems: 'center' },
24
- content: { minWidth: 0, flexShrink: 1, gap: space[1] },
56
+ rowBody: {
57
+ flex: 1,
58
+ minWidth: 0,
59
+ flexDirection: 'row',
60
+ alignItems: 'center',
61
+ gap: space[4],
62
+ },
63
+ mixedRowBody: { gap: space[3] },
64
+ mixedRow: {
65
+ height: r(64),
66
+ paddingVertical: 0,
67
+ paddingHorizontal: space[3],
68
+ borderWidth: 0,
69
+ borderRadius: 0,
70
+ },
71
+ content: { minWidth: 0, flexShrink: 1 },
25
72
  rowContent: { flex: 1 },
26
73
  media: {
27
74
  alignItems: 'center',
28
75
  justifyContent: 'center',
29
- alignSelf: 'center',
76
+ position: 'relative',
77
+ },
78
+ placeholder: {
79
+ backgroundColor: colors.surfaceContainerHigh,
80
+ borderRadius: radius.sm,
81
+ alignItems: 'center',
82
+ justifyContent: 'center',
30
83
  },
31
- imageLayer: {
84
+ statusOwner: {
32
85
  position: 'absolute',
86
+ top: (CARD_WIDTH - ATTACHMENT_STATUS_OWNER_SIZE) / 2,
87
+ left: (CARD_WIDTH - ATTACHMENT_STATUS_OWNER_SIZE) / 2,
88
+ width: ATTACHMENT_STATUS_OWNER_SIZE,
89
+ height: ATTACHMENT_STATUS_OWNER_SIZE,
33
90
  alignItems: 'center',
34
91
  justifyContent: 'center',
92
+ },
93
+ retryOwner: { zIndex: 3, elevation: 3 },
94
+ statusVisual: {
95
+ width: ATTACHMENT_STATUS_SIZE,
96
+ height: ATTACHMENT_STATUS_SIZE,
97
+ borderRadius: radius.pill,
98
+ backgroundColor: colors.scrim,
99
+ alignItems: 'center',
100
+ justifyContent: 'center',
101
+ },
102
+ removeOwner: {
103
+ position: 'absolute',
35
104
  top: 0,
36
- bottom: 0,
37
- left: 0,
38
- right: 0,
105
+ width: 44,
106
+ height: 44,
107
+ paddingTop: space[1],
108
+ zIndex: 2,
109
+ elevation: 2,
39
110
  },
40
- placeholder: {
41
- backgroundColor: colors.surfaceContainer,
42
- borderRadius: radius.sm,
111
+ removeVisual: {
112
+ width: icon.xs,
113
+ height: icon.xs,
114
+ borderRadius: radius.pill,
115
+ backgroundColor: colors.scrim,
116
+ alignItems: 'center',
117
+ justifyContent: 'center',
43
118
  },
44
- progress: {
45
- padding: space[1],
46
- borderRadius: radius.sm,
47
- backgroundColor: colors.surface,
119
+ removeFailed: { backgroundColor: colors.error },
120
+ caption: {
121
+ flexDirection: 'row',
122
+ alignItems: 'center',
123
+ justifyContent: 'center',
124
+ gap: space[1],
125
+ paddingTop: space[1],
126
+ width: CARD_WIDTH,
127
+ },
128
+ captionText: {
129
+ flexShrink: 1,
130
+ fontSize: type.micro,
131
+ color: colors.foregroundMuted,
132
+ },
133
+ previewAction: { width: CARD_WIDTH, alignItems: 'center' },
134
+ name: {
135
+ color: colors.foreground,
136
+ fontSize: type.xs,
137
+ fontWeight: fw.medium,
138
+ },
139
+ meta: {
140
+ color: colors.foregroundSubtle,
141
+ fontSize: type.micro,
142
+ marginTop: r(2),
48
143
  },
49
- name: { color: colors.foreground, fontSize: type.body },
50
- meta: { color: colors.foregroundMuted, fontSize: type.sm },
144
+ fileMeta: { fontFamily: fontMono },
51
145
  failed: { color: colors.error },
52
146
  action: { maxWidth: '100%' },
53
147
  actions: { flexDirection: 'row', flexWrap: 'wrap', gap: space[1] },
@@ -35,4 +35,5 @@ export interface AttachmentItemProps extends Pick<
35
35
  width?: number;
36
36
  imageSize: number;
37
37
  row: boolean;
38
+ mixed?: boolean;
38
39
  }