Skip to content

Commit 6dc4539

Browse files
committed
feat(animation): speed up animation config
1 parent 4904347 commit 6dc4539

6 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/components/Drawer/Drawer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { View } from 'react-native';
33
import { animated, useSpring } from 'react-spring/native.cjs';
44
import { DeepPartial } from 'ts-essentials';
55

6+
import { springDefaultConfig } from '../../constants/Animation';
67
import { useTheme } from '../../theme';
78
import { mergeStyles, ReplaceReturnType } from '../../utils/mergeStyles';
89
import { Modal } from '../Modal';
@@ -51,6 +52,7 @@ export const Drawer = (props: DrawerProps) => {
5152

5253
const animation = useSpring({
5354
[position]: offset,
55+
config: springDefaultConfig,
5456
from: { [position]: -600 },
5557
reset: true,
5658
});

src/components/Modal/ModalBase.web.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as React from 'react';
33
import * as ReactDOM from 'react-dom';
44
import { animated, useSpring } from 'react-spring/web.cjs';
55

6+
import { springDefaultConfig } from '../../constants/Animation';
67
import { useElement, useFreezeBody } from '../Helpers';
78
import { ModalBaseProps } from './ModalBase';
89

@@ -69,6 +70,8 @@ export const ModalBase = (props: ModalBaseProps): React.ReactPortal | null => {
6970
if (!visible) setIsInView(false);
7071
},
7172

73+
config: springDefaultConfig,
74+
7275
opacity: animationType === 'fade' ? (visible ? 1 : 0) : 1,
7376
y: animationType === 'slide' ? (visible ? 0 : 100) : 0,
7477
});

src/components/Progress/Progress.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Platform, View } from 'react-native';
33
import { animated, useSpring } from 'react-spring/native.cjs';
44
import { DeepPartial } from 'ts-essentials';
55

6+
import { springDefaultConfig } from '../../constants/Animation';
67
import { useTheme } from '../../theme';
78
import { mergeStyles, ReplaceReturnType } from '../../utils/mergeStyles';
89
import {
@@ -32,6 +33,7 @@ export const Progress = (props: ProgressProps) => {
3233

3334
const boundPercent = Math.max(Math.min(percent, 100), 0);
3435
const { width } = useSpring({
36+
config: springDefaultConfig,
3537
from: { width: boundPercent },
3638
width: boundPercent,
3739
});

src/components/Switch/Switch.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { animated, useSpring } from 'react-spring/native.cjs';
99
import { DeepPartial } from 'ts-essentials';
1010

11+
import { springDefaultConfig } from '../../constants/Animation';
1112
import { Icon } from '../../icons';
1213
import { useTheme } from '../../theme';
1314
import { mergeStyles, ReplaceReturnType } from '../../utils/mergeStyles';
@@ -53,6 +54,8 @@ export const Switch = (props: SwitchProps) => {
5354
} = mergeStyles(getSwitchStyles, getStyles)(theme);
5455

5556
const { backgroundColor, circleColor, circlePosition } = useSpring({
57+
config: springDefaultConfig,
58+
5659
backgroundColor: isSwitchedOn ? backgroundColorOn : backgroundColorOff,
5760
circleColor: isSwitchedOn ? circleColorOn : circleColorOff,
5861
circlePosition: isSwitchedOn

src/components/Toast/Toast.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { View } from 'react-native';
33
import { animated, useSpring } from 'react-spring/native.cjs';
44
import { Omit } from 'ts-essentials';
55

6+
import { springDefaultConfig } from '../../constants/Animation';
67
import { Alert, AlertProps } from '../Alert';
78

89
const AnimatedView = animated(View);
@@ -37,6 +38,8 @@ export const Toast = (props: ToastProps) => {
3738
} = props;
3839

3940
const style = useSpring({
41+
config: springDefaultConfig,
42+
4043
from: { translateY: -500 },
4144
onRest: () => onRemove(),
4245
to: async next => {

src/constants/Animation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const springDefaultConfig = {
2+
friction: 40,
3+
tension: 400,
4+
};

0 commit comments

Comments
 (0)