This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 808
Add option to change the size of images/videos in the timeline #7017
Merged
Merged
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
aef7e59
Add support for variable image size in timeline (default/large)
turt2live 9584a58
Move `Layout` to new enums path
turt2live a335c6a
Dear Linter, here is your semicolon
turt2live e56f918
Update src/components/views/settings/ImageSizePanel.tsx
turt2live 359ebd7
Merge branch 'develop' into travis/image-size
turt2live c52ad3f
Apply changes to videos as well
turt2live 11f1d89
Apply 8px border radius
turt2live ec46fce
Merge branch 'develop' into travis/image-size
toger5 f13d1c0
fix crash when opening the appearance-settings
toger5 c72c4ef
fix rounded corners for blurhash
toger5 2512087
Make images size based on Width
toger5 4ce60ed
Always scale videos based on the requested width.
toger5 ee6fcc7
fix typo
toger5 33428cc
Merge branch 'develop' into travis/image-size
toger5 90ec75f
use $timeline-image-boarder-radius
toger5 591b63e
Merge remote-tracking branch 'origin/travis/image-size' into travis/i…
toger5 6748113
add return type to thumbScale
toger5 6975892
add space at the top of the file
toger5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ import { IBodyProps } from "./IBodyProps"; | |
| import MFileBody from "./MFileBody"; | ||
|
|
||
| import { logger } from "matrix-js-sdk/src/logger"; | ||
| import { ImageSize } from "../../../settings/enums/ImageSize"; | ||
|
|
||
| interface IState { | ||
| decryptedUrl?: string; | ||
|
|
@@ -42,6 +43,7 @@ interface IState { | |
| @replaceableComponent("views.messages.MVideoBody") | ||
| export default class MVideoBody extends React.PureComponent<IBodyProps, IState> { | ||
| private videoRef = React.createRef<HTMLVideoElement>(); | ||
| private sizeWatcher: string; | ||
|
|
||
| constructor(props) { | ||
| super(props); | ||
|
|
@@ -57,7 +59,28 @@ export default class MVideoBody extends React.PureComponent<IBodyProps, IState> | |
| }; | ||
| } | ||
|
|
||
| thumbScale(fullWidth: number, fullHeight: number, thumbWidth = 480, thumbHeight = 360) { | ||
| private get suggestedDimensions(): { w: number, h: number } { | ||
| switch (SettingsStore.getValue("Images.size") as ImageSize) { | ||
| case ImageSize.Large: | ||
| return { w: 480, h: 360 }; | ||
toger5 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| case ImageSize.Normal: | ||
| default: | ||
| return { w: 324, h: 220 }; | ||
| } | ||
| } | ||
|
|
||
| private thumbScale( | ||
| fullWidth: number, | ||
| fullHeight: number, | ||
| thumbWidth?, | ||
| thumbHeight?, | ||
toger5 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) { | ||
|
||
| if (!thumbWidth || !thumbHeight) { | ||
| const dims = this.suggestedDimensions; | ||
| thumbWidth = dims.w; | ||
| thumbHeight = dims.h; | ||
| } | ||
|
|
||
| if (!fullWidth || !fullHeight) { | ||
| // Cannot calculate thumbnail height for image: missing w/h in metadata. We can't even | ||
| // log this because it's spammy | ||
|
|
@@ -152,12 +175,16 @@ export default class MVideoBody extends React.PureComponent<IBodyProps, IState> | |
| } | ||
| } | ||
|
|
||
| async componentDidMount() { | ||
| const autoplay = SettingsStore.getValue("autoplayVideo") as boolean; | ||
| public async componentDidMount() { | ||
| this.sizeWatcher = SettingsStore.watchSetting("Images.size", null, () => { | ||
| this.forceUpdate(); // we don't really have a reliable thing to update, so just update the whole thing | ||
| }); | ||
|
|
||
| this.loadBlurhash(); | ||
|
|
||
| if (this.props.mediaEventHelper.media.isEncrypted && this.state.decryptedUrl === null) { | ||
| try { | ||
| const autoplay = SettingsStore.getValue("autoplayVideo") as boolean; | ||
| const thumbnailUrl = await this.props.mediaEventHelper.thumbnailUrl.value; | ||
| if (autoplay) { | ||
| logger.log("Preloading video"); | ||
|
|
@@ -189,6 +216,10 @@ export default class MVideoBody extends React.PureComponent<IBodyProps, IState> | |
| } | ||
| } | ||
|
|
||
| public componentWillUnmount() { | ||
| SettingsStore.unwatchSetting(this.sizeWatcher); | ||
| } | ||
|
|
||
| private videoOnPlay = async () => { | ||
| if (this.hasContentUrl() || this.state.fetchingData || this.state.error) { | ||
| // We have the file, we are fetching the file, or there is an error. | ||
|
|
@@ -249,8 +280,9 @@ export default class MVideoBody extends React.PureComponent<IBodyProps, IState> | |
|
|
||
| const contentUrl = this.getContentUrl(); | ||
| const thumbUrl = this.getThumbUrl(); | ||
| let height = null; | ||
| let width = null; | ||
| const defaultDims = this.suggestedDimensions; | ||
| let height = defaultDims.h; | ||
| let width = defaultDims.w; | ||
| let poster = null; | ||
| let preload = "metadata"; | ||
| if (content.info) { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.