|
1 | 1 | import AttachmentsScreenshot from "../assets/attachments-screenshot.png"; |
| 2 | +import ImageSizingScreenshot1 from "../assets/image-sizing-screenshot-1.png"; |
| 3 | +import ImageSizingScreenshot2 from "../assets/image-sizing-screenshot-2.png"; |
| 4 | +import ImageSizingScreenshot3 from "../assets/image-sizing-screenshot-3.png"; |
2 | 5 |
|
3 | | -The `AttachmentList` compontent displays the attachments of a message. The following attachments are supported: |
| 6 | +The `AttachmentList` component displays the attachments of a message. The following attachments are supported: |
4 | 7 |
|
5 | 8 | - Images (including GIFs) are displayed inline |
6 | 9 | - Videos are displayed inline |
@@ -40,5 +43,55 @@ You can use the [`AttachmentConfigurationService`](../services/AttachmentConfigu |
40 | 43 |
|
41 | 44 | You can provide your own attachment list component by the [`CustomTemplatesService`](../services/CustomTemplatesService.mdx) |
42 | 45 |
|
| 46 | +### Image and video sizing |
| 47 | + |
| 48 | +The following section details how the width and height of images and videos uploaded from files are computed. |
| 49 | + |
| 50 | +#### Maximum size |
| 51 | + |
| 52 | +You can control the maximum size of images and videos with the [`--str-chat__attachment-max-width`](../theming/component-variables.mdx) CSS variable (available only in [theme-v2](../theming/introduction.mdx)). The value of this variable must be a value that can be computed to a valid pixel value using the [`getComputedStyle`](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle) method (for example: `300px`, `10rem`, `calc(300px - var(--margin))`, but not `100%`). If you provide an invalid value, the image and video sizing can break, which can lead to scrolling issues inside the message list (for example the message list isn't scrolled to the bottom when you open a channel). |
| 53 | + |
| 54 | +:::tip |
| 55 | +If you're unsure about the value you provided for `--str-chat__attachment-max-width`, send an image/video to a channel, then inspect the `img`/`video` element inside the message list using your browser's development tools. Inside the **computed** properties of the element, you should see that `max-height` and `max-width` are set to a valid pixel value. |
| 56 | +::: |
| 57 | + |
| 58 | +#### File size optimization |
| 59 | + |
| 60 | +Based on the CSS settings provided for images and videos, the SDK will load an image (or thumbnail image in case of a video file) with a reduced file size while still providing sufficient image quality for the given dimensions. This will result in less network traffic and faster image load for users. |
| 61 | + |
| 62 | +#### Aspect ratio |
| 63 | + |
| 64 | +The following description is applicable for [theme-v2](../theming/introduction.mdx). |
| 65 | + |
| 66 | +The SDK will try to display images and videos with their original aspect ratio, however this isn't always guaranteed (in those cases a cropped image will be displayed). Three notable exceptions are: |
| 67 | + |
| 68 | +1. if a message contains multiple lines of texts and/or multiple attachments, the image/video might be stretched to its `max-width` |
| 69 | + |
| 70 | +**Example 1** - message with one line of text |
| 71 | + |
| 72 | +<img src={ImageSizingScreenshot1} width="200" /> |
| 73 | + |
| 74 | +**Example 2** - message with multiple lines of text |
| 75 | + |
| 76 | +<img src={ImageSizingScreenshot2} width="200" /> |
| 77 | + |
| 78 | +2. in Safari, images/videos with portrait orientation are stretched to `max-width` |
| 79 | + |
| 80 | +**Example 3** - portrait images in Safari |
| 81 | + |
| 82 | +<img src={ImageSizingScreenshot3} width="200" /> |
| 83 | + |
| 84 | +3. if the image/video can't be rendered with the original aspect ratio given the `max-width` and `max-height` constraints of the host HTML element |
| 85 | + |
| 86 | +:::important |
| 87 | +**File size optimization** and maintaining **aspect ratio** uses features provided by Stream's CDN. If you're using your **own CDN** you'll likely have to provide your own implementation for this. You can do this using the [`AttachmentConfigurationService`](../services/AttachmentConfigurationService.mdx). |
| 88 | +::: |
| 89 | + |
| 90 | +:::danger |
| 91 | +**If you're planning to rewrite attachment sizing with your own CSS code** it's important to note that: |
| 92 | + |
| 93 | +The sizing logic for images and videos inside the [`AttachmentConfigurationService`](../services/AttachmentConfigurationService.mdx) requires that host elements of images and videos (ususally `img` and `video` elements) have `max-height`/`height` and `max-width` properties defined and that these values can be computed to a valid pixel value using the [`getComputedStyle`](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle) (for more information refer to the [Maximum size](#maximum-size) section). |
| 94 | +::: |
| 95 | + |
43 | 96 | [//]: # "Start of generated content" |
44 | 97 | [//]: # "End of generated content" |
0 commit comments