Blame view

天文台pc/tianwentai-ui/node_modules/react-smooth/src/AnimateManager.js 1.07 KB
bc518174   王天杨   提交两个项目文件
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
  import setRafTimeout from './setRafTimeout';
  
  export default function createAnimateManager() {
    let currStyle = {};
    let handleChange = () => null;
    let shouldStop = false;
  
    const setStyle = _style => {
      if (shouldStop) {
        return;
      }
  
      if (Array.isArray(_style)) {
        if (!_style.length) {
          return;
        }
  
        const styles = _style;
        const [curr, ...restStyles] = styles;
  
        if (typeof curr === 'number') {
          setRafTimeout(setStyle.bind(null, restStyles), curr);
  
          return;
        }
  
        setStyle(curr);
        setRafTimeout(setStyle.bind(null, restStyles));
        return;
      }
  
      if (typeof _style === 'object') {
        currStyle = _style;
        handleChange(currStyle);
      }
  
      if (typeof _style === 'function') {
        _style();
      }
    };
  
    return {
      stop: () => {
        shouldStop = true;
      },
      start: style => {
        shouldStop = false;
        setStyle(style);
      },
      subscribe: _handleChange => {
        handleChange = _handleChange;
  
        return () => {
          handleChange = () => null;
        };
      },
    };
  }