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

Reduced Motion: System level support #13

Closed
ItsJonQ opened this issue Aug 4, 2020 · 2 comments
Closed

Reduced Motion: System level support #13

ItsJonQ opened this issue Aug 4, 2020 · 2 comments

Comments

@ItsJonQ
Copy link
Owner

ItsJonQ commented Aug 4, 2020

Animation and transitions should be disabled anything from @wp-g2 respecting reducedMotion configs (whether that's an app specific config, or a user machine config).

From a DX perspective, Animation/transition disabling/enabling should be invisible.

Therefore, this has to be supported at the core system level.

I have the foundations of this working:
https://github.com/ItsJonQ/g2/blob/master/packages/styles/src/create-system/createSystemElement.js#L20

For this to work, reduceMotion needs to automatically kick in for anything using...

@wp-g2/animations

  • Entire library

@wp-g2/styles

  • css
  • styled
  • View

@wp-g2/components

  • AnimatedView
  • View
@ItsJonQ
Copy link
Owner Author

ItsJonQ commented Aug 5, 2020

Oh boy! Was able to do this with a new useReducedMotion hook from @wp-g2/styles.

https://github.com/ItsJonQ/g2/blob/master/packages/styles/src/hooks/useReducedMotion.js

Screen Capture on 2020-08-05 at 16-48-42

It uses the createStore function from @wp-g2/context (zustand under the hood) to track + coordinated state in a dedicated stream.

This allows for Animated components to recognize app controlled useReducedMotion without requiring a wrapping Provider!

The implementation of this is tricky as Animated (motion from Framer Motion) animates style properties in their own render loop(s). For example, manually incrementing height from 0px to 100px. Therefore, a blanket transition: none !important will not work.

To achieve the a seamless system-supported setup, we have to intercept and adjust the transition property being passed to motion.div based on our (new) useReducedMotion state.

@ItsJonQ
Copy link
Owner Author

ItsJonQ commented Nov 3, 2020

Closing this up! We have system-wide reduced motion support via the Style System. This configuration can also be controlled programatically (via JS) in addition to understanding and respecting the user's device preference.

@ItsJonQ ItsJonQ closed this as completed Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant