@transferwise/components 0.0.0-experimental-45bc551 → 0.0.0-experimental-49ac695

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,14 @@
1
1
  import {
2
- getElasticDragDifference,
3
2
  swipedLeftToRight,
4
3
  swipedRightToLeft,
5
4
  getSwipeDifference,
6
5
  swipeShouldChangeTab,
7
- getVelocity,
8
6
  Swipe,
9
7
  } from './utils';
10
8
 
11
9
  describe('Tabs Utility', () => {
12
10
  let start: Swipe;
13
11
  let end: Swipe;
14
- let coords: Swipe[];
15
12
 
16
13
  beforeEach(() => {
17
14
  jest.clearAllMocks();
@@ -68,59 +65,4 @@ describe('Tabs Utility', () => {
68
65
  expect(swipeShouldChangeTab(start, end)).toBe(false);
69
66
  });
70
67
  });
71
-
72
- describe('checking for velocity against an array of touches', () => {
73
- beforeEach(() => {
74
- coords = [
75
- { x: 0, y: 0, time: 1569538800000 },
76
- { x: 100, y: 0, time: 1569538825000 },
77
- { x: 200, y: 0, time: 1569538850000 },
78
- { x: 300, y: 0, time: 1569538875000 },
79
- { x: 400, y: 0, time: 1569538900000 },
80
- ];
81
- });
82
-
83
- it('should return the difference in velocity between the first and last touch in an array', () => {
84
- expect(getVelocity(coords)).toBe(0.004);
85
- });
86
-
87
- it('should only take into account the last 5 coordinates', () => {
88
- coords.unshift(
89
- { x: 10000, y: 0, time: 1569538800000 },
90
- { x: 100000, y: 0, time: 1569538800000 },
91
- );
92
- expect(getVelocity(coords)).toBe(0.004);
93
- });
94
-
95
- it('returns a default 0 if there are any issues with the touches passed in', () => {
96
- expect(getVelocity([])).toBe(0);
97
- });
98
- });
99
-
100
- describe('applying elasticity to a drag event', () => {
101
- it('gradually reduces the amount of difference returned toward a maximum distance', () => {
102
- global.innerWidth = 375;
103
- const maximumDraggableDistance = 125;
104
-
105
- expect(getElasticDragDifference(0)).toBe(0);
106
- expect(getApproximateElasticDragDifference(50)).toBe(28);
107
- expect(getApproximateElasticDragDifference(100)).toBe(49);
108
- expect(getApproximateElasticDragDifference(150)).toBe(66);
109
- expect(getApproximateElasticDragDifference(200)).toBe(79);
110
- expect(getApproximateElasticDragDifference(250)).toBe(89);
111
- expect(getApproximateElasticDragDifference(300)).toBe(97);
112
- expect(getApproximateElasticDragDifference(350)).toBe(103);
113
-
114
- expect(getElasticDragDifference(10000)).toBe(maximumDraggableDistance);
115
- });
116
-
117
- it('limits the maximum dragable distance on larger screens', () => {
118
- global.innerWidth = 1024;
119
- const maximumDraggableDistance = 150;
120
- expect(getElasticDragDifference(10000)).toBe(maximumDraggableDistance);
121
- });
122
- });
123
68
  });
124
-
125
- const getApproximateElasticDragDifference = (difference: number) =>
126
- Math.round(getElasticDragDifference(difference));
package/src/tabs/utils.ts CHANGED
@@ -35,23 +35,3 @@ export const swipeShouldChangeTab = (start: Swipe, end: Swipe) => {
35
35
 
36
36
  return swipedSignificantDistance(difference) && swipedWithSignificantVelocity(velocity);
37
37
  };
38
-
39
- export function getVelocity(coords: Swipe[]) {
40
- try {
41
- const relevant = coords.slice(Math.max(coords.length - 5, 1));
42
- const first = relevant[0];
43
- const last = relevant[relevant.length - 1];
44
-
45
- return Math.abs(first.x - last.x) / (last.time - first.time);
46
- } catch {
47
- return 0;
48
- }
49
- }
50
-
51
- /*
52
- `elasticDrag` is the translateX value, which slows down as the difference increases
53
- `1 - Math.E ** (-0.005 * difference)` provides a % value of how far we want to translate (0.005 being the rate)
54
- `Math.min(150, window.innerWidth / 3)` provides the maximum translate value
55
- */
56
- export const getElasticDragDifference = (difference: number) =>
57
- Math.min(150, window.innerWidth / 3) * (1 - Math.E ** (-0.005 * difference));