mattermost-mobile/app/hooks/screen_transition_animation.ts
Lucas Reis d38bf60050
Disable Animations when Accessibility configuration is to remove it (#8743)
* feat: add support for reduced motion in BottomSheet and TabBar components

* fix: remove reduceMotion option from animation timing in login, onboarding, and server screens

* feat: integrate reduced motion support to the entire app and switch accordingly

* feat: positions the Login screen differently if animations are disabled

* fix: remove mock implementation of useReducedMotion in react-native-reanimated

* revert login screen

* fix: remove unused effect that resets translateX value in LoginOptions

* feat: add reduced motion support to ForgotPassword screen and reset translateX on LoginOptions mount

* feat: integrate reduced motion support in Onboarding and Slide components

* feat: add reduced motion support to MFA and SSO screens

* feat: update ReducedMotionConfig to use system preference in withServerDatabase

* refactor: remove ReducedMotionConfig from withServerDatabase component

* feat: remove reduced motion configuration from screens and adjust animations accordingly

* feat: integrate reduced motion handling in Server component animations

* feat: enhance BottomSheet animation with reduced motion support and update test setup for react-native-reanimated

* fix: update channel list row snapshots with collapsable and animated props

* test: update react-native-reanimated mock setup for improved testing

* fix: enhance react-native-reanimated mock to support reduced motion and prevent default call

* fix: refactor animationConfigs to use useMemo for improved performance and clarity

* feat: implement screen transition animation hook and integrate it into ForgotPassword screen

* fix: refactor LoginOptions to utilize useScreenTransitionAnimation for improved animation handling

* refactor: streamline MFA component by removing unused imports and integrating useScreenTransitionAnimation for enhanced transitions

* refactor: simplify Onboarding component by removing unused imports and integrating useScreenTransitionAnimation for smoother transitions

* refactor: enhance useScreenTransitionAnimation hook to support animated transitions and integrate it into Server component

* refactor: replace custom animation logic with useScreenTransitionAnimation in SSO component for improved transition handling
2025-06-26 11:25:48 +02:00

44 lines
1.5 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {useEffect} from 'react';
import {Platform, useWindowDimensions} from 'react-native';
import {Navigation} from 'react-native-navigation';
import {useReducedMotion, useSharedValue, useAnimatedStyle, withTiming} from 'react-native-reanimated';
export const useScreenTransitionAnimation = (componentId: string, animated: boolean = true) => {
const {width} = useWindowDimensions();
const reducedMotion = useReducedMotion();
const shouldAnimate = animated && !reducedMotion;
const translateX = useSharedValue(shouldAnimate ? width : 0);
const animatedStyle = useAnimatedStyle(() => {
const duration = Platform.OS === 'android' ? 250 : 350;
return {
transform: [{translateX: withTiming(translateX.value, {duration})}],
};
}, []);
useEffect(() => {
const listener = {
componentDidAppear: () => {
translateX.value = 0;
},
componentDidDisappear: () => {
translateX.value = shouldAnimate ? -width : 0;
},
};
const unsubscribe = Navigation.events().registerComponentListener(listener, componentId);
return () => unsubscribe.remove();
}, [componentId, translateX, width, reducedMotion, shouldAnimate]);
useEffect(() => {
if (!shouldAnimate) {
translateX.value = 0;
}
}, [translateX, shouldAnimate]);
return animatedStyle;
};