@react-native-aria/slider 0.2.9 → 0.2.11
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.
- package/CHANGELOG.md +8 -0
- package/lib/commonjs/index.js +0 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/textSelection.js +13 -8
- package/lib/commonjs/textSelection.js.map +1 -1
- package/lib/commonjs/useMove.js +24 -22
- package/lib/commonjs/useMove.js.map +1 -1
- package/lib/commonjs/useMove.web.js +5 -27
- package/lib/commonjs/useMove.web.js.map +1 -1
- package/lib/commonjs/usePanResponder.js +0 -9
- package/lib/commonjs/usePanResponder.js.map +1 -1
- package/lib/commonjs/useSlider.js +9 -25
- package/lib/commonjs/useSlider.js.map +1 -1
- package/lib/commonjs/useSlider.web.js +17 -52
- package/lib/commonjs/useSlider.web.js.map +1 -1
- package/lib/commonjs/useSliderThumb.js +12 -33
- package/lib/commonjs/useSliderThumb.js.map +1 -1
- package/lib/commonjs/useSliderThumb.web.js +10 -33
- package/lib/commonjs/useSliderThumb.web.js.map +1 -1
- package/lib/commonjs/utils.js +1 -5
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/textSelection.js +7 -5
- package/lib/module/textSelection.js.map +1 -1
- package/lib/module/useMove.js +23 -16
- package/lib/module/useMove.js.map +1 -1
- package/lib/module/useMove.web.js +6 -24
- package/lib/module/useMove.web.js.map +1 -1
- package/lib/module/usePanResponder.js +0 -5
- package/lib/module/usePanResponder.js.map +1 -1
- package/lib/module/useSlider.js +9 -19
- package/lib/module/useSlider.js.map +1 -1
- package/lib/module/useSlider.web.js +17 -43
- package/lib/module/useSlider.web.js.map +1 -1
- package/lib/module/useSliderThumb.js +13 -26
- package/lib/module/useSliderThumb.js.map +1 -1
- package/lib/module/useSliderThumb.web.js +10 -24
- package/lib/module/useSliderThumb.web.js.map +1 -1
- package/lib/module/utils.js +0 -2
- package/lib/module/utils.js.map +1 -1
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/textSelection.d.ts +1 -0
- package/lib/typescript/textSelection.d.ts.map +1 -0
- package/lib/typescript/useMove.d.ts +1 -0
- package/lib/typescript/useMove.d.ts.map +1 -0
- package/lib/typescript/useMove.web.d.ts +1 -0
- package/lib/typescript/useMove.web.d.ts.map +1 -0
- package/lib/typescript/usePanResponder.d.ts +2 -1
- package/lib/typescript/usePanResponder.d.ts.map +1 -0
- package/lib/typescript/useSlider.d.ts +1 -0
- package/lib/typescript/useSlider.d.ts.map +1 -0
- package/lib/typescript/useSlider.web.d.ts +1 -0
- package/lib/typescript/useSlider.web.d.ts.map +1 -0
- package/lib/typescript/useSliderThumb.d.ts +1 -0
- package/lib/typescript/useSliderThumb.d.ts.map +1 -0
- package/lib/typescript/useSliderThumb.web.d.ts +1 -0
- package/lib/typescript/useSliderThumb.web.d.ts.map +1 -0
- package/lib/typescript/utils.d.ts +1 -0
- package/lib/typescript/utils.d.ts.map +1 -0
- package/package.json +8 -4
- package/src/useMove.ts +20 -12
- package/src/useMove.web.ts +3 -0
- package/src/useSliderThumb.ts +10 -7
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"textSelection.d.ts","sourceRoot":"","sources":["../../src/textSelection.ts"],"names":[],"mappings":"AA4BA,wBAAgB,oBAAoB,SAOnC;AAED,wBAAgB,oBAAoB,SA2BnC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useMove.d.ts","sourceRoot":"","sources":["../../src/useMove.ts"],"names":[],"mappings":"AAeA,UAAU,UAAU;IAClB,6CAA6C;IAC7C,SAAS,EAAE,GAAG,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,UAAU,CA8C9C"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useMove.web.d.ts","sourceRoot":"","sources":["../../src/useMove.web.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAe,MAAM,qBAAqB,CAAC;AAC9D,OAAc,EAAE,cAAc,EAAmB,MAAM,OAAO,CAAC;AAG/D,UAAU,UAAU;IAClB,6CAA6C;IAC7C,SAAS,EAAE,cAAc,CAAC,WAAW,CAAC,CAAC;CACxC;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CA0KrD"}
|
@@ -1 +1,2 @@
|
|
1
|
-
export declare const usePanResponder: (props: any) => import("react-native
|
1
|
+
export declare const usePanResponder: (props: any) => import("react-native").PanResponderInstance;
|
2
|
+
//# sourceMappingURL=usePanResponder.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"usePanResponder.d.ts","sourceRoot":"","sources":["../../src/usePanResponder.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,UAAW,GAAG,gDA+BzC,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useSlider.d.ts","sourceRoot":"","sources":["../../src/useSlider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAIpD,UAAU,UAAU;IAClB,mCAAmC;IACnC,UAAU,EAAE,GAAG,CAAC;IAEhB,gFAAgF;IAChF,UAAU,EAAE,GAAG,CAAC;IAEhB,mCAAmC;IACnC,UAAU,EAAE,GAAG,CAAC;IAEhB,+EAA+E;IAC/E,WAAW,EAAE,GAAG,CAAC;CAClB;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,eAAe,EACtB,KAAK,EAAE,WAAW,EAClB,WAAW,EAAE,GAAG,EAChB,UAAU,CAAC,EAAE,OAAO,GACnB,UAAU,CA+EZ"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useSlider.web.d.ts","sourceRoot":"","sources":["../../src/useSlider.web.ts"],"names":[],"mappings":"AAwPA,eAAO,MAAM,SAAS,UACb,GAAG,SACH,GAAG,OACL,GAAG,eACK,OAAO;;IA3OpB,mCAAmC;gBACvB,GAAG;IAEf,+EAA+E;iBAClE,GAAG;;CAkPjB,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useSliderThumb.d.ts","sourceRoot":"","sources":["../../src/useSliderThumb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAI3D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAKpD,UAAU,eAAe;IACvB,qEAAqE;IACrE,UAAU,EAAE,GAAG,CAAC;IAEhB,yDAAyD;IACzD,UAAU,EAAE,GAAG,CAAC;IAEhB,6DAA6D;IAC7D,UAAU,EAAE,GAAG,CAAC;CACjB;AAED,UAAU,kBAAmB,SAAQ,oBAAoB;IACvD,kCAAkC;IAClC,WAAW,EAAE,GAAG,CAAC;IACjB,wCAAwC;IACxC,QAAQ,EAAE,GAAG,CAAC;CACf;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,kBAAkB,EACxB,KAAK,EAAE,WAAW,EAClB,UAAU,CAAC,EAAE,OAAO,GACnB,eAAe,CAqGjB"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useSliderThumb.web.d.ts","sourceRoot":"","sources":["../../src/useSliderThumb.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAQ3D,OAAc,EAEZ,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,SAAS,EAIV,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAMpD,UAAU,eAAe;IACvB,qEAAqE;IACrE,UAAU,EAAE,cAAc,CAAC,WAAW,CAAC,CAAC;IAExC,yDAAyD;IACzD,UAAU,EAAE,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;IAElD,6DAA6D;IAC7D,UAAU,EAAE,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;CACnD;AAED,UAAU,kBAAmB,SAAQ,oBAAoB;IACvD,kCAAkC;IAClC,WAAW,EAAE,GAAG,CAAC;IACjB,wCAAwC;IACxC,QAAQ,EAAE,SAAS,CAAC,gBAAgB,CAAC,CAAC;CACvC;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,kBAAkB,EACxB,KAAK,EAAE,WAAW,EAClB,UAAU,CAAC,EAAE,OAAO,GACnB,eAAe,CAmKjB"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,eAAO,MAAM,SAAS,8BAAqC,CAAC;AAE5D,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,UAOjE"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@react-native-aria/slider",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.11",
|
4
4
|
"description": "useSlider - React Native Aria",
|
5
5
|
"main": "lib/commonjs/index",
|
6
6
|
"module": "lib/module/index",
|
@@ -26,6 +26,7 @@
|
|
26
26
|
"test": "jest",
|
27
27
|
"typescript": "tsc --noEmit",
|
28
28
|
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
29
|
+
"build": "bob build",
|
29
30
|
"prepare": "bob build",
|
30
31
|
"release": "release-it",
|
31
32
|
"example": "yarn --cwd example",
|
@@ -37,13 +38,16 @@
|
|
37
38
|
"ios",
|
38
39
|
"android"
|
39
40
|
],
|
40
|
-
"
|
41
|
+
"homepage": "https://github.com/gluestack/gluestack-ui/tree/main/packages/react-native-aria/slider#readme",
|
42
|
+
"repository": {
|
43
|
+
"type": "git",
|
44
|
+
"url": "git+https://github.com/gluestack/gluestack-ui.git"
|
45
|
+
},
|
41
46
|
"author": "nishan <nishanbende@gmail.com> (https://github.com/intergalacticspacehighway)",
|
42
47
|
"license": "MIT",
|
43
48
|
"bugs": {
|
44
49
|
"url": "https://github.com/intergalacticspacehighway/react-native-bob-mono/issues"
|
45
50
|
},
|
46
|
-
"homepage": "https://github.com/intergalacticspacehighway/react-native-bob-mono#readme",
|
47
51
|
"publishConfig": {
|
48
52
|
"registry": "https://registry.npmjs.org/"
|
49
53
|
},
|
@@ -57,7 +61,7 @@
|
|
57
61
|
"@react-aria/label": "^3.1.1",
|
58
62
|
"@react-aria/slider": "^3.0.1",
|
59
63
|
"@react-aria/utils": "^3.6.0",
|
60
|
-
"@react-native-aria/utils": "
|
64
|
+
"@react-native-aria/utils": "0.2.11",
|
61
65
|
"@react-stately/slider": "^3.0.1"
|
62
66
|
},
|
63
67
|
"devDependencies": {
|
package/src/useMove.ts
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
* governing permissions and limitations under the License.
|
11
11
|
*/
|
12
12
|
|
13
|
-
import React from 'react';
|
13
|
+
import React, { useState } from 'react';
|
14
14
|
import { PanResponder } from 'react-native';
|
15
15
|
|
16
16
|
interface MoveResult {
|
@@ -26,29 +26,37 @@ interface MoveResult {
|
|
26
26
|
export function useMove(props: any): MoveResult {
|
27
27
|
let { onMoveStart, onMove, onMoveEnd } = props;
|
28
28
|
|
29
|
-
const
|
29
|
+
const [initialMoveX, setInitialMoveX] = useState(0);
|
30
|
+
const [initialMoveY, setInitialMoveY] = useState(0);
|
31
|
+
const panResponder = React.useMemo(
|
30
32
|
() =>
|
31
33
|
PanResponder.create({
|
32
34
|
onMoveShouldSetPanResponderCapture: (_event) => {
|
33
35
|
return true;
|
34
36
|
},
|
35
|
-
onPanResponderGrant: (_evt) => {
|
37
|
+
onPanResponderGrant: (_evt, gestureState) => {
|
36
38
|
onMoveStart?.({
|
37
39
|
type: 'movestart',
|
38
40
|
pointerType: 'touch',
|
39
41
|
});
|
42
|
+
setInitialMoveX(gestureState.moveX);
|
43
|
+
setInitialMoveY(gestureState.moveY);
|
40
44
|
},
|
41
45
|
onPanResponderMove: (_event, gestureState) => {
|
42
|
-
|
46
|
+
const deltaX = gestureState.moveX - initialMoveX;
|
47
|
+
const deltaY = gestureState.moveY - initialMoveY;
|
48
|
+
if (deltaX === 0 && deltaY === 0) {
|
43
49
|
return;
|
44
50
|
}
|
45
51
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
+
if (deltaX) {
|
53
|
+
onMove({
|
54
|
+
type: 'move',
|
55
|
+
pointerType: 'touch',
|
56
|
+
deltaX: deltaX,
|
57
|
+
deltaY: deltaY,
|
58
|
+
});
|
59
|
+
}
|
52
60
|
},
|
53
61
|
onPanResponderRelease: () => {
|
54
62
|
onMoveEnd?.({
|
@@ -57,8 +65,8 @@ export function useMove(props: any): MoveResult {
|
|
57
65
|
});
|
58
66
|
},
|
59
67
|
}),
|
60
|
-
[onMove, onMoveEnd, onMoveStart]
|
68
|
+
[onMove, onMoveEnd, onMoveStart, initialMoveX, initialMoveY]
|
61
69
|
);
|
62
70
|
|
63
|
-
return { moveProps:
|
71
|
+
return { moveProps: panResponder.panHandlers };
|
64
72
|
}
|
package/src/useMove.web.ts
CHANGED
@@ -50,11 +50,13 @@ export function useMove(props: MoveEvents): MoveResult {
|
|
50
50
|
|
51
51
|
if (!state.current.didMove) {
|
52
52
|
state.current.didMove = true;
|
53
|
+
// @ts-ignore
|
53
54
|
onMoveStart?.({
|
54
55
|
type: 'movestart',
|
55
56
|
pointerType,
|
56
57
|
});
|
57
58
|
}
|
59
|
+
// @ts-ignore
|
58
60
|
onMove({
|
59
61
|
type: 'move',
|
60
62
|
pointerType,
|
@@ -65,6 +67,7 @@ export function useMove(props: MoveEvents): MoveResult {
|
|
65
67
|
let end = (pointerType: PointerType) => {
|
66
68
|
restoreTextSelection();
|
67
69
|
if (state.current.didMove) {
|
70
|
+
// @ts-ignore
|
68
71
|
onMoveEnd?.({
|
69
72
|
type: 'moveend',
|
70
73
|
pointerType,
|
package/src/useSliderThumb.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { AriaSliderThumbProps } from '@react-types/slider';
|
2
2
|
import { clamp } from '@react-aria/utils';
|
3
3
|
import { getSliderThumbId, sliderIds } from './utils';
|
4
|
-
import { useRef } from 'react';
|
4
|
+
import { useRef, useState } from 'react';
|
5
5
|
import { SliderState } from '@react-stately/slider';
|
6
6
|
import { useLabel } from '@react-aria/label';
|
7
7
|
import { useMove } from './useMove';
|
@@ -52,10 +52,14 @@ export function useSliderThumb(
|
|
52
52
|
stateRef.current = state;
|
53
53
|
let reverseX = isReversed || direction === 'rtl';
|
54
54
|
let currentPosition = useRef<number>(null);
|
55
|
+
|
56
|
+
const [startPosition, setStartPosition] = useState(0);
|
57
|
+
|
55
58
|
let { moveProps } = useMove({
|
56
59
|
onMoveStart() {
|
57
|
-
currentPosition.current = null;
|
58
60
|
state.setThumbDragging(index, true);
|
61
|
+
let size = isVertical ? trackLayout.height : trackLayout.width;
|
62
|
+
setStartPosition(stateRef.current.getThumbPercent(index) * size);
|
59
63
|
},
|
60
64
|
onMove({ deltaX, deltaY }) {
|
61
65
|
let size = isVertical ? trackLayout.height : trackLayout.width;
|
@@ -75,11 +79,10 @@ export function useSliderThumb(
|
|
75
79
|
delta = -delta;
|
76
80
|
}
|
77
81
|
}
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
);
|
82
|
+
|
83
|
+
const position = startPosition + delta;
|
84
|
+
|
85
|
+
stateRef.current.setThumbPercent(index, clamp(position / size, 0, 1));
|
83
86
|
},
|
84
87
|
onMoveEnd() {
|
85
88
|
state.setThumbDragging(index, false);
|