Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for prefers-reduced-motion #8494

Merged
merged 12 commits into from
Jul 19, 2019
2 changes: 1 addition & 1 deletion src/ui/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ class Camera extends Evented {
easing: defaultEasing
}, options);

if (options.animate === false) options.duration = 0;
if (options.animate === false || browser.prefersReducedMotion) options.duration = 0;

const tr = this.transform,
startZoom = this.getZoom(),
Expand Down
13 changes: 12 additions & 1 deletion src/util/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const cancel = window.cancelAnimationFrame ||

let linkEl;

let _reducedMotionQuery: MediaQueryList;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe remove the dangling _ in the name for consistency? This will be private anyway since it's not exposed.


/**
* @private
*/
Expand Down Expand Up @@ -53,7 +55,16 @@ const exported = {
},

hardwareConcurrency: window.navigator.hardwareConcurrency || 4,
get devicePixelRatio() { return window.devicePixelRatio; }

get devicePixelRatio() { return window.devicePixelRatio; },
get prefersReducedMotion(): boolean {
if (!window.matchMedia) return false;
//Lazily initialize media query
if (_reducedMotionQuery == null) {
_reducedMotionQuery = window.matchMedia('(prefers-reduced-motion: reduce)');
}
return _reducedMotionQuery.matches;
},
};

export default exported;