All files / design-system/tokens animations.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 0/0
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170      35x                                 35x                                         35x                                                                                                       35x                   35x                                                                                                                                    
import { Easing } from 'react-native';
 
// 动画时长 (ms)
export const duration = {
  instant: 0,
  fastest: 50,
  faster: 100,
  fast: 150,
  normal: 200,
  slow: 300,
  slower: 400,
  slowest: 500,
  pageTransition: 350,
  modalOpen: 300,
  modalClose: 250,
  tooltip: 150,
  skeleton: 1500,
} as const;
 
// 缓动函数
export const easing = {
  linear: Easing.linear,
  easeIn: Easing.ease,
  easeInQuad: Easing.in(Easing.quad),
  easeInCubic: Easing.in(Easing.cubic),
  easeInQuart: Easing.in(Easing.poly(4)),
  easeOut: Easing.out(Easing.ease),
  easeOutQuad: Easing.out(Easing.quad),
  easeOutCubic: Easing.out(Easing.cubic),
  easeOutQuart: Easing.out(Easing.poly(4)),
  easeInOut: Easing.inOut(Easing.ease),
  easeInOutQuad: Easing.inOut(Easing.quad),
  easeInOutCubic: Easing.inOut(Easing.cubic),
  bounce: Easing.bounce,
  elastic: Easing.elastic(1),
  back: Easing.back(1.5),
  backIn: Easing.in(Easing.back(1.5)),
  backOut: Easing.out(Easing.back(1.5)),
} as const;
 
// 弹簧配置 (Reanimated)
export const springConfig = {
  gentle: {
    damping: 20,
    mass: 1,
    stiffness: 100,
    overshootClamping: false,
    restDisplacementThreshold: 0.01,
    restSpeedThreshold: 0.01,
  },
  default: {
    damping: 15,
    mass: 1,
    stiffness: 150,
    overshootClamping: false,
    restDisplacementThreshold: 0.01,
    restSpeedThreshold: 0.01,
  },
  bouncy: {
    damping: 10,
    mass: 0.9,
    stiffness: 100,
    overshootClamping: false,
    restDisplacementThreshold: 0.01,
    restSpeedThreshold: 0.01,
  },
  quick: {
    damping: 20,
    mass: 1.2,
    stiffness: 250,
    overshootClamping: false,
    restDisplacementThreshold: 0.01,
    restSpeedThreshold: 0.01,
  },
  stiff: {
    damping: 25,
    mass: 1,
    stiffness: 300,
    overshootClamping: true,
    restDisplacementThreshold: 0.01,
    restSpeedThreshold: 0.01,
  },
  slow: {
    damping: 20,
    mass: 1.5,
    stiffness: 80,
    overshootClamping: false,
    restDisplacementThreshold: 0.01,
    restSpeedThreshold: 0.01,
  },
} as const;
 
// Tamagui 动画配置
export const tamaguiAnimations = {
  bouncy: { type: 'spring' as const, damping: 10, mass: 0.9, stiffness: 100 },
  lazy: { type: 'spring' as const, damping: 20, stiffness: 60 },
  quick: { type: 'spring' as const, damping: 20, mass: 1.2, stiffness: 250 },
  tooltip: { type: 'spring' as const, damping: 10, mass: 0.9, stiffness: 100 },
  medium: { type: 'spring' as const, damping: 15, mass: 1, stiffness: 150 },
  slow: { type: 'spring' as const, damping: 20, mass: 1.5, stiffness: 80 },
} as const;
 
// 常用动画预设
export const animationPresets = {
  fadeIn: {
    from: { opacity: 0 },
    to: { opacity: 1 },
    duration: duration.normal,
    easing: easing.easeOut,
  },
  fadeOut: {
    from: { opacity: 1 },
    to: { opacity: 0 },
    duration: duration.fast,
    easing: easing.easeIn,
  },
  scaleIn: {
    from: { scale: 0.9, opacity: 0 },
    to: { scale: 1, opacity: 1 },
    duration: duration.normal,
    easing: easing.easeOutCubic,
  },
  scaleOut: {
    from: { scale: 1, opacity: 1 },
    to: { scale: 0.9, opacity: 0 },
    duration: duration.fast,
    easing: easing.easeIn,
  },
  slideInUp: {
    from: { translateY: 20, opacity: 0 },
    to: { translateY: 0, opacity: 1 },
    duration: duration.normal,
    easing: easing.easeOutCubic,
  },
  slideInDown: {
    from: { translateY: -20, opacity: 0 },
    to: { translateY: 0, opacity: 1 },
    duration: duration.normal,
    easing: easing.easeOutCubic,
  },
  slideInLeft: {
    from: { translateX: -20, opacity: 0 },
    to: { translateX: 0, opacity: 1 },
    duration: duration.normal,
    easing: easing.easeOutCubic,
  },
  slideInRight: {
    from: { translateX: 20, opacity: 0 },
    to: { translateX: 0, opacity: 1 },
    duration: duration.normal,
    easing: easing.easeOutCubic,
  },
  press: {
    from: { scale: 1 },
    to: { scale: 0.96 },
    duration: duration.faster,
    easing: easing.easeOut,
  },
  pulse: {
    from: { scale: 1 },
    to: { scale: 1.05 },
    duration: duration.slow,
    easing: easing.easeInOut,
  },
} as const;
 
export type Duration = keyof typeof duration;
export type SpringConfig = keyof typeof springConfig;
export type AnimationPreset = keyof typeof animationPresets;