Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit cc5ed3e

Browse files
authored
Merge pull request #5660 from matrix-org/jryans/reduced-motion-effects
Disable chat effects when reduced motion preferred
2 parents 5c1b38a + 10e25f3 commit cc5ed3e

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

src/i18n/strings/en_EN.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@
844844
"How fast should messages be downloaded.": "How fast should messages be downloaded.",
845845
"Manually verify all remote sessions": "Manually verify all remote sessions",
846846
"IRC display name width": "IRC display name width",
847-
"Show chat effects": "Show chat effects",
847+
"Show chat effects (animations when receiving e.g. confetti)": "Show chat effects (animations when receiving e.g. confetti)",
848848
"Collecting app version information": "Collecting app version information",
849849
"Collecting logs": "Collecting logs",
850850
"Uploading logs": "Uploading logs",

src/settings/Settings.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import UIFeatureController from "./controllers/UIFeatureController";
3737
import { UIFeature } from "./UIFeature";
3838
import { OrderedMultiController } from "./controllers/OrderedMultiController";
3939
import {Layout} from "./Layout";
40+
import ReducedMotionController from './controllers/ReducedMotionController';
4041

4142
// These are just a bunch of helper arrays to avoid copy/pasting a bunch of times
4243
const LEVELS_ROOM_SETTINGS = [
@@ -650,8 +651,9 @@ export const SETTINGS: {[setting: string]: ISetting} = {
650651
},
651652
"showChatEffects": {
652653
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
653-
displayName: _td("Show chat effects"),
654+
displayName: _td("Show chat effects (animations when receiving e.g. confetti)"),
654655
default: true,
656+
controller: new ReducedMotionController(),
655657
},
656658
"Widgets.pinned": { // deprecated
657659
supportedLevels: LEVELS_ROOM_OR_ACCOUNT,
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Copyright 2021 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import SettingController from "./SettingController";
18+
import { SettingLevel } from "../SettingLevel";
19+
20+
/**
21+
* For animation-like settings, this controller checks whether the user has
22+
* indicated they prefer reduced motion via browser or OS level settings.
23+
* If they have, this forces the setting value to false.
24+
*/
25+
export default class ReducedMotionController extends SettingController {
26+
public getValueOverride(
27+
level: SettingLevel,
28+
roomId: string,
29+
calculatedValue: any,
30+
calculatedAtLevel: SettingLevel,
31+
): any {
32+
if (this.prefersReducedMotion()) {
33+
return false;
34+
}
35+
return null; // no override
36+
}
37+
38+
public get settingDisabled(): boolean {
39+
return this.prefersReducedMotion();
40+
}
41+
42+
private prefersReducedMotion(): boolean {
43+
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
44+
}
45+
}

0 commit comments

Comments
 (0)