@react-native-aria/slider 0.2.5 → 0.2.7

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.
@@ -23,7 +23,7 @@ var _utils2 = require("@react-native-aria/utils");
23
23
  * accepts click and drag motions, so that the closest thumb will follow clicks and drags on
24
24
  * the track.
25
25
  */
26
- function useSlider(props, state, trackLayout) {
26
+ function useSlider(props, state, trackLayout, isReversed) {
27
27
  var _labelProps$id;
28
28
 
29
29
  let {
@@ -38,6 +38,7 @@ function useSlider(props, state, trackLayout) {
38
38
 
39
39
  let onDownTrack = (e, id, clientX, clientY) => {
40
40
  const direction = (0, _utils2.isRTL)() ? 'rtl' : undefined;
41
+ const reverseX = isReversed || direction === 'rtl';
41
42
 
42
43
  if (!props.isDisabled && state.values.every((_, i) => !state.isThumbDragging(i))) {
43
44
  let size = isVertical ? trackLayout.height : trackLayout.width; // Find the closest thumb
@@ -47,8 +48,14 @@ function useSlider(props, state, trackLayout) {
47
48
  const offset = clickPosition - trackPosition;
48
49
  let percent = offset / size;
49
50
 
50
- if (direction === 'rtl' || isVertical) {
51
- percent = 1 - percent;
51
+ if (reverseX) {
52
+ if (!isVertical) {
53
+ percent = 1 - percent;
54
+ }
55
+ } else {
56
+ if (isVertical) {
57
+ percent = 1 - percent;
58
+ }
52
59
  }
53
60
 
54
61
  let value = state.getPercentValue(percent); // to find the closet thumb we split the array based on the first thumb position to the "right/end" of the click.
@@ -1 +1 @@
1
- {"version":3,"sources":["useSlider.ts"],"names":["useSlider","props","state","trackLayout","labelProps","fieldProps","isVertical","orientation","sliderIds","set","id","currentPointer","undefined","onDownTrack","e","clientX","clientY","direction","isDisabled","values","every","_","i","isThumbDragging","size","height","width","trackPosition","clickPosition","offset","percent","value","getPercentValue","closestThumb","split","findIndex","v","length","lastLeft","firstRight","Math","abs","isThumbEditable","preventDefault","setFocusedThumb","current","setThumbDragging","setThumbValue","groupProps","trackProps","onPress","locationX","locationY","nativeEvent","outputPro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EAAqC,KAArC;AACD;AACF;AACF,GAnDD;;AAqDA,SAAO;AACL7B,IAAAA,UADK;AAEL4C,IAAAA,UAAU,EAAE,EAFP;AAGLC,IAAAA,UAAU,EAAE;AACVC,MAAAA,OAAO,EAAGpC,CAAD,IAAY;AACnB,cAAM;AAAEqC,UAAAA,SAAF;AAAaC,UAAAA;AAAb,YAA2BtC,CAAC,CAACuC,WAAnC;AACAxC,QAAAA,WAAW,CAACC,CAAD,EAAIF,SAAJ,EAAeuC,SAAf,EAA0BC,SAA1B,CAAX;AACD;AAJS,KAHP;AASLE,IAAAA,WAAW,EAAE;AATR,GAAP;AAWD","sourcesContent":["import { sliderIds } from './utils';\nimport { AriaSliderProps } from '@react-types/slider';\nimport React, { useRef } from 'react';\nimport { SliderState } from '@react-stately/slider';\nimport { useLabel } from '@react-aria/label';\nimport { isRTL } from '@react-native-aria/utils';\n\ninterface SliderAria {\n /** Props for the label element. */\n labelProps: any;\n\n /** Props for the root element of the slider component; groups slider inputs. */\n groupProps: any;\n\n /** Props for the track element. */\n trackProps: any;\n\n /** Props for the output element, displaying the value of the slider thumbs. */\n outputProps: any;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a slider component representing one or more values.\n *\n * @param props Props for the slider.\n * @param state State for the slider, as returned by `useSliderState`.\n * @param trackRef Ref for the \"track\" element. The width of this element provides the \"length\"\n * of the track -- the span of one dimensional space that the slider thumb can be. It also\n * accepts click and drag motions, so that the closest thumb will follow clicks and drags on\n * the track.\n */\nexport function useSlider(\n props: AriaSliderProps,\n state: SliderState,\n trackLayout: any\n): SliderAria {\n let { labelProps, fieldProps } = useLabel(props);\n\n let isVertical = props.orientation === 'vertical';\n\n sliderIds.set(state, labelProps.id ?? fieldProps.id);\n let currentPointer = useRef<number | null | undefined>(undefined);\n\n let onDownTrack = (\n e: React.UIEvent,\n id: number,\n clientX: number,\n clientY: number\n ) => {\n const direction = isRTL() ? 'rtl' : undefined;\n if (\n !props.isDisabled &&\n state.values.every((_, i) => !state.isThumbDragging(i))\n ) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n // Find the closest thumb\n const trackPosition = trackLayout[isVertical ? 'y' : 'x'];\n const clickPosition = isVertical ? clientY : clientX;\n const offset = clickPosition - trackPosition;\n let percent = offset / size;\n if (direction === 'rtl' || isVertical) {\n percent = 1 - percent;\n }\n let value = state.getPercentValue(percent);\n // to find the closet thumb we split the array based on the first thumb position to the \"right/end\" of the click.\n let closestThumb;\n let split = state.values.findIndex((v) => value - v < 0);\n if (split === 0) {\n // If the index is zero then the closetThumb is the first one\n closestThumb = split;\n } else if (split === -1) {\n // If no index is found they've clicked past all the thumbs\n closestThumb = state.values.length - 1;\n } else {\n let lastLeft = state.values[split - 1];\n let firstRight = state.values[split];\n // Pick the last left/start thumb, unless they are stacked on top of each other, then pick the right/end one\n if (Math.abs(lastLeft - value) < Math.abs(firstRight - value)) {\n closestThumb = split - 1;\n } else {\n closestThumb = split;\n }\n }\n // Confirm that the found closest thumb is editable, not disabled, and move it\n if (closestThumb >= 0 && state.isThumbEditable(closestThumb)) {\n // Don't unfocus anything\n e.preventDefault();\n state.setFocusedThumb(closestThumb);\n currentPointer.current = id;\n state.setThumbDragging(closestThumb, true);\n state.setThumbValue(closestThumb, value);\n state.setThumbDragging(closestThumb, false);\n }\n }\n };\n\n return {\n labelProps,\n groupProps: {},\n trackProps: {\n onPress: (e: any) => {\n const { locationX, locationY } = e.nativeEvent;\n onDownTrack(e, undefined, locationX, locationY);\n },\n },\n outputProps: {},\n };\n}\n"]}
1
+ {"version":3,"sources":["useSlider.ts"],"names":["useSlider","props","state","trackLayout","isReversed","labelProps","fieldProps","isVertical","orientation","sliderIds","set","id","currentPointer","undefined","onDownTrack","e","clientX","clientY","direction","reverseX","isDisabled","values","every","_","i","isThumbDragging","size","height","width","trackPosition","clickPosition","offset","percent","value","getPercentValue","closestThumb","split","findIndex","v","length","lastLeft","firstRight","Math","abs","isThumbEditable","preventDefault","setFocusedThumb","current","setThumbDragging","setThumbValue","groupProps","trackProps","onPress","locationX","locationY","nativeEvent","outputProps"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;AACA;;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,SAAT,CACLC,KADK,EAELC,KAFK,EAGLC,WAHK,EAILC,UAJK,EAKO;AAAA;;AACZ,MAAI;AAAEC,IAAAA,UAAF;AAAcC,IAAAA;AAAd,MAA6B,qBAASL,KAAT,CAAjC;AAEA,MAAIM,UAAU,GAAGN,KAAK,CAACO,WAAN,KAAsB,UAAvC;;AAEAC,mBAAUC,GAAV,CAAcR,KAAd,oBAAqBG,UAAU,CAACM,EAAhC,2DAAsCL,UAAU,CAACK,EAAjD;;AACA,MAAIC,cAAc,GAAG,mBAAkCC,SAAlC,CAArB;;AAEA,MAAIC,WAAW,GAAG,CAChBC,CADgB,EAEhBJ,EAFgB,EAGhBK,OAHgB,EAIhBC,OAJgB,KAKb;AACH,UAAMC,SAAS,GAAG,uBAAU,KAAV,GAAkBL,SAApC;AACA,UAAMM,QAAQ,GAAGf,UAAU,IAAIc,SAAS,KAAK,KAA7C;;AACA,QACE,CAACjB,KAAK,CAACmB,UAAP,IACAlB,KAAK,CAACmB,MAAN,CAAaC,KAAb,CAAmB,CAACC,CAAD,EAAIC,CAAJ,KAAU,CAACtB,KAAK,CAACuB,eAAN,CAAsBD,CAAtB,CAA9B,CAFF,EAGE;AACA,UAAIE,IAAI,GAAGnB,UAAU,GAAGJ,WAAW,CAACwB,MAAf,GAAwBxB,WAAW,CAACyB,KAAzD,CADA,CAEA;;AACA,YAAMC,aAAa,GAAG1B,WAAW,CAACI,UAAU,GAAG,GAAH,GAAS,GAApB,CAAjC;AACA,YAAMuB,aAAa,GAAGvB,UAAU,GAAGU,OAAH,GAAaD,OAA7C;AACA,YAAMe,MAAM,GAAGD,aAAa,GAAGD,aAA/B;AACA,UAAIG,OAAO,GAAGD,MAAM,GAAGL,IAAvB;;AACA,UAAIP,QAAJ,E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,CAACmC,OAAf,GAAyBpC,EAAzB;AACAT,QAAAA,KAAK,CAAC8C,gBAAN,CAAuBb,YAAvB,EAAqC,IAArC;AACAjC,QAAAA,KAAK,CAAC+C,aAAN,CAAoBd,YAApB,EAAkCF,KAAlC;AACA/B,QAAAA,KAAK,CAAC8C,gBAAN,CAAuBb,YAAvB,EAAqC,KAArC;AACD;AACF;AACF,GA1DD;;AA4DA,SAAO;AACL9B,IAAAA,UADK;AAEL6C,IAAAA,UAAU,EAAE,EAFP;AAGLC,IAAAA,UAAU,EAAE;AACVC,MAAAA,OAAO,EAAGrC,CAAD,IAAY;AACnB,cAAM;AAAEsC,UAAAA,SAAF;AAAaC,UAAAA;AAAb,YAA2BvC,CAAC,CAACwC,WAAnC;AACAzC,QAAAA,WAAW,CAACC,CAAD,EAAIF,SAAJ,EAAewC,SAAf,EAA0BC,SAA1B,CAAX;AACD;AAJS,KAHP;AASLE,IAAAA,WAAW,EAAE;AATR,GAAP;AAWD","sourcesContent":["import { sliderIds } from './utils';\nimport { AriaSliderProps } from '@react-types/slider';\nimport React, { useRef } from 'react';\nimport { SliderState } from '@react-stately/slider';\nimport { useLabel } from '@react-aria/label';\nimport { isRTL } from '@react-native-aria/utils';\n\ninterface SliderAria {\n /** Props for the label element. */\n labelProps: any;\n\n /** Props for the root element of the slider component; groups slider inputs. */\n groupProps: any;\n\n /** Props for the track element. */\n trackProps: any;\n\n /** Props for the output element, displaying the value of the slider thumbs. */\n outputProps: any;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a slider component representing one or more values.\n *\n * @param props Props for the slider.\n * @param state State for the slider, as returned by `useSliderState`.\n * @param trackRef Ref for the \"track\" element. The width of this element provides the \"length\"\n * of the track -- the span of one dimensional space that the slider thumb can be. It also\n * accepts click and drag motions, so that the closest thumb will follow clicks and drags on\n * the track.\n */\nexport function useSlider(\n props: AriaSliderProps,\n state: SliderState,\n trackLayout: any,\n isReversed?: boolean\n): SliderAria {\n let { labelProps, fieldProps } = useLabel(props);\n\n let isVertical = props.orientation === 'vertical';\n\n sliderIds.set(state, labelProps.id ?? fieldProps.id);\n let currentPointer = useRef<number | null | undefined>(undefined);\n\n let onDownTrack = (\n e: React.UIEvent,\n id: number,\n clientX: number,\n clientY: number\n ) => {\n const direction = isRTL() ? 'rtl' : undefined;\n const reverseX = isReversed || direction === 'rtl';\n if (\n !props.isDisabled &&\n state.values.every((_, i) => !state.isThumbDragging(i))\n ) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n // Find the closest thumb\n const trackPosition = trackLayout[isVertical ? 'y' : 'x'];\n const clickPosition = isVertical ? clientY : clientX;\n const offset = clickPosition - trackPosition;\n let percent = offset / size;\n if (reverseX) {\n if (!isVertical) {\n percent = 1 - percent;\n }\n } else {\n if (isVertical) {\n percent = 1 - percent;\n }\n }\n let value = state.getPercentValue(percent);\n // to find the closet thumb we split the array based on the first thumb position to the \"right/end\" of the click.\n let closestThumb;\n let split = state.values.findIndex((v) => value - v < 0);\n if (split === 0) {\n // If the index is zero then the closetThumb is the first one\n closestThumb = split;\n } else if (split === -1) {\n // If no index is found they've clicked past all the thumbs\n closestThumb = state.values.length - 1;\n } else {\n let lastLeft = state.values[split - 1];\n let firstRight = state.values[split];\n // Pick the last left/start thumb, unless they are stacked on top of each other, then pick the right/end one\n if (Math.abs(lastLeft - value) < Math.abs(firstRight - value)) {\n closestThumb = split - 1;\n } else {\n closestThumb = split;\n }\n }\n // Confirm that the found closest thumb is editable, not disabled, and move it\n if (closestThumb >= 0 && state.isThumbEditable(closestThumb)) {\n // Don't unfocus anything\n e.preventDefault();\n state.setFocusedThumb(closestThumb);\n currentPointer.current = id;\n state.setThumbDragging(closestThumb, true);\n state.setThumbValue(closestThumb, value);\n state.setThumbDragging(closestThumb, false);\n }\n }\n };\n\n return {\n labelProps,\n groupProps: {},\n trackProps: {\n onPress: (e: any) => {\n const { locationX, locationY } = e.nativeEvent;\n onDownTrack(e, undefined, locationX, locationY);\n },\n },\n outputProps: {},\n };\n}\n"]}
@@ -19,7 +19,7 @@ var _utils3 = require("@react-native-aria/utils");
19
19
 
20
20
  var _useMove = require("./useMove");
21
21
 
22
- function useSliderWeb(props, state, trackLayout) {
22
+ function useSliderWeb(props, state, trackLayout, isReversed) {
23
23
  var _labelProps$id;
24
24
 
25
25
  let {
@@ -42,7 +42,7 @@ function useSliderWeb(props, state, trackLayout) {
42
42
  const realTimeTrackDraggingIndex = (0, _react.useRef)(null);
43
43
  const stateRef = (0, _react.useRef)(null);
44
44
  stateRef.current = state;
45
- const reverseX = direction === 'rtl';
45
+ const reverseX = isReversed || direction === 'rtl';
46
46
  const currentPosition = (0, _react.useRef)(null);
47
47
  const {
48
48
  moveProps
@@ -63,8 +63,14 @@ function useSliderWeb(props, state, trackLayout) {
63
63
 
64
64
  let delta = isVertical ? deltaY : deltaX;
65
65
 
66
- if (isVertical || reverseX) {
67
- delta = -delta;
66
+ if (reverseX) {
67
+ if (!isVertical) {
68
+ delta = -delta;
69
+ }
70
+ } else {
71
+ if (isVertical) {
72
+ delta = -delta;
73
+ }
68
74
  }
69
75
 
70
76
  currentPosition.current += delta;
@@ -95,8 +101,14 @@ function useSliderWeb(props, state, trackLayout) {
95
101
  const offset = clickPosition - trackPosition;
96
102
  let percent = offset / size;
97
103
 
98
- if (direction === 'rtl' || isVertical) {
99
- percent = 1 - percent;
104
+ if (reverseX) {
105
+ if (!isVertical) {
106
+ percent = 1 - percent;
107
+ }
108
+ } else {
109
+ if (isVertical) {
110
+ percent = 1 - percent;
111
+ }
100
112
  }
101
113
 
102
114
  let value = state.getPercentValue(percent); // to find the closet thumb we split the array based on the first thumb position to the "right/end" of the click.
@@ -211,11 +223,11 @@ function useSliderWeb(props, state, trackLayout) {
211
223
  };
212
224
  }
213
225
 
214
- const useSlider = (props, state, ref) => {
226
+ const useSlider = (props, state, ref, isReversed) => {
215
227
  let {
216
228
  groupProps: webGroupProps,
217
229
  ...rest
218
- } = useSliderWeb(props, state, ref);
230
+ } = useSliderWeb(props, state, ref, isReversed);
219
231
  let groupProps = (0, _utils3.mapDomPropsToRN)(webGroupProps);
220
232
  let labelProps = (0, _utils3.mapDomPropsToRN)(rest.labelProps);
221
233
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["useSlider.web.ts"],"names":["useSliderWeb","props","state","trackLayout","labelProps","fieldProps","isVertical","orientation","sliderIds","set","id","direction","undefined","addGlobalListener","removeGlobalListener","realTimeTrackDraggingIndex","stateRef","current","reverseX","currentPosition","moveProps","onMoveStart","onMove","deltaX","deltaY","size","height","width","getThumbPercent","delta","percent","setThumbPercent","onMoveEnd","setThumbDragging","currentPointer","onDownTrack","e","clientX","clientY","isDisabled","values","every","_","i","isThumbDragging","trackPosition","clickPosition","offset","value","getPercentValue","closestThumb","split","findIndex","v","length","lastLeft","firstRight","Math","abs","isThumbEditable","preventDefault","setFocusedThumb","setThumbValue","window","onUpTrack","pointerId","changedTouches","identifier","htmlFor","onClick","document","getElementById","focus","groupProps","role","trackProps","onMouseDown","button","altKey","ctrlKey","metaKey","onPointerDown","pointerType","onTouchStart","outputProps","map","index","join","useSlider","ref","webGroupProps","rest"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AAgBA,SAASA,YAAT,CACEC,KADF,EAEEC,KAFF,EAGEC,WAHF,EAWc;AAAA;;AACZ,MAAI;AAAEC,IAAAA,UAAF;AAAcC,IAAAA;AAAd,MAA6B,qBAASJ,KAAT,CAAjC;AAEA,MAAIK,UAAU,GAAGL,KAAK,CAACM,WAAN,KAAsB,UAAvC,CAHY,CAKZ;;AACAC,oBAAUC,GAAV,CAAcP,KAAd,oBAAqBE,UAAU,CAACM,EAAhC,2DAAsCL,UAAU,CAACK,EAAjD;;AAEA,QAAMC,SAAS,GAAG,uBAAU,KAAV,GAAkBC,SAApC;AAEA,MAAI;AAAEC,IAAAA,iBAAF;AAAqBC,IAAAA;AAArB,MAA8C,gCAAlD,CAVY,CAYZ;AACA;AACA;AACA;;AACA,QAAMC,0BA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mBAAa;AAJF;AArCR,GAAP;AA4CD;;AAEM,MAAMC,SAAS,GAAG,CAACvF,KAAD,EAAaC,KAAb,EAAyBuF,GAAzB,KAAsC;AAC7D,MAAI;AAAEhB,IAAAA,UAAU,EAAEiB,aAAd;AAA6B,OAAGC;AAAhC,MAAyC3F,YAAY,CAACC,KAAD,EAAQC,KAAR,EAAeuF,GAAf,CAAzD;AACA,MAAIhB,UAAU,GAAG,6BAAgBiB,aAAhB,CAAjB;AACA,MAAItF,UAAU,GAAG,6BAAgBuF,IAAI,CAACvF,UAArB,CAAjB;AACA,SAAO;AAAEqE,IAAAA,UAAF;AAAc,OAAGkB,IAAjB;AAAuBvF,IAAAA;AAAvB,GAAP;AACD,CALM","sourcesContent":["import { AriaSliderProps } from '@react-types/slider';\nimport { clamp, mergeProps, useGlobalListeners } from '@react-aria/utils';\nimport { getSliderThumbId, sliderIds } from './utils';\nimport React, { useRef } from 'react';\nimport { setInteractionModality } from '@react-aria/interactions';\nimport { SliderState } from '@react-stately/slider';\nimport { useLabel } from '@react-aria/label';\nimport { mapDomPropsToRN, isRTL } from '@react-native-aria/utils';\nimport { useMove } from './useMove';\n\ninterface SliderAria {\n /** Props for the label element. */\n labelProps: any;\n\n /** Props for the root element of the slider component; groups slider inputs. */\n groupProps: any;\n\n /** Props for the track element. */\n trackProps: any;\n\n /** Props for the output element, displaying the value of the slider thumbs. */\n outputProps: any;\n}\n\nfunction useSliderWeb(\n props: AriaSliderProps,\n state: SliderState,\n trackLayout: {\n height: number;\n width: number;\n top: number;\n left: number;\n x: number;\n y: number;\n }\n): SliderAria {\n let { labelProps, fieldProps } = useLabel(props);\n\n let isVertical = props.orientation === 'vertical';\n\n // Attach id of the label to the state so it can be accessed by useSliderThumb.\n sliderIds.set(state, labelProps.id ?? fieldProps.id);\n\n const direction = isRTL() ? 'rtl' : undefined;\n\n let { addGlobalListener, removeGlobalListener } = useGlobalListeners();\n\n // When the user clicks or drags the track, we want the motion to set and drag the\n // closest thumb. Hence we also need to install useMove() on the track element.\n // Here, we keep track of which index is the \"closest\" to the drag start point.\n // It is set onMouseDown/onTouchDown; see trackProps below.\n const realTimeTrackDraggingIndex = useRef<number | null>(null);\n\n const stateRef = useRef<SliderState>(null);\n stateRef.current = state;\n const reverseX = direction === 'rtl';\n const currentPosition = useRef<number>(null);\n const { moveProps } = useMove({\n onMoveStart() {\n currentPosition.current = null;\n },\n onMove({ deltaX, deltaY }) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n\n if (currentPosition.current == null) {\n currentPosition.current =\n stateRef.current.getThumbPercent(realTimeTrackDraggingIndex.current) *\n size;\n }\n\n let delta = isVertical ? deltaY : deltaX;\n if (isVertical || reverseX) {\n delta = -delta;\n }\n\n currentPosition.current += delta;\n\n if (realTimeTrackDraggingIndex.current != null) {\n const percent = clamp(currentPosition.current / size, 0, 1);\n stateRef.current.setThumbPercent(\n realTimeTrackDraggingIndex.current,\n percent\n );\n }\n },\n onMoveEnd() {\n if (realTimeTrackDraggingIndex.current != null) {\n stateRef.current.setThumbDragging(\n realTimeTrackDraggingIndex.current,\n false\n );\n realTimeTrackDraggingIndex.current = null;\n }\n },\n });\n\n let currentPointer = useRef<number | null | undefined>(undefined);\n let onDownTrack = (\n e: React.UIEvent,\n id: number,\n clientX: number,\n clientY: number\n ) => {\n // We only trigger track-dragging if the user clicks on the track itself and nothing is currently being dragged.\n if (\n !props.isDisabled &&\n state.values.every((_, i) => !state.isThumbDragging(i))\n ) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n // Find the closest thumb\n const trackPosition = trackLayout[isVertical ? 'top' : 'left'];\n const clickPosition = isVertical ? clientY : clientX;\n const offset = clickPosition - trackPosition;\n let percent = offset / size;\n if (direction === 'rtl' || isVertical) {\n percent = 1 - percent;\n }\n let value = state.getPercentValue(percent);\n\n // to find the closet thumb we split the array based on the first thumb position to the \"right/end\" of the click.\n let closestThumb;\n let split = state.values.findIndex((v) => value - v < 0);\n if (split === 0) {\n // If the index is zero then the closetThumb is the first one\n closestThumb = split;\n } else if (split === -1) {\n // If no index is found they've clicked past all the thumbs\n closestThumb = state.values.length - 1;\n } else {\n let lastLeft = state.values[split - 1];\n let firstRight = state.values[split];\n // Pick the last left/start thumb, unless they are stacked on top of each other, then pick the right/end one\n if (Math.abs(lastLeft - value) < Math.abs(firstRight - value)) {\n closestThumb = split - 1;\n } else {\n closestThumb = split;\n }\n }\n\n // Confirm that the found closest thumb is editable, not disabled, and move it\n if (closestThumb >= 0 && state.isThumbEditable(closestThumb)) {\n // Don't unfocus anything\n e.preventDefault();\n\n realTimeTrackDraggingIndex.current = closestThumb;\n state.setFocusedThumb(closestThumb);\n currentPointer.current = id;\n\n state.setThumbDragging(realTimeTrackDraggingIndex.current, true);\n state.setThumbValue(closestThumb, value);\n\n addGlobalListener(window, 'mouseup', onUpTrack, false);\n addGlobalListener(window, 'touchend', onUpTrack, false);\n addGlobalListener(window, 'pointerup', onUpTrack, false);\n } else {\n realTimeTrackDraggingIndex.current = null;\n }\n }\n };\n\n let onUpTrack = (e) => {\n let id = e.pointerId ?? e.changedTouches?.[0].identifier;\n if (id === currentPointer.current) {\n if (realTimeTrackDraggingIndex.current != null) {\n state.setThumbDragging(realTimeTrackDraggingIndex.current, false);\n realTimeTrackDraggingIndex.current = null;\n }\n\n removeGlobalListener(window, 'mouseup', onUpTrack, false);\n removeGlobalListener(window, 'touchend', onUpTrack, false);\n removeGlobalListener(window, 'pointerup', onUpTrack, false);\n }\n };\n\n if (labelProps.htmlFor) {\n // Ideally the `for` attribute should point to the first thumb, but VoiceOver on iOS\n // causes this to override the `aria-labelledby` on the thumb. This causes the first\n // thumb to only be announced as the slider label rather than its individual name as well.\n // See https://bugs.webkit.org/show_bug.cgi?id=172464.\n delete labelProps.htmlFor;\n labelProps.onClick = () => {\n // Safari does not focus <input type=\"range\"> elements when clicking on an associated <label>,\n // so do it manually. In addition, make sure we show the focus ring.\n document.getElementById(getSliderThumbId(state, 0))?.focus();\n setInteractionModality('keyboard');\n };\n }\n\n return {\n labelProps,\n // The root element of the Slider will have role=\"group\" to group together\n // all the thumb inputs in the Slider. The label of the Slider will\n // be used to label the group.\n groupProps: {\n role: 'group',\n ...fieldProps,\n },\n trackProps: mergeProps(\n {\n onMouseDown(e: React.MouseEvent<HTMLElement>) {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onDownTrack(e, undefined, e.clientX, e.clientY);\n },\n onPointerDown(e: React.PointerEvent<HTMLElement>) {\n if (\n e.pointerType === 'mouse' &&\n (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)\n ) {\n return;\n }\n onDownTrack(e, e.pointerId, e.clientX, e.clientY);\n },\n onTouchStart(e: React.TouchEvent<HTMLElement>) {\n onDownTrack(\n e,\n e.changedTouches[0].identifier,\n e.changedTouches[0].clientX,\n e.changedTouches[0].clientY\n );\n },\n },\n moveProps\n ),\n outputProps: {\n 'htmlFor': state.values\n .map((_, index) => getSliderThumbId(state, index))\n .join(' '),\n 'aria-live': 'off',\n },\n };\n}\n\nexport const useSlider = (props: any, state: any, ref: any) => {\n let { groupProps: webGroupProps, ...rest } = useSliderWeb(props, state, ref);\n let groupProps = mapDomPropsToRN(webGroupProps);\n let labelProps = mapDomPropsToRN(rest.labelProps);\n return { groupProps, ...rest, labelProps };\n};\n"]}
1
+ {"version":3,"sources":["useSlider.web.ts"],"names":["useSliderWeb","props","state","trackLayout","isReversed","labelProps","fieldProps","isVertical","orientation","sliderIds","set","id","direction","undefined","addGlobalListener","removeGlobalListener","realTimeTrackDraggingIndex","stateRef","current","reverseX","currentPosition","moveProps","onMoveStart","onMove","deltaX","deltaY","size","height","width","getThumbPercent","delta","percent","setThumbPercent","onMoveEnd","setThumbDragging","currentPointer","onDownTrack","e","clientX","clientY","isDisabled","values","every","_","i","isThumbDragging","trackPosition","clickPosition","offset","value","getPercentValue","closestThumb","split","findIndex","v","length","lastLeft","firstRight","Math","abs","isThumbEditable","preventDefault","setFocusedThumb","setThumbValue","window","onUpTrack","pointerId","changedTouches","identifier","htmlFor","onClick","document","getElementById","focus","groupProps","role","trackProps","onMouseDown","button","altKey","ctrlKey","metaKey","onPointerDown","pointerType","onTouchStart","outputProps","map","index","join","useSlider","ref","webGroupProps","rest"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AAgBA,SAASA,YAAT,CACEC,KADF,EAEEC,KAFF,EAGEC,WAHF,EAWEC,UAXF,EAYc;AAAA;;AACZ,MAAI;AAAEC,IAAAA,UAAF;AAAcC,IAAAA;AAAd,MAA6B,qBAASL,KAAT,CAAjC;AAEA,MAAIM,UAAU,GAAGN,KAAK,CAACO,WAAN,KAAsB,UAAvC,CAHY,CAKZ;;AACAC,oBAAUC,GAAV,CAAcR,KAAd,oBAAqBG,UAAU,CAACM,EAAhC,2DAAsCL,UAAU,CAACK,EAAjD;;AAEA,QAAMC,SAAS,GAAG,uBAAU,KAAV,GAAkBC,SAApC;AAEA,MAAI;AAAEC,IAAAA,iBAAF;AAAqBC,IAAAA;AAArB,MAA8C,gCAAlD,CAVY,CAYZ;AACA;AACA;AACA;;AACA,QAAMC,0BAA0B,GAAG,mBAAsB,IAAtB,CAAnC;AAEA,QAAMC,QAAQ,GAAG,mBAAoB,IAApB,CAAjB;AACAA,EAAAA,QAAQ,CAACC,OAAT,GAAmBhB,KAAnB;AACA,QAAMiB,QAAQ,GAAGf,UAAU,IAAIQ,SAAS,KAAK,KAA7C;AAEA,QAAMQ,eAAe,GAAG,mBAAe,IAAf,CAAxB;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAgB,sBAAQ;AAC5BC,IAAAA,WAAW,GAAG;AACZF,MAAAA,eAAe,CAACF,OAAhB,GAA0B,IAA1B;AACD,KAH2B;;AAI5BK,IAAAA,MAAM,CAAC;AAAEC,MAAAA,MAAF;AAAUC,MAAAA;AAAV,KAAD,EAAqB;AACzB,UAAIC,IAAI,GAAGnB,UAAU,GAAGJ,WAAW,CAACwB,MAAf,GAAwB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E,UAAU,GAAG,6BAAgBiB,aAAhB,CAAjB;AACA,MAAItF,UAAU,GAAG,6BAAgBuF,IAAI,CAACvF,UAArB,CAAjB;AACA,SAAO;AAAEqE,IAAAA,UAAF;AAAc,OAAGkB,IAAjB;AAAuBvF,IAAAA;AAAvB,GAAP;AACD,CAfM","sourcesContent":["import { AriaSliderProps } from '@react-types/slider';\nimport { clamp, mergeProps, useGlobalListeners } from '@react-aria/utils';\nimport { getSliderThumbId, sliderIds } from './utils';\nimport React, { useRef } from 'react';\nimport { setInteractionModality } from '@react-aria/interactions';\nimport { SliderState } from '@react-stately/slider';\nimport { useLabel } from '@react-aria/label';\nimport { mapDomPropsToRN, isRTL } from '@react-native-aria/utils';\nimport { useMove } from './useMove';\n\ninterface SliderAria {\n /** Props for the label element. */\n labelProps: any;\n\n /** Props for the root element of the slider component; groups slider inputs. */\n groupProps: any;\n\n /** Props for the track element. */\n trackProps: any;\n\n /** Props for the output element, displaying the value of the slider thumbs. */\n outputProps: any;\n}\n\nfunction useSliderWeb(\n props: AriaSliderProps,\n state: SliderState,\n trackLayout: {\n height: number;\n width: number;\n top: number;\n left: number;\n x: number;\n y: number;\n },\n isReversed?: boolean\n): SliderAria {\n let { labelProps, fieldProps } = useLabel(props);\n\n let isVertical = props.orientation === 'vertical';\n\n // Attach id of the label to the state so it can be accessed by useSliderThumb.\n sliderIds.set(state, labelProps.id ?? fieldProps.id);\n\n const direction = isRTL() ? 'rtl' : undefined;\n\n let { addGlobalListener, removeGlobalListener } = useGlobalListeners();\n\n // When the user clicks or drags the track, we want the motion to set and drag the\n // closest thumb. Hence we also need to install useMove() on the track element.\n // Here, we keep track of which index is the \"closest\" to the drag start point.\n // It is set onMouseDown/onTouchDown; see trackProps below.\n const realTimeTrackDraggingIndex = useRef<number | null>(null);\n\n const stateRef = useRef<SliderState>(null);\n stateRef.current = state;\n const reverseX = isReversed || direction === 'rtl';\n\n const currentPosition = useRef<number>(null);\n const { moveProps } = useMove({\n onMoveStart() {\n currentPosition.current = null;\n },\n onMove({ deltaX, deltaY }) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n\n if (currentPosition.current == null) {\n currentPosition.current =\n stateRef.current.getThumbPercent(realTimeTrackDraggingIndex.current) *\n size;\n }\n\n let delta = isVertical ? deltaY : deltaX;\n if (reverseX) {\n if (!isVertical) {\n delta = -delta;\n }\n } else {\n if (isVertical) {\n delta = -delta;\n }\n }\n\n currentPosition.current += delta;\n\n if (realTimeTrackDraggingIndex.current != null) {\n const percent = clamp(currentPosition.current / size, 0, 1);\n stateRef.current.setThumbPercent(\n realTimeTrackDraggingIndex.current,\n percent\n );\n }\n },\n onMoveEnd() {\n if (realTimeTrackDraggingIndex.current != null) {\n stateRef.current.setThumbDragging(\n realTimeTrackDraggingIndex.current,\n false\n );\n realTimeTrackDraggingIndex.current = null;\n }\n },\n });\n\n let currentPointer = useRef<number | null | undefined>(undefined);\n let onDownTrack = (\n e: React.UIEvent,\n id: number,\n clientX: number,\n clientY: number\n ) => {\n // We only trigger track-dragging if the user clicks on the track itself and nothing is currently being dragged.\n if (\n !props.isDisabled &&\n state.values.every((_, i) => !state.isThumbDragging(i))\n ) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n // Find the closest thumb\n const trackPosition = trackLayout[isVertical ? 'top' : 'left'];\n const clickPosition = isVertical ? clientY : clientX;\n const offset = clickPosition - trackPosition;\n let percent = offset / size;\n if (reverseX) {\n if (!isVertical) {\n percent = 1 - percent;\n }\n } else {\n if (isVertical) {\n percent = 1 - percent;\n }\n }\n let value = state.getPercentValue(percent);\n\n // to find the closet thumb we split the array based on the first thumb position to the \"right/end\" of the click.\n let closestThumb;\n let split = state.values.findIndex((v) => value - v < 0);\n if (split === 0) {\n // If the index is zero then the closetThumb is the first one\n closestThumb = split;\n } else if (split === -1) {\n // If no index is found they've clicked past all the thumbs\n closestThumb = state.values.length - 1;\n } else {\n let lastLeft = state.values[split - 1];\n let firstRight = state.values[split];\n // Pick the last left/start thumb, unless they are stacked on top of each other, then pick the right/end one\n if (Math.abs(lastLeft - value) < Math.abs(firstRight - value)) {\n closestThumb = split - 1;\n } else {\n closestThumb = split;\n }\n }\n\n // Confirm that the found closest thumb is editable, not disabled, and move it\n if (closestThumb >= 0 && state.isThumbEditable(closestThumb)) {\n // Don't unfocus anything\n e.preventDefault();\n\n realTimeTrackDraggingIndex.current = closestThumb;\n state.setFocusedThumb(closestThumb);\n currentPointer.current = id;\n\n state.setThumbDragging(realTimeTrackDraggingIndex.current, true);\n state.setThumbValue(closestThumb, value);\n\n addGlobalListener(window, 'mouseup', onUpTrack, false);\n addGlobalListener(window, 'touchend', onUpTrack, false);\n addGlobalListener(window, 'pointerup', onUpTrack, false);\n } else {\n realTimeTrackDraggingIndex.current = null;\n }\n }\n };\n\n let onUpTrack = (e) => {\n let id = e.pointerId ?? e.changedTouches?.[0].identifier;\n if (id === currentPointer.current) {\n if (realTimeTrackDraggingIndex.current != null) {\n state.setThumbDragging(realTimeTrackDraggingIndex.current, false);\n realTimeTrackDraggingIndex.current = null;\n }\n\n removeGlobalListener(window, 'mouseup', onUpTrack, false);\n removeGlobalListener(window, 'touchend', onUpTrack, false);\n removeGlobalListener(window, 'pointerup', onUpTrack, false);\n }\n };\n\n if (labelProps.htmlFor) {\n // Ideally the `for` attribute should point to the first thumb, but VoiceOver on iOS\n // causes this to override the `aria-labelledby` on the thumb. This causes the first\n // thumb to only be announced as the slider label rather than its individual name as well.\n // See https://bugs.webkit.org/show_bug.cgi?id=172464.\n delete labelProps.htmlFor;\n labelProps.onClick = () => {\n // Safari does not focus <input type=\"range\"> elements when clicking on an associated <label>,\n // so do it manually. In addition, make sure we show the focus ring.\n document.getElementById(getSliderThumbId(state, 0))?.focus();\n setInteractionModality('keyboard');\n };\n }\n\n return {\n labelProps,\n // The root element of the Slider will have role=\"group\" to group together\n // all the thumb inputs in the Slider. The label of the Slider will\n // be used to label the group.\n groupProps: {\n role: 'group',\n ...fieldProps,\n },\n trackProps: mergeProps(\n {\n onMouseDown(e: React.MouseEvent<HTMLElement>) {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onDownTrack(e, undefined, e.clientX, e.clientY);\n },\n onPointerDown(e: React.PointerEvent<HTMLElement>) {\n if (\n e.pointerType === 'mouse' &&\n (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)\n ) {\n return;\n }\n onDownTrack(e, e.pointerId, e.clientX, e.clientY);\n },\n onTouchStart(e: React.TouchEvent<HTMLElement>) {\n onDownTrack(\n e,\n e.changedTouches[0].identifier,\n e.changedTouches[0].clientX,\n e.changedTouches[0].clientY\n );\n },\n },\n moveProps\n ),\n outputProps: {\n 'htmlFor': state.values\n .map((_, index) => getSliderThumbId(state, index))\n .join(' '),\n 'aria-live': 'off',\n },\n };\n}\n\nexport const useSlider = (\n props: any,\n state: any,\n ref: any,\n isReversed?: boolean\n) => {\n let { groupProps: webGroupProps, ...rest } = useSliderWeb(\n props,\n state,\n ref,\n isReversed\n );\n let groupProps = mapDomPropsToRN(webGroupProps);\n let labelProps = mapDomPropsToRN(rest.labelProps);\n return { groupProps, ...rest, labelProps };\n};\n"]}
@@ -23,7 +23,7 @@ var _utils3 = require("@react-native-aria/utils");
23
23
  * @param opts Options for this Slider thumb.
24
24
  * @param state Slider state, created via `useSliderState`.
25
25
  */
26
- function useSliderThumb(opts, state) {
26
+ function useSliderThumb(opts, state, isReversed) {
27
27
  var _opts$ariaLabelledby;
28
28
 
29
29
  let {
@@ -45,7 +45,7 @@ function useSliderThumb(opts, state) {
45
45
  });
46
46
  const stateRef = (0, _react.useRef)(null);
47
47
  stateRef.current = state;
48
- let reverseX = direction === 'rtl';
48
+ let reverseX = isReversed || direction === 'rtl';
49
49
  let currentPosition = (0, _react.useRef)(null);
50
50
  let {
51
51
  moveProps
@@ -67,8 +67,14 @@ function useSliderThumb(opts, state) {
67
67
 
68
68
  let delta = isVertical ? deltaY : deltaX;
69
69
 
70
- if (isVertical || reverseX) {
71
- delta = -delta;
70
+ if (reverseX) {
71
+ if (!isVertical) {
72
+ delta = -delta;
73
+ }
74
+ } else {
75
+ if (isVertical) {
76
+ delta = -delta;
77
+ }
72
78
  }
73
79
 
74
80
  currentPosition.current += delta;
@@ -1 +1 @@
1
- {"version":3,"sources":["useSliderThumb.ts"],"names":["useSliderThumb","opts","state","index","isDisabled","trackLayout","isVertical","orientation","direction","undefined","labelId","sliderIds","get","labelProps","fieldProps","trim","stateRef","current","reverseX","currentPosition","moveProps","onMoveStart","setThumbDragging","onMove","deltaX","deltaY","size","height","width","getThumbPercent","delta","setThumbPercent","onMoveEnd","setThumbEditable","onAccessibilityAction","event","max","getThumbMinValue","min","getThumbMaxValue","value","getThumbValue","incrementValue","Math","step","decrementValue","nativeEvent","actionName","setThumbValue","inputProps","disabled","accessibilityRole","accessibilityValue","now","accessibilityActions","name","label","thumbProps"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AAoBA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,cAAT,CACLC,IADK,EAELC,KAFK,EAGY;AAAA;;AACjB,MAAI;AAAEC,IAAAA,KAAF;AAASC,IAAAA,UAAT;AAAqBC,IAAAA;AAArB,MAAqCJ,IAAzC;AAEA,MAAIK,UAAU,GAAGL,IAAI,CAACM,WAAL,KAAqB,UAAtC;AACA,QAAMC,SAAS,GAAG,uBAAU,KAAV,GAAkBC,SAApC;;AAEA,MAAIC,OAAO,GAAGC,kBAAUC,GAAV,CAAcV,KAAd,CAAd;;AACA,QAAM;AAAEW,IAAAA,UAAF;AAAcC,IAAAA;AAAd,MAA6B,qBAAS,EAC1C,GAAGb,IADuC;AAE1C,UAAM,8BAAiBC,KAAjB,EAAwBC,KAAxB,CAFoC;AAG1C,uBAAoB,GAAEO,OAAQ,IAAX,wBAAcT,IAAI,CAAC,iBAAD,CAAlB,uEAAyC,EAAG,EAA5C,CAA8Cc,IAA9C;AAHuB,GAAT,CAAnC;AAMA,QAAMC,QAAQ,GAAG,mB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,WADR;AAEEC,QAAAA,KAAK,EAAE;AAFT,OADoB,EAKpB;AACED,QAAAA,IAAI,EAAE,WADR;AAEEC,QAAAA,KAAK,EAAE;AAFT,OALoB,CATZ;AAmBVtB,MAAAA;AAnBU,KADP;AAsBLuB,IAAAA,UAAU,EAAE,CAACrD,UAAD,GAAcgB,SAAd,GAA0B,EAtBjC;AAuBLP,IAAAA;AAvBK,GAAP;AAyBD","sourcesContent":["import { AriaSliderThumbProps } from '@react-types/slider';\nimport { clamp } from '@react-aria/utils';\nimport { getSliderThumbId, sliderIds } from './utils';\nimport { useRef } from 'react';\nimport { SliderState } from '@react-stately/slider';\nimport { useLabel } from '@react-aria/label';\nimport { useMove } from './useMove';\nimport { isRTL } from '@react-native-aria/utils';\n\ninterface SliderThumbAria {\n /** Props for the root thumb element; handles the dragging motion. */\n thumbProps: any;\n\n /** Props for the visually hidden range input element. */\n inputProps: any;\n\n /** Props for the label element for this thumb (optional). */\n labelProps: any;\n}\n\ninterface SliderThumbOptions extends AriaSliderThumbProps {\n /** A ref to the track element. */\n trackLayout: any;\n /** A ref to the thumb input element. */\n inputRef: any;\n}\n\n/**\n * Provides behavior and accessibility for a thumb of a slider component.\n *\n * @param opts Options for this Slider thumb.\n * @param state Slider state, created via `useSliderState`.\n */\nexport function useSliderThumb(\n opts: SliderThumbOptions,\n state: SliderState\n): SliderThumbAria {\n let { index, isDisabled, trackLayout } = opts;\n\n let isVertical = opts.orientation === 'vertical';\n const direction = isRTL() ? 'rtl' : undefined;\n\n let labelId = sliderIds.get(state);\n const { labelProps, fieldProps } = useLabel({\n ...opts,\n 'id': getSliderThumbId(state, index),\n 'aria-labelledby': `${labelId} ${opts['aria-labelledby'] ?? ''}`.trim(),\n });\n\n const stateRef = useRef<SliderState>(null);\n stateRef.current = state;\n let reverseX = direction === 'rtl';\n let currentPosition = useRef<number>(null);\n let { moveProps } = useMove({\n onMoveStart() {\n currentPosition.current = null;\n state.setThumbDragging(index, true);\n },\n onMove({ deltaX, deltaY }) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n\n if (currentPosition.current == null) {\n currentPosition.current =\n stateRef.current.getThumbPercent(index) * size;\n }\n\n let delta = isVertical ? deltaY : deltaX;\n if (isVertical || reverseX) {\n delta = -delta;\n }\n currentPosition.current += delta;\n stateRef.current.setThumbPercent(\n index,\n clamp(currentPosition.current / size, 0, 1)\n );\n },\n onMoveEnd() {\n state.setThumbDragging(index, false);\n },\n });\n\n state.setThumbEditable(index, !isDisabled);\n\n const onAccessibilityAction = (event: any) => {\n const max = state.getThumbMinValue(index);\n const min = state.getThumbMaxValue(index);\n const value = state.getThumbValue(index);\n\n const incrementValue = Math.min(value + state.step ?? 1, max);\n const decrementValue = Math.max(value - state.step ?? 1, min);\n\n switch (event.nativeEvent.actionName) {\n case 'increment':\n state.setThumbValue(index, incrementValue);\n break;\n case 'decrement':\n state.setThumbValue(index, decrementValue);\n break;\n default:\n break;\n }\n };\n\n return {\n inputProps: {\n ...fieldProps,\n disabled: isDisabled,\n accessibilityRole: 'adjustable',\n accessibilityValue: {\n min: state.getThumbMinValue(index),\n max: state.getThumbMaxValue(index),\n now: state.getThumbValue(index),\n },\n accessibilityActions: [\n {\n name: 'increment',\n label: 'Increment',\n },\n {\n name: 'decrement',\n label: 'Decrement',\n },\n ],\n onAccessibilityAction,\n },\n thumbProps: !isDisabled ? moveProps : {},\n labelProps,\n };\n}\n"]}
1
+ {"version":3,"sources":["useSliderThumb.ts"],"names":["useSliderThumb","opts","state","isReversed","index","isDisabled","trackLayout","isVertical","orientation","direction","undefined","labelId","sliderIds","get","labelProps","fieldProps","trim","stateRef","current","reverseX","currentPosition","moveProps","onMoveStart","setThumbDragging","onMove","deltaX","deltaY","size","height","width","getThumbPercent","delta","setThumbPercent","onMoveEnd","setThumbEditable","onAccessibilityAction","event","max","getThumbMinValue","min","getThumbMaxValue","value","getThumbValue","incrementValue","Math","step","decrementValue","nativeEvent","actionName","setThumbValue","inputProps","disabled","accessibilityRole","accessibilityVal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AvB,uCAA+B,CAA/B,EAAkCR,GAAlC,CAAvB;AACA,UAAMS,cAAc,GAAGF,IAAI,CAACP,GAAL,UAASI,KAAK,GAAGvC,KAAK,CAAC2C,IAAvB,yCAA+B,CAA/B,EAAkCN,GAAlC,CAAvB;;AAEA,YAAQH,KAAK,CAACW,WAAN,CAAkBC,UAA1B;AACE,WAAK,WAAL;AACE9C,QAAAA,KAAK,CAAC+C,aAAN,CAAoB7C,KAApB,EAA2BuC,cAA3B;AACA;;AACF,WAAK,WAAL;AACEzC,QAAAA,KAAK,CAAC+C,aAAN,CAAoB7C,KAApB,EAA2B0C,cAA3B;AACA;;AACF;AACE;AARJ;AAUD,GAlBD;;AAoBA,SAAO;AACLI,IAAAA,UAAU,EAAE,EACV,GAAGnC,UADO;AAEVoC,MAAAA,QAAQ,EAAE9C,UAFA;AAGV+C,MAAAA,iBAAiB,EAAE,YAHT;AAIVC,MAAAA,kBAAkB,EAAE;AAClBd,QAAAA,GAAG,EAAErC,KAAK,CAACoC,gBAAN,CAAuBlC,KAAvB,CADa;AAElBiC,QAAAA,GAAG,EAAEnC,KAAK,CAACsC,gBAAN,CAAuBpC,KAAvB,CAFa;AAGlBkD,QAAAA,GAAG,EAAEpD,KAAK,CAACwC,aAAN,CAAoBtC,KAApB;AAHa,OAJV;AASVmD,MAAAA,oBAAoB,EAAE,CACpB;AACEC,QAAAA,IAAI,EAAE,WADR;AAEEC,QAAAA,KAAK,EAAE;AAFT,OADoB,EAKpB;AACED,QAAAA,IAAI,EAAE,WADR;AAEEC,QAAAA,KAAK,EAAE;AAFT,OALoB,CATZ;AAmBVtB,MAAAA;AAnBU,KADP;AAsBLuB,IAAAA,UAAU,EAAE,CAACrD,UAAD,GAAcgB,SAAd,GAA0B,EAtBjC;AAuBLP,IAAAA;AAvBK,GAAP;AAyBD","sourcesContent":["import { AriaSliderThumbProps } from '@react-types/slider';\nimport { clamp } from '@react-aria/utils';\nimport { getSliderThumbId, sliderIds } from './utils';\nimport { useRef } from 'react';\nimport { SliderState } from '@react-stately/slider';\nimport { useLabel } from '@react-aria/label';\nimport { useMove } from './useMove';\nimport { isRTL } from '@react-native-aria/utils';\n\ninterface SliderThumbAria {\n /** Props for the root thumb element; handles the dragging motion. */\n thumbProps: any;\n\n /** Props for the visually hidden range input element. */\n inputProps: any;\n\n /** Props for the label element for this thumb (optional). */\n labelProps: any;\n}\n\ninterface SliderThumbOptions extends AriaSliderThumbProps {\n /** A ref to the track element. */\n trackLayout: any;\n /** A ref to the thumb input element. */\n inputRef: any;\n}\n\n/**\n * Provides behavior and accessibility for a thumb of a slider component.\n *\n * @param opts Options for this Slider thumb.\n * @param state Slider state, created via `useSliderState`.\n */\nexport function useSliderThumb(\n opts: SliderThumbOptions,\n state: SliderState,\n isReversed?: boolean\n): SliderThumbAria {\n let { index, isDisabled, trackLayout } = opts;\n\n let isVertical = opts.orientation === 'vertical';\n const direction = isRTL() ? 'rtl' : undefined;\n\n let labelId = sliderIds.get(state);\n const { labelProps, fieldProps } = useLabel({\n ...opts,\n 'id': getSliderThumbId(state, index),\n 'aria-labelledby': `${labelId} ${opts['aria-labelledby'] ?? ''}`.trim(),\n });\n\n const stateRef = useRef<SliderState>(null);\n stateRef.current = state;\n let reverseX = isReversed || direction === 'rtl';\n let currentPosition = useRef<number>(null);\n let { moveProps } = useMove({\n onMoveStart() {\n currentPosition.current = null;\n state.setThumbDragging(index, true);\n },\n onMove({ deltaX, deltaY }) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n\n if (currentPosition.current == null) {\n currentPosition.current =\n stateRef.current.getThumbPercent(index) * size;\n }\n\n let delta = isVertical ? deltaY : deltaX;\n if (reverseX) {\n if (!isVertical) {\n delta = -delta;\n }\n } else {\n if (isVertical) {\n delta = -delta;\n }\n }\n currentPosition.current += delta;\n stateRef.current.setThumbPercent(\n index,\n clamp(currentPosition.current / size, 0, 1)\n );\n },\n onMoveEnd() {\n state.setThumbDragging(index, false);\n },\n });\n\n state.setThumbEditable(index, !isDisabled);\n\n const onAccessibilityAction = (event: any) => {\n const max = state.getThumbMinValue(index);\n const min = state.getThumbMaxValue(index);\n const value = state.getThumbValue(index);\n\n const incrementValue = Math.min(value + state.step ?? 1, max);\n const decrementValue = Math.max(value - state.step ?? 1, min);\n\n switch (event.nativeEvent.actionName) {\n case 'increment':\n state.setThumbValue(index, incrementValue);\n break;\n case 'decrement':\n state.setThumbValue(index, decrementValue);\n break;\n default:\n break;\n }\n };\n\n return {\n inputProps: {\n ...fieldProps,\n disabled: isDisabled,\n accessibilityRole: 'adjustable',\n accessibilityValue: {\n min: state.getThumbMinValue(index),\n max: state.getThumbMaxValue(index),\n now: state.getThumbValue(index),\n },\n accessibilityActions: [\n {\n name: 'increment',\n label: 'Increment',\n },\n {\n name: 'decrement',\n label: 'Decrement',\n },\n ],\n onAccessibilityAction,\n },\n thumbProps: !isDisabled ? moveProps : {},\n labelProps,\n };\n}\n"]}
@@ -25,7 +25,7 @@ var _utils3 = require("@react-native-aria/utils");
25
25
  * @param opts Options for this Slider thumb.
26
26
  * @param state Slider state, created via `useSliderState`.
27
27
  */
28
- function useSliderThumb(opts, state) {
28
+ function useSliderThumb(opts, state, isReversed) {
29
29
  var _opts$ariaLabelledby;
30
30
 
31
31
  let {
@@ -66,7 +66,7 @@ function useSliderThumb(opts, state) {
66
66
  }, [isFocused, focusInput]);
67
67
  const stateRef = (0, _react.useRef)(null);
68
68
  stateRef.current = state;
69
- let reverseX = direction === 'rtl';
69
+ let reverseX = isReversed || direction === 'rtl';
70
70
  let currentPosition = (0, _react.useRef)(null);
71
71
  let {
72
72
  moveProps
@@ -89,14 +89,20 @@ function useSliderThumb(opts, state) {
89
89
 
90
90
  if (pointerType === 'keyboard') {
91
91
  // (invert left/right according to language direction) + (according to vertical)
92
- let delta = ((reverseX ? -deltaX : deltaX) + (isVertical ? -deltaY : -deltaY)) * stateRef.current.step;
92
+ let delta = ((reverseX ? -deltaX : deltaX) + (reverseX ? deltaY : -deltaY)) * stateRef.current.step;
93
93
  currentPosition.current += delta * size;
94
94
  stateRef.current.setThumbValue(index, stateRef.current.getThumbValue(index) + delta);
95
95
  } else {
96
96
  let delta = isVertical ? deltaY : deltaX;
97
97
 
98
- if (isVertical || reverseX) {
99
- delta = -delta;
98
+ if (reverseX) {
99
+ if (!isVertical) {
100
+ delta = -delta;
101
+ }
102
+ } else {
103
+ if (isVertical) {
104
+ delta = -delta;
105
+ }
100
106
  }
101
107
 
102
108
  currentPosition.current += delta;
@@ -1 +1 @@
1
- {"version":3,"sources":["useSliderThumb.web.ts"],"names":["useSliderThumb","opts","state","index","isRequired","isDisabled","validationState","trackLayout","inputRef","isVertical","orientation","direction","undefined","addGlobalListener","removeGlobalListener","labelId","sliderIds","get","labelProps","fieldProps","trim","value","values","focusInput","current","isFocused","focusedThumb","stateRef","reverseX","currentPosition","moveProps","onMoveStart","setThumbDragging","onMove","deltaX","deltaY","pointerType","size","height","width","getThumbPercent","delta","step","setThumbValue","getThumbValue","setThumbPercent","onMoveEnd","setThumbEditable","focusableProps","onFocus","setFocusedThumb","onBlur","currentPointer","onDown","id","window","onUp","e","pointerId","changedTouches","identifier","inputProps","getThumbMinValue","getThumbMaxValue","getThumbValueLabel","parseFloat","target","thumbProps","onMouseDown","button","altKey","ctrlKey","metaKey","onPointerDown","onTouchStart"],"mappings":";;;;;;;AACA;;AAMA;;AACA;;AAWA;;AACA;;AACA;;AACA;;AAoBA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,cAAT,CACLC,IADK,EAELC,KAFK,EAGY;AAAA;;AACjB,MAAI;AACFC,IAAAA,KADE;AAEFC,IAAAA,UAFE;AAGFC,IAAAA,UAHE;AAIFC,IAAAA,eAJE;AAKFC,IAAAA,WALE;AAMFC,IAAAA;AANE,MAOAP,IAPJ;AASA,MAAIQ,UAAU,GAAGR,IAAI,CAACS,WAAL,KAAqB,UAAtC;AAEA,MAAIC,SAAS,GAAG,uBAAU,KAAV,GAAkBC,SAAlC;AACA,MAAI;AAAEC,IAAAA,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AA0D;AACxD;AACD;;AACDnB,QAAAA,MAAM;AACP,OANmB;AAOpBoB,MAAAA,aAAa,EAAGhB,CAAD,IAAwC;AACrD,YAAIA,CAAC,CAACY,MAAF,KAAa,CAAb,IAAkBZ,CAAC,CAACa,MAApB,IAA8Bb,CAAC,CAACc,OAAhC,IAA2Cd,CAAC,CAACe,OAAjD,EAA0D;AACxD;AACD;;AACDnB,QAAAA,MAAM,CAACI,CAAC,CAACC,SAAH,CAAN;AACD,OAZmB;AAapBgB,MAAAA,YAAY,EAAGjB,CAAD,IAAsC;AAClDJ,QAAAA,MAAM,CAACI,CAAC,CAACE,cAAF,CAAiB,CAAjB,EAAoBC,UAArB,CAAN;AACD;AAfmB,KAAtB,CADQ,GAkBR,EApCC;AAqCL1C,IAAAA;AArCK,GAAP;AAuCD","sourcesContent":["import { AriaSliderThumbProps } from '@react-types/slider';\nimport {\n clamp,\n focusWithoutScrolling,\n mergeProps,\n useGlobalListeners,\n} from '@react-aria/utils';\nimport { getSliderThumbId, sliderIds } from './utils';\nimport React, {\n ChangeEvent,\n HTMLAttributes,\n InputHTMLAttributes,\n LabelHTMLAttributes,\n RefObject,\n useCallback,\n useEffect,\n useRef,\n} from 'react';\nimport { SliderState } from '@react-stately/slider';\nimport { useFocusable } from '@react-aria/focus';\nimport { useLabel } from '@react-aria/label';\nimport { useMove } from './useMove';\nimport { isRTL } from '@react-native-aria/utils';\n\ninterface SliderThumbAria {\n /** Props for the root thumb element; handles the dragging motion. */\n thumbProps: HTMLAttributes<HTMLElement>;\n\n /** Props for the visually hidden range input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>;\n\n /** Props for the label element for this thumb (optional). */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>;\n}\n\ninterface SliderThumbOptions extends AriaSliderThumbProps {\n /** A ref to the track element. */\n trackLayout: any;\n /** A ref to the thumb input element. */\n inputRef: RefObject<HTMLInputElement>;\n}\n\n/**\n * Provides behavior and accessibility for a thumb of a slider component.\n *\n * @param opts Options for this Slider thumb.\n * @param state Slider state, created via `useSliderState`.\n */\nexport function useSliderThumb(\n opts: SliderThumbOptions,\n state: SliderState\n): SliderThumbAria {\n let {\n index,\n isRequired,\n isDisabled,\n validationState,\n trackLayout,\n inputRef,\n } = opts;\n\n let isVertical = opts.orientation === 'vertical';\n\n let direction = isRTL() ? 'rtl' : undefined;\n let { addGlobalListener, removeGlobalListener } = useGlobalListeners();\n\n let labelId = sliderIds.get(state);\n const { labelProps, fieldProps } = useLabel({\n ...opts,\n 'id': getSliderThumbId(state, index),\n 'aria-labelledby': `${labelId} ${opts['aria-labelledby'] ?? ''}`.trim(),\n });\n\n const value = state.values[index];\n\n const focusInput = useCallback(() => {\n if (inputRef.current) {\n focusWithoutScrolling(inputRef.current);\n }\n }, [inputRef]);\n\n const isFocused = state.focusedThumb === index;\n\n useEffect(() => {\n if (isFocused) {\n focusInput();\n }\n }, [isFocused, focusInput]);\n\n const stateRef = useRef<SliderState>(null);\n stateRef.current = state;\n let reverseX = direction === 'rtl';\n let currentPosition = useRef<number>(null);\n let { moveProps } = useMove({\n onMoveStart() {\n currentPosition.current = null;\n state.setThumbDragging(index, true);\n },\n onMove({ deltaX, deltaY, pointerType }) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n\n if (currentPosition.current == null) {\n currentPosition.current =\n stateRef.current.getThumbPercent(index) * size;\n }\n if (pointerType === 'keyboard') {\n // (invert left/right according to language direction) + (according to vertical)\n let delta =\n ((reverseX ? -deltaX : deltaX) + (isVertical ? -deltaY : -deltaY)) *\n stateRef.current.step;\n currentPosition.current += delta * size;\n stateRef.current.setThumbValue(\n index,\n stateRef.current.getThumbValue(index) + delta\n );\n } else {\n let delta = isVertical ? deltaY : deltaX;\n if (isVertical || reverseX) {\n delta = -delta;\n }\n currentPosition.current += delta;\n stateRef.current.setThumbPercent(\n index,\n clamp(currentPosition.current / size, 0, 1)\n );\n }\n },\n onMoveEnd() {\n state.setThumbDragging(index, false);\n },\n });\n\n // Immediately register editability with the state\n state.setThumbEditable(index, !isDisabled);\n\n const { focusableProps } = useFocusable(\n mergeProps(opts, {\n onFocus: () => state.setFocusedThumb(index),\n onBlur: () => state.setFocusedThumb(undefined),\n }),\n inputRef\n );\n\n let currentPointer = useRef<number | undefined>(undefined);\n let onDown = (id?: number) => {\n focusInput();\n currentPointer.current = id;\n state.setThumbDragging(index, true);\n\n addGlobalListener(window, 'mouseup', onUp, false);\n addGlobalListener(window, 'touchend', onUp, false);\n addGlobalListener(window, 'pointerup', onUp, false);\n };\n\n let onUp = (e) => {\n let id = e.pointerId ?? e.changedTouches?.[0].identifier;\n if (id === currentPointer.current) {\n focusInput();\n state.setThumbDragging(index, false);\n removeGlobalListener(window, 'mouseup', onUp, false);\n removeGlobalListener(window, 'touchend', onUp, false);\n removeGlobalListener(window, 'pointerup', onUp, false);\n }\n };\n\n // We install mouse handlers for the drag motion on the thumb div, but\n // not the key handler for moving the thumb with the slider. Instead,\n // we focus the range input, and let the browser handle the keyboard\n // interactions; we then listen to input's onChange to update state.\n return {\n inputProps: mergeProps(focusableProps, fieldProps, {\n 'type': 'range',\n 'tabIndex': !isDisabled ? 0 : undefined,\n 'min': state.getThumbMinValue(index),\n 'max': state.getThumbMaxValue(index),\n 'step': state.step,\n 'value': value,\n 'disabled': isDisabled,\n 'aria-orientation': opts.orientation,\n 'aria-valuetext': state.getThumbValueLabel(index),\n 'aria-required': isRequired || undefined,\n 'aria-invalid': validationState === 'invalid' || undefined,\n 'aria-errormessage': opts['aria-errormessage'],\n 'onChange': (e: ChangeEvent<HTMLInputElement>) => {\n state.setThumbValue(index, parseFloat(e.target.value));\n },\n }),\n thumbProps: !isDisabled\n ? mergeProps(moveProps, {\n onMouseDown: (e: React.MouseEvent<HTMLElement>) => {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onDown();\n },\n onPointerDown: (e: React.PointerEvent<HTMLElement>) => {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onDown(e.pointerId);\n },\n onTouchStart: (e: React.TouchEvent<HTMLElement>) => {\n onDown(e.changedTouches[0].identifier);\n },\n })\n : {},\n labelProps,\n };\n}\n"]}
1
+ {"version":3,"sources":["useSliderThumb.web.ts"],"names":["useSliderThumb","opts","state","isReversed","index","isRequired","isDisabled","validationState","trackLayout","inputRef","isVertical","orientation","direction","undefined","addGlobalListener","removeGlobalListener","labelId","sliderIds","get","labelProps","fieldProps","trim","value","values","focusInput","current","isFocused","focusedThumb","stateRef","reverseX","currentPosition","moveProps","onMoveStart","setThumbDragging","onMove","deltaX","deltaY","pointerType","size","height","width","getThumbPercent","delta","step","setThumbValue","getThumbValue","setThumbPercent","onMoveEnd","setThumbEditable","focusableProps","onFocus","setFocusedThumb","onBlur","currentPointer","onDown","id","window","onUp","e","pointerId","changedTouches","identifier","inputProps","getThumbMinValue","getThumbMaxValue","getThumbValueLabel","parseFloat","target","thumbProps","onMouseDown","button","altKey","ctrlKey","metaKey","onPointerDown","onTouchStart"],"mappings":";;;;;;;AACA;;AAMA;;AACA;;AAWA;;AACA;;AACA;;AACA;;AAoBA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,cAAT,CACLC,IADK,EAELC,KAFK,EAGLC,UAHK,EAIY;AAAA;;AACjB,MAAI;AACFC,IAAAA,KADE;AAEFC,IAAAA,UAFE;AAGFC,IAAAA,UAHE;AAIFC,IAAAA,eAJE;AAKFC,IAAAA,WALE;AAMFC,IAAAA;AANE,MAOAR,IAPJ;AASA,MAAIS,UAAU,GAAGT,IAAI,CAACU,WAAL,KAAqB,UAAtC;AAEA,MAAIC,SAAS,GAAG,uBAAU,KAAV,GAAkBC,SAAlC;AACA,MAAI;AAAEC,IAAAA,iBAAF;AAAqBC,IAAAA;AAArB,MAA8C,gCAAlD;;AAEA,MAAIC,OAAO,GAAGC,kBAAUC,GAAV,CAAchB,KAAd,CAAd;;AACA,QAAM;AAAEiB,IAAAA,UAAF;AAAcC,IAAAA;AAAd,MAA6B,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pBoB,MAAAA,aAAa,EAAGhB,CAAD,IAAwC;AACrD,YAAIA,CAAC,CAACY,MAAF,KAAa,CAAb,IAAkBZ,CAAC,CAACa,MAApB,IAA8Bb,CAAC,CAACc,OAAhC,IAA2Cd,CAAC,CAACe,OAAjD,EAA0D;AACxD;AACD;;AACDnB,QAAAA,MAAM,CAACI,CAAC,CAACC,SAAH,CAAN;AACD,OAZmB;AAapBgB,MAAAA,YAAY,EAAGjB,CAAD,IAAsC;AAClDJ,QAAAA,MAAM,CAACI,CAAC,CAACE,cAAF,CAAiB,CAAjB,EAAoBC,UAArB,CAAN;AACD;AAfmB,KAAtB,CADQ,GAkBR,EApCC;AAqCL1C,IAAAA;AArCK,GAAP;AAuCD","sourcesContent":["import { AriaSliderThumbProps } from '@react-types/slider';\nimport {\n clamp,\n focusWithoutScrolling,\n mergeProps,\n useGlobalListeners,\n} from '@react-aria/utils';\nimport { getSliderThumbId, sliderIds } from './utils';\nimport React, {\n ChangeEvent,\n HTMLAttributes,\n InputHTMLAttributes,\n LabelHTMLAttributes,\n RefObject,\n useCallback,\n useEffect,\n useRef,\n} from 'react';\nimport { SliderState } from '@react-stately/slider';\nimport { useFocusable } from '@react-aria/focus';\nimport { useLabel } from '@react-aria/label';\nimport { useMove } from './useMove';\nimport { isRTL } from '@react-native-aria/utils';\n\ninterface SliderThumbAria {\n /** Props for the root thumb element; handles the dragging motion. */\n thumbProps: HTMLAttributes<HTMLElement>;\n\n /** Props for the visually hidden range input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>;\n\n /** Props for the label element for this thumb (optional). */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>;\n}\n\ninterface SliderThumbOptions extends AriaSliderThumbProps {\n /** A ref to the track element. */\n trackLayout: any;\n /** A ref to the thumb input element. */\n inputRef: RefObject<HTMLInputElement>;\n}\n\n/**\n * Provides behavior and accessibility for a thumb of a slider component.\n *\n * @param opts Options for this Slider thumb.\n * @param state Slider state, created via `useSliderState`.\n */\nexport function useSliderThumb(\n opts: SliderThumbOptions,\n state: SliderState,\n isReversed?: boolean\n): SliderThumbAria {\n let {\n index,\n isRequired,\n isDisabled,\n validationState,\n trackLayout,\n inputRef,\n } = opts;\n\n let isVertical = opts.orientation === 'vertical';\n\n let direction = isRTL() ? 'rtl' : undefined;\n let { addGlobalListener, removeGlobalListener } = useGlobalListeners();\n\n let labelId = sliderIds.get(state);\n const { labelProps, fieldProps } = useLabel({\n ...opts,\n 'id': getSliderThumbId(state, index),\n 'aria-labelledby': `${labelId} ${opts['aria-labelledby'] ?? ''}`.trim(),\n });\n\n const value = state.values[index];\n\n const focusInput = useCallback(() => {\n if (inputRef.current) {\n focusWithoutScrolling(inputRef.current);\n }\n }, [inputRef]);\n\n const isFocused = state.focusedThumb === index;\n\n useEffect(() => {\n if (isFocused) {\n focusInput();\n }\n }, [isFocused, focusInput]);\n\n const stateRef = useRef<SliderState>(null);\n stateRef.current = state;\n let reverseX = isReversed || direction === 'rtl';\n let currentPosition = useRef<number>(null);\n let { moveProps } = useMove({\n onMoveStart() {\n currentPosition.current = null;\n state.setThumbDragging(index, true);\n },\n onMove({ deltaX, deltaY, pointerType }) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n\n if (currentPosition.current == null) {\n currentPosition.current =\n stateRef.current.getThumbPercent(index) * size;\n }\n if (pointerType === 'keyboard') {\n // (invert left/right according to language direction) + (according to vertical)\n let delta =\n ((reverseX ? -deltaX : deltaX) + (reverseX ? deltaY : -deltaY)) *\n stateRef.current.step;\n currentPosition.current += delta * size;\n stateRef.current.setThumbValue(\n index,\n stateRef.current.getThumbValue(index) + delta\n );\n } else {\n let delta = isVertical ? deltaY : deltaX;\n if (reverseX) {\n if (!isVertical) {\n delta = -delta;\n }\n } else {\n if (isVertical) {\n delta = -delta;\n }\n }\n currentPosition.current += delta;\n stateRef.current.setThumbPercent(\n index,\n clamp(currentPosition.current / size, 0, 1)\n );\n }\n },\n onMoveEnd() {\n state.setThumbDragging(index, false);\n },\n });\n\n // Immediately register editability with the state\n state.setThumbEditable(index, !isDisabled);\n\n const { focusableProps } = useFocusable(\n mergeProps(opts, {\n onFocus: () => state.setFocusedThumb(index),\n onBlur: () => state.setFocusedThumb(undefined),\n }),\n inputRef\n );\n\n let currentPointer = useRef<number | undefined>(undefined);\n let onDown = (id?: number) => {\n focusInput();\n currentPointer.current = id;\n state.setThumbDragging(index, true);\n\n addGlobalListener(window, 'mouseup', onUp, false);\n addGlobalListener(window, 'touchend', onUp, false);\n addGlobalListener(window, 'pointerup', onUp, false);\n };\n\n let onUp = (e) => {\n let id = e.pointerId ?? e.changedTouches?.[0].identifier;\n if (id === currentPointer.current) {\n focusInput();\n state.setThumbDragging(index, false);\n removeGlobalListener(window, 'mouseup', onUp, false);\n removeGlobalListener(window, 'touchend', onUp, false);\n removeGlobalListener(window, 'pointerup', onUp, false);\n }\n };\n\n // We install mouse handlers for the drag motion on the thumb div, but\n // not the key handler for moving the thumb with the slider. Instead,\n // we focus the range input, and let the browser handle the keyboard\n // interactions; we then listen to input's onChange to update state.\n return {\n inputProps: mergeProps(focusableProps, fieldProps, {\n 'type': 'range',\n 'tabIndex': !isDisabled ? 0 : undefined,\n 'min': state.getThumbMinValue(index),\n 'max': state.getThumbMaxValue(index),\n 'step': state.step,\n 'value': value,\n 'disabled': isDisabled,\n 'aria-orientation': opts.orientation,\n 'aria-valuetext': state.getThumbValueLabel(index),\n 'aria-required': isRequired || undefined,\n 'aria-invalid': validationState === 'invalid' || undefined,\n 'aria-errormessage': opts['aria-errormessage'],\n 'onChange': (e: ChangeEvent<HTMLInputElement>) => {\n state.setThumbValue(index, parseFloat(e.target.value));\n },\n }),\n thumbProps: !isDisabled\n ? mergeProps(moveProps, {\n onMouseDown: (e: React.MouseEvent<HTMLElement>) => {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onDown();\n },\n onPointerDown: (e: React.PointerEvent<HTMLElement>) => {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onDown(e.pointerId);\n },\n onTouchStart: (e: React.TouchEvent<HTMLElement>) => {\n onDown(e.changedTouches[0].identifier);\n },\n })\n : {},\n labelProps,\n };\n}\n"]}
@@ -13,7 +13,7 @@ import { isRTL } from '@react-native-aria/utils';
13
13
  * accepts click and drag motions, so that the closest thumb will follow clicks and drags on
14
14
  * the track.
15
15
  */
16
- export function useSlider(props, state, trackLayout) {
16
+ export function useSlider(props, state, trackLayout, isReversed) {
17
17
  var _labelProps$id;
18
18
 
19
19
  let {
@@ -26,6 +26,7 @@ export function useSlider(props, state, trackLayout) {
26
26
 
27
27
  let onDownTrack = (e, id, clientX, clientY) => {
28
28
  const direction = isRTL() ? 'rtl' : undefined;
29
+ const reverseX = isReversed || direction === 'rtl';
29
30
 
30
31
  if (!props.isDisabled && state.values.every((_, i) => !state.isThumbDragging(i))) {
31
32
  let size = isVertical ? trackLayout.height : trackLayout.width; // Find the closest thumb
@@ -35,8 +36,14 @@ export function useSlider(props, state, trackLayout) {
35
36
  const offset = clickPosition - trackPosition;
36
37
  let percent = offset / size;
37
38
 
38
- if (direction === 'rtl' || isVertical) {
39
- percent = 1 - percent;
39
+ if (reverseX) {
40
+ if (!isVertical) {
41
+ percent = 1 - percent;
42
+ }
43
+ } else {
44
+ if (isVertical) {
45
+ percent = 1 - percent;
46
+ }
40
47
  }
41
48
 
42
49
  let value = state.getPercentValue(percent); // to find the closet thumb we split the array based on the first thumb position to the "right/end" of the click.
@@ -1 +1 @@
1
- {"version":3,"sources":["useSlider.ts"],"names":["sliderIds","useRef","useLabel","isRTL","useSlider","props","state","trackLayout","labelProps","fieldProps","isVertical","orientation","set","id","currentPointer","undefined","onDownTrack","e","clientX","clientY","direction","isDisabled","values","every","_","i","isThumbDragging","size","height","width","trackPosition","clickPosition","offset","percent","value","getPercentValue","closestThumb","split","findIndex","v","length","lastLeft","firstRight","Math","abs","isThumbEditable","preventDefault","setFocusedThumb","current","setThumbDragging","setThumbValue","groupProps","trackProps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,CAAC2C,gBAAN,CAAuBb,YAAvB,EAAqC,IAArC;AACA9B,QAAAA,KAAK,CAAC4C,aAAN,CAAoBd,YAApB,EAAkCF,KAAlC;AACA5B,QAAAA,KAAK,CAAC2C,gBAAN,CAAuBb,YAAvB,EAAqC,KAArC;AACD;AACF;AACF,GAnDD;;AAqDA,SAAO;AACL5B,IAAAA,UADK;AAEL2C,IAAAA,UAAU,EAAE,EAFP;AAGLC,IAAAA,UAAU,EAAE;AACVC,MAAAA,OAAO,EAAGpC,CAAD,IAAY;AACnB,cAAM;AAAEqC,UAAAA,SAAF;AAAaC,UAAAA;AAAb,YAA2BtC,CAAC,CAACuC,WAAnC;AACAxC,QAAAA,WAAW,CAACC,CAAD,EAAIF,SAAJ,EAAeuC,SAAf,EAA0BC,SAA1B,CAAX;AACD;AAJS,KAHP;AASLE,IAAAA,WAAW,EAAE;AATR,GAAP;AAWD","sourcesContent":["import { sliderIds } from './utils';\nimport { AriaSliderProps } from '@react-types/slider';\nimport React, { useRef } from 'react';\nimport { SliderState } from '@react-stately/slider';\nimport { useLabel } from '@react-aria/label';\nimport { isRTL } from '@react-native-aria/utils';\n\ninterface SliderAria {\n /** Props for the label element. */\n labelProps: any;\n\n /** Props for the root element of the slider component; groups slider inputs. */\n groupProps: any;\n\n /** Props for the track element. */\n trackProps: any;\n\n /** Props for the output element, displaying the value of the slider thumbs. */\n outputProps: any;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a slider component representing one or more values.\n *\n * @param props Props for the slider.\n * @param state State for the slider, as returned by `useSliderState`.\n * @param trackRef Ref for the \"track\" element. The width of this element provides the \"length\"\n * of the track -- the span of one dimensional space that the slider thumb can be. It also\n * accepts click and drag motions, so that the closest thumb will follow clicks and drags on\n * the track.\n */\nexport function useSlider(\n props: AriaSliderProps,\n state: SliderState,\n trackLayout: any\n): SliderAria {\n let { labelProps, fieldProps } = useLabel(props);\n\n let isVertical = props.orientation === 'vertical';\n\n sliderIds.set(state, labelProps.id ?? fieldProps.id);\n let currentPointer = useRef<number | null | undefined>(undefined);\n\n let onDownTrack = (\n e: React.UIEvent,\n id: number,\n clientX: number,\n clientY: number\n ) => {\n const direction = isRTL() ? 'rtl' : undefined;\n if (\n !props.isDisabled &&\n state.values.every((_, i) => !state.isThumbDragging(i))\n ) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n // Find the closest thumb\n const trackPosition = trackLayout[isVertical ? 'y' : 'x'];\n const clickPosition = isVertical ? clientY : clientX;\n const offset = clickPosition - trackPosition;\n let percent = offset / size;\n if (direction === 'rtl' || isVertical) {\n percent = 1 - percent;\n }\n let value = state.getPercentValue(percent);\n // to find the closet thumb we split the array based on the first thumb position to the \"right/end\" of the click.\n let closestThumb;\n let split = state.values.findIndex((v) => value - v < 0);\n if (split === 0) {\n // If the index is zero then the closetThumb is the first one\n closestThumb = split;\n } else if (split === -1) {\n // If no index is found they've clicked past all the thumbs\n closestThumb = state.values.length - 1;\n } else {\n let lastLeft = state.values[split - 1];\n let firstRight = state.values[split];\n // Pick the last left/start thumb, unless they are stacked on top of each other, then pick the right/end one\n if (Math.abs(lastLeft - value) < Math.abs(firstRight - value)) {\n closestThumb = split - 1;\n } else {\n closestThumb = split;\n }\n }\n // Confirm that the found closest thumb is editable, not disabled, and move it\n if (closestThumb >= 0 && state.isThumbEditable(closestThumb)) {\n // Don't unfocus anything\n e.preventDefault();\n state.setFocusedThumb(closestThumb);\n currentPointer.current = id;\n state.setThumbDragging(closestThumb, true);\n state.setThumbValue(closestThumb, value);\n state.setThumbDragging(closestThumb, false);\n }\n }\n };\n\n return {\n labelProps,\n groupProps: {},\n trackProps: {\n onPress: (e: any) => {\n const { locationX, locationY } = e.nativeEvent;\n onDownTrack(e, undefined, locationX, locationY);\n },\n },\n outputProps: {},\n };\n}\n"]}
1
+ {"version":3,"sources":["useSlider.ts"],"names":["sliderIds","useRef","useLabel","isRTL","useSlider","props","state","trackLayout","isReversed","labelProps","fieldProps","isVertical","orientation","set","id","currentPointer","undefined","onDownTrack","e","clientX","clientY","direction","reverseX","isDisabled","values","every","_","i","isThumbDragging","size","height","width","trackPosition","clickPosition","offset","percent","value","getPercentValue","closestThumb","split","findIndex","v","length","lastLeft","firstRight","Math","abs","isThumbEditable","preventDefault","setFocusedThumb","current","setThumbDragging","setThumbValue","groupProps","trackProps","onPress","locationX","locationY","nativeEvent","outputProps"],"mappings":"AAAA,SAASA,SAAT,QAA0B,SAA1B;AAEA,SAAgBC,MAAhB,QAA8B,OAA9B;AAEA,SAASC,QAAT,QAAyB,mBAAzB;AACA,SAASC,KAAT,QAAsB,0BAAtB;;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,SAAT,CACLC,KADK,EAELC,KAFK,EAGLC,WAHK,EAILC,UAJK,EAKO;AAAA;;AACZ,MAAI;AAAEC,IAAAA,UAAF;AAAcC,IAAAA;AAAd,MAA6BR,QAAQ,CAACG,KAAD,CAAzC;AAEA,MAAIM,UAAU,GAAGN,KAAK,CAACO,WAAN,KAAsB,UAAvC;AAEAZ,EAAAA,SAAS,CAACa,GAAV,CAAcP,KAAd,oBAAqBG,UAAU,CAACK,EAAhC,2DAAsCJ,UAAU,CAACI,EAAjD;AACA,MAAIC,cAAc,GAAGd,MAAM,CAA4Be,SAA5B,CAA3B;;AAEA,MAAIC,WAAW,GAAG,CAChBC,CADgB,EAEhBJ,EAFgB,EAGhBK,OAHgB,EAIhBC,OAJgB,KAKb;AACH,UAAMC,SAAS,GAAGlB,KAAK,KAAK,KAAL,GAAaa,SAApC;AACA,UAAMM,QAAQ,GAAGd,UAAU,IAAIa,SAAS,KAAK,KAA7C;;AACA,QACE,CAAChB,KAAK,CAACkB,UAAP,IACAjB,KAAK,CAACkB,MAAN,CAAaC,KAAb,CAAmB,CAACC,CAAD,EAAIC,CAAJ,KAAU,CAACrB,KAAK,CAACsB,eAAN,CAAsBD,CAAtB,CAA9B,CAFF,EAGE;AACA,UAAIE,IAAI,GAAGlB,UAAU,GA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,UAAAA,YAAY,GAAGC,KAAK,GAAG,CAAvB;AACD,SAFD,MAEO;AACLD,UAAAA,YAAY,GAAGC,KAAf;AACD;AACF,OAnCD,CAoCA;;;AACA,UAAID,YAAY,IAAI,CAAhB,IAAqBhC,KAAK,CAACyC,eAAN,CAAsBT,YAAtB,CAAzB,EAA8D;AAC5D;AACApB,QAAAA,CAAC,CAAC8B,cAAF;AACA1C,QAAAA,KAAK,CAAC2C,eAAN,CAAsBX,YAAtB;AACAvB,QAAAA,cAAc,CAACmC,OAAf,GAAyBpC,EAAzB;AACAR,QAAAA,KAAK,CAAC6C,gBAAN,CAAuBb,YAAvB,EAAqC,IAArC;AACAhC,QAAAA,KAAK,CAAC8C,aAAN,CAAoBd,YAApB,EAAkCF,KAAlC;AACA9B,QAAAA,KAAK,CAAC6C,gBAAN,CAAuBb,YAAvB,EAAqC,KAArC;AACD;AACF;AACF,GA1DD;;AA4DA,SAAO;AACL7B,IAAAA,UADK;AAEL4C,IAAAA,UAAU,EAAE,EAFP;AAGLC,IAAAA,UAAU,EAAE;AACVC,MAAAA,OAAO,EAAGrC,CAAD,IAAY;AACnB,cAAM;AAAEsC,UAAAA,SAAF;AAAaC,UAAAA;AAAb,YAA2BvC,CAAC,CAACwC,WAAnC;AACAzC,QAAAA,WAAW,CAACC,CAAD,EAAIF,SAAJ,EAAewC,SAAf,EAA0BC,SAA1B,CAAX;AACD;AAJS,KAHP;AASLE,IAAAA,WAAW,EAAE;AATR,GAAP;AAWD","sourcesContent":["import { sliderIds } from './utils';\nimport { AriaSliderProps } from '@react-types/slider';\nimport React, { useRef } from 'react';\nimport { SliderState } from '@react-stately/slider';\nimport { useLabel } from '@react-aria/label';\nimport { isRTL } from '@react-native-aria/utils';\n\ninterface SliderAria {\n /** Props for the label element. */\n labelProps: any;\n\n /** Props for the root element of the slider component; groups slider inputs. */\n groupProps: any;\n\n /** Props for the track element. */\n trackProps: any;\n\n /** Props for the output element, displaying the value of the slider thumbs. */\n outputProps: any;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a slider component representing one or more values.\n *\n * @param props Props for the slider.\n * @param state State for the slider, as returned by `useSliderState`.\n * @param trackRef Ref for the \"track\" element. The width of this element provides the \"length\"\n * of the track -- the span of one dimensional space that the slider thumb can be. It also\n * accepts click and drag motions, so that the closest thumb will follow clicks and drags on\n * the track.\n */\nexport function useSlider(\n props: AriaSliderProps,\n state: SliderState,\n trackLayout: any,\n isReversed?: boolean\n): SliderAria {\n let { labelProps, fieldProps } = useLabel(props);\n\n let isVertical = props.orientation === 'vertical';\n\n sliderIds.set(state, labelProps.id ?? fieldProps.id);\n let currentPointer = useRef<number | null | undefined>(undefined);\n\n let onDownTrack = (\n e: React.UIEvent,\n id: number,\n clientX: number,\n clientY: number\n ) => {\n const direction = isRTL() ? 'rtl' : undefined;\n const reverseX = isReversed || direction === 'rtl';\n if (\n !props.isDisabled &&\n state.values.every((_, i) => !state.isThumbDragging(i))\n ) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n // Find the closest thumb\n const trackPosition = trackLayout[isVertical ? 'y' : 'x'];\n const clickPosition = isVertical ? clientY : clientX;\n const offset = clickPosition - trackPosition;\n let percent = offset / size;\n if (reverseX) {\n if (!isVertical) {\n percent = 1 - percent;\n }\n } else {\n if (isVertical) {\n percent = 1 - percent;\n }\n }\n let value = state.getPercentValue(percent);\n // to find the closet thumb we split the array based on the first thumb position to the \"right/end\" of the click.\n let closestThumb;\n let split = state.values.findIndex((v) => value - v < 0);\n if (split === 0) {\n // If the index is zero then the closetThumb is the first one\n closestThumb = split;\n } else if (split === -1) {\n // If no index is found they've clicked past all the thumbs\n closestThumb = state.values.length - 1;\n } else {\n let lastLeft = state.values[split - 1];\n let firstRight = state.values[split];\n // Pick the last left/start thumb, unless they are stacked on top of each other, then pick the right/end one\n if (Math.abs(lastLeft - value) < Math.abs(firstRight - value)) {\n closestThumb = split - 1;\n } else {\n closestThumb = split;\n }\n }\n // Confirm that the found closest thumb is editable, not disabled, and move it\n if (closestThumb >= 0 && state.isThumbEditable(closestThumb)) {\n // Don't unfocus anything\n e.preventDefault();\n state.setFocusedThumb(closestThumb);\n currentPointer.current = id;\n state.setThumbDragging(closestThumb, true);\n state.setThumbValue(closestThumb, value);\n state.setThumbDragging(closestThumb, false);\n }\n }\n };\n\n return {\n labelProps,\n groupProps: {},\n trackProps: {\n onPress: (e: any) => {\n const { locationX, locationY } = e.nativeEvent;\n onDownTrack(e, undefined, locationX, locationY);\n },\n },\n outputProps: {},\n };\n}\n"]}
@@ -6,7 +6,7 @@ import { useLabel } from '@react-aria/label';
6
6
  import { mapDomPropsToRN, isRTL } from '@react-native-aria/utils';
7
7
  import { useMove } from './useMove';
8
8
 
9
- function useSliderWeb(props, state, trackLayout) {
9
+ function useSliderWeb(props, state, trackLayout, isReversed) {
10
10
  var _labelProps$id;
11
11
 
12
12
  let {
@@ -28,7 +28,7 @@ function useSliderWeb(props, state, trackLayout) {
28
28
  const realTimeTrackDraggingIndex = useRef(null);
29
29
  const stateRef = useRef(null);
30
30
  stateRef.current = state;
31
- const reverseX = direction === 'rtl';
31
+ const reverseX = isReversed || direction === 'rtl';
32
32
  const currentPosition = useRef(null);
33
33
  const {
34
34
  moveProps
@@ -49,8 +49,14 @@ function useSliderWeb(props, state, trackLayout) {
49
49
 
50
50
  let delta = isVertical ? deltaY : deltaX;
51
51
 
52
- if (isVertical || reverseX) {
53
- delta = -delta;
52
+ if (reverseX) {
53
+ if (!isVertical) {
54
+ delta = -delta;
55
+ }
56
+ } else {
57
+ if (isVertical) {
58
+ delta = -delta;
59
+ }
54
60
  }
55
61
 
56
62
  currentPosition.current += delta;
@@ -81,8 +87,14 @@ function useSliderWeb(props, state, trackLayout) {
81
87
  const offset = clickPosition - trackPosition;
82
88
  let percent = offset / size;
83
89
 
84
- if (direction === 'rtl' || isVertical) {
85
- percent = 1 - percent;
90
+ if (reverseX) {
91
+ if (!isVertical) {
92
+ percent = 1 - percent;
93
+ }
94
+ } else {
95
+ if (isVertical) {
96
+ percent = 1 - percent;
97
+ }
86
98
  }
87
99
 
88
100
  let value = state.getPercentValue(percent); // to find the closet thumb we split the array based on the first thumb position to the "right/end" of the click.
@@ -197,11 +209,11 @@ function useSliderWeb(props, state, trackLayout) {
197
209
  };
198
210
  }
199
211
 
200
- export const useSlider = (props, state, ref) => {
212
+ export const useSlider = (props, state, ref, isReversed) => {
201
213
  let {
202
214
  groupProps: webGroupProps,
203
215
  ...rest
204
- } = useSliderWeb(props, state, ref);
216
+ } = useSliderWeb(props, state, ref, isReversed);
205
217
  let groupProps = mapDomPropsToRN(webGroupProps);
206
218
  let labelProps = mapDomPropsToRN(rest.labelProps);
207
219
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["useSlider.web.ts"],"names":["clamp","mergeProps","useGlobalListeners","getSliderThumbId","sliderIds","useRef","setInteractionModality","useLabel","mapDomPropsToRN","isRTL","useMove","useSliderWeb","props","state","trackLayout","labelProps","fieldProps","isVertical","orientation","set","id","direction","undefined","addGlobalListener","removeGlobalListener","realTimeTrackDraggingIndex","stateRef","current","reverseX","currentPosition","moveProps","onMoveStart","onMove","deltaX","deltaY","size","height","width","getThumbPercent","delta","percent","setThumbPercent","onMoveEnd","setThumbDragging","currentPointer","onDownTrack","e","clientX","clientY","isDisabled","values","every","_","i","isThumbDragging","trackPosition","clickPosition","offset","value","getPercentValue","closestThumb","split","findIndex","v","length","lastLeft","firstRight","Math","abs","isThumbEditable","preventDefault","setFocusedThumb","setThumbValue","window","onUpTrack","pointerId","changedTouches","identifier","htmlFor","onClick","document","getElementById","focus","groupProps","role","trackProps","onMouseDown","button","altKey","ctrlKey","metaKey","onPointerDown","pointerType","onTouchStart","outputProps","map","index","join","useSlider","ref","webGroupProps","rest"],"mappings":"AACA,SAASA,KAAT,EAAgBC,UAAhB,EAA4BC,kBAA5B,QAAsD,mBAAtD;AACA,SAASC,gBAAT,EAA2BC,SAA3B,QAA4C,SAA5C;AACA,SAAgBC,MAAhB,QAA8B,OAA9B;AACA,S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derProps } from '@react-types/slider';\nimport { clamp, mergeProps, useGlobalListeners } from '@react-aria/utils';\nimport { getSliderThumbId, sliderIds } from './utils';\nimport React, { useRef } from 'react';\nimport { setInteractionModality } from '@react-aria/interactions';\nimport { SliderState } from '@react-stately/slider';\nimport { useLabel } from '@react-aria/label';\nimport { mapDomPropsToRN, isRTL } from '@react-native-aria/utils';\nimport { useMove } from './useMove';\n\ninterface SliderAria {\n /** Props for the label element. */\n labelProps: any;\n\n /** Props for the root element of the slider component; groups slider inputs. */\n groupProps: any;\n\n /** Props for the track element. */\n trackProps: any;\n\n /** Props for the output element, displaying the value of the slider thumbs. */\n outputProps: any;\n}\n\nfunction useSliderWeb(\n props: AriaSliderProps,\n state: SliderState,\n trackLayout: {\n height: number;\n width: number;\n top: number;\n left: number;\n x: number;\n y: number;\n }\n): SliderAria {\n let { labelProps, fieldProps } = useLabel(props);\n\n let isVertical = props.orientation === 'vertical';\n\n // Attach id of the label to the state so it can be accessed by useSliderThumb.\n sliderIds.set(state, labelProps.id ?? fieldProps.id);\n\n const direction = isRTL() ? 'rtl' : undefined;\n\n let { addGlobalListener, removeGlobalListener } = useGlobalListeners();\n\n // When the user clicks or drags the track, we want the motion to set and drag the\n // closest thumb. Hence we also need to install useMove() on the track element.\n // Here, we keep track of which index is the \"closest\" to the drag start point.\n // It is set onMouseDown/onTouchDown; see trackProps below.\n const realTimeTrackDraggingIndex = useRef<number | null>(null);\n\n const stateRef = useRef<SliderState>(null);\n stateRef.current = state;\n const reverseX = direction === 'rtl';\n const currentPosition = useRef<number>(null);\n const { moveProps } = useMove({\n onMoveStart() {\n currentPosition.current = null;\n },\n onMove({ deltaX, deltaY }) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n\n if (currentPosition.current == null) {\n currentPosition.current =\n stateRef.current.getThumbPercent(realTimeTrackDraggingIndex.current) *\n size;\n }\n\n let delta = isVertical ? deltaY : deltaX;\n if (isVertical || reverseX) {\n delta = -delta;\n }\n\n currentPosition.current += delta;\n\n if (realTimeTrackDraggingIndex.current != null) {\n const percent = clamp(currentPosition.current / size, 0, 1);\n stateRef.current.setThumbPercent(\n realTimeTrackDraggingIndex.current,\n percent\n );\n }\n },\n onMoveEnd() {\n if (realTimeTrackDraggingIndex.current != null) {\n stateRef.current.setThumbDragging(\n realTimeTrackDraggingIndex.current,\n false\n );\n realTimeTrackDraggingIndex.current = null;\n }\n },\n });\n\n let currentPointer = useRef<number | null | undefined>(undefined);\n let onDownTrack = (\n e: React.UIEvent,\n id: number,\n clientX: number,\n clientY: number\n ) => {\n // We only trigger track-dragging if the user clicks on the track itself and nothing is currently being dragged.\n if (\n !props.isDisabled &&\n state.values.every((_, i) => !state.isThumbDragging(i))\n ) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n // Find the closest thumb\n const trackPosition = trackLayout[isVertical ? 'top' : 'left'];\n const clickPosition = isVertical ? clientY : clientX;\n const offset = clickPosition - trackPosition;\n let percent = offset / size;\n if (direction === 'rtl' || isVertical) {\n percent = 1 - percent;\n }\n let value = state.getPercentValue(percent);\n\n // to find the closet thumb we split the array based on the first thumb position to the \"right/end\" of the click.\n let closestThumb;\n let split = state.values.findIndex((v) => value - v < 0);\n if (split === 0) {\n // If the index is zero then the closetThumb is the first one\n closestThumb = split;\n } else if (split === -1) {\n // If no index is found they've clicked past all the thumbs\n closestThumb = state.values.length - 1;\n } else {\n let lastLeft = state.values[split - 1];\n let firstRight = state.values[split];\n // Pick the last left/start thumb, unless they are stacked on top of each other, then pick the right/end one\n if (Math.abs(lastLeft - value) < Math.abs(firstRight - value)) {\n closestThumb = split - 1;\n } else {\n closestThumb = split;\n }\n }\n\n // Confirm that the found closest thumb is editable, not disabled, and move it\n if (closestThumb >= 0 && state.isThumbEditable(closestThumb)) {\n // Don't unfocus anything\n e.preventDefault();\n\n realTimeTrackDraggingIndex.current = closestThumb;\n state.setFocusedThumb(closestThumb);\n currentPointer.current = id;\n\n state.setThumbDragging(realTimeTrackDraggingIndex.current, true);\n state.setThumbValue(closestThumb, value);\n\n addGlobalListener(window, 'mouseup', onUpTrack, false);\n addGlobalListener(window, 'touchend', onUpTrack, false);\n addGlobalListener(window, 'pointerup', onUpTrack, false);\n } else {\n realTimeTrackDraggingIndex.current = null;\n }\n }\n };\n\n let onUpTrack = (e) => {\n let id = e.pointerId ?? e.changedTouches?.[0].identifier;\n if (id === currentPointer.current) {\n if (realTimeTrackDraggingIndex.current != null) {\n state.setThumbDragging(realTimeTrackDraggingIndex.current, false);\n realTimeTrackDraggingIndex.current = null;\n }\n\n removeGlobalListener(window, 'mouseup', onUpTrack, false);\n removeGlobalListener(window, 'touchend', onUpTrack, false);\n removeGlobalListener(window, 'pointerup', onUpTrack, false);\n }\n };\n\n if (labelProps.htmlFor) {\n // Ideally the `for` attribute should point to the first thumb, but VoiceOver on iOS\n // causes this to override the `aria-labelledby` on the thumb. This causes the first\n // thumb to only be announced as the slider label rather than its individual name as well.\n // See https://bugs.webkit.org/show_bug.cgi?id=172464.\n delete labelProps.htmlFor;\n labelProps.onClick = () => {\n // Safari does not focus <input type=\"range\"> elements when clicking on an associated <label>,\n // so do it manually. In addition, make sure we show the focus ring.\n document.getElementById(getSliderThumbId(state, 0))?.focus();\n setInteractionModality('keyboard');\n };\n }\n\n return {\n labelProps,\n // The root element of the Slider will have role=\"group\" to group together\n // all the thumb inputs in the Slider. The label of the Slider will\n // be used to label the group.\n groupProps: {\n role: 'group',\n ...fieldProps,\n },\n trackProps: mergeProps(\n {\n onMouseDown(e: React.MouseEvent<HTMLElement>) {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onDownTrack(e, undefined, e.clientX, e.clientY);\n },\n onPointerDown(e: React.PointerEvent<HTMLElement>) {\n if (\n e.pointerType === 'mouse' &&\n (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)\n ) {\n return;\n }\n onDownTrack(e, e.pointerId, e.clientX, e.clientY);\n },\n onTouchStart(e: React.TouchEvent<HTMLElement>) {\n onDownTrack(\n e,\n e.changedTouches[0].identifier,\n e.changedTouches[0].clientX,\n e.changedTouches[0].clientY\n );\n },\n },\n moveProps\n ),\n outputProps: {\n 'htmlFor': state.values\n .map((_, index) => getSliderThumbId(state, index))\n .join(' '),\n 'aria-live': 'off',\n },\n };\n}\n\nexport const useSlider = (props: any, state: any, ref: any) => {\n let { groupProps: webGroupProps, ...rest } = useSliderWeb(props, state, ref);\n let groupProps = mapDomPropsToRN(webGroupProps);\n let labelProps = mapDomPropsToRN(rest.labelProps);\n return { groupProps, ...rest, labelProps };\n};\n"]}
1
+ {"version":3,"sources":["useSlider.web.ts"],"names":["clamp","mergeProps","useGlobalListeners","getSliderThumbId","sliderIds","useRef","setInteractionModality","useLabel","mapDomPropsToRN","isRTL","useMove","useSliderWeb","props","state","trackLayout","isReversed","labelProps","fieldProps","isVertical","orientation","set","id","direction","undefined","addGlobalListener","removeGlobalListener","realTimeTrackDraggingIndex","stateRef","current","reverseX","currentPosition","moveProps","onMoveStart","onMove","deltaX","deltaY","size","height","width","getThumbPercent","delta","percent","setThumbPercent","onMoveEnd","setThumbDragging","currentPointer","onDownTrack","e","clientX","clientY","isDisabled","values","every","_","i","isThumbDragging","trackPosition","clickPosition","offset","value","getPercentValue","closestThumb","split","findIndex","v","length","lastLeft","firstRight","Math","abs","isThumbEditable","preventDefault","setFocusedThumb","setThumbValue","window","onUpTrack","pointerId","changedTouches","identifier","htmlFor","onClick","document","getElementById","focus","groupProps","role","trackProps","onMouseDown","button","altKey","ctrlKey","metaKey","onPointerDown","pointerType","onTouchStart","outputProps","map","index","join","useSlider","ref","webGroupProps","rest"],"mappings":"AACA,SAASA,KAAT,EAAgBC,UAAhB,EAA4BC,kBAA5B,QAAsD,mBAAtD;AACA,SAASC,gBAAT,EAA2BC,SAA3B,QAA4C,SAA5C;AACA,SAAgBC,MAAhB,QAA8B,OAA9B;AACA,SAASC,sBAAT,QAAuC,0BAAvC;AAEA,SAASC,QAAT,QAAyB,mBAAzB;AACA,SAASC,eA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CAAC6F,aAAD,CAAhC;AACA,MAAIrF,UAAU,GAAGR,eAAe,CAAC8F,IAAI,CAACtF,UAAN,CAAhC;AACA,SAAO;AAAEoE,IAAAA,UAAF;AAAc,OAAGkB,IAAjB;AAAuBtF,IAAAA;AAAvB,GAAP;AACD,CAfM","sourcesContent":["import { AriaSliderProps } from '@react-types/slider';\nimport { clamp, mergeProps, useGlobalListeners } from '@react-aria/utils';\nimport { getSliderThumbId, sliderIds } from './utils';\nimport React, { useRef } from 'react';\nimport { setInteractionModality } from '@react-aria/interactions';\nimport { SliderState } from '@react-stately/slider';\nimport { useLabel } from '@react-aria/label';\nimport { mapDomPropsToRN, isRTL } from '@react-native-aria/utils';\nimport { useMove } from './useMove';\n\ninterface SliderAria {\n /** Props for the label element. */\n labelProps: any;\n\n /** Props for the root element of the slider component; groups slider inputs. */\n groupProps: any;\n\n /** Props for the track element. */\n trackProps: any;\n\n /** Props for the output element, displaying the value of the slider thumbs. */\n outputProps: any;\n}\n\nfunction useSliderWeb(\n props: AriaSliderProps,\n state: SliderState,\n trackLayout: {\n height: number;\n width: number;\n top: number;\n left: number;\n x: number;\n y: number;\n },\n isReversed?: boolean\n): SliderAria {\n let { labelProps, fieldProps } = useLabel(props);\n\n let isVertical = props.orientation === 'vertical';\n\n // Attach id of the label to the state so it can be accessed by useSliderThumb.\n sliderIds.set(state, labelProps.id ?? fieldProps.id);\n\n const direction = isRTL() ? 'rtl' : undefined;\n\n let { addGlobalListener, removeGlobalListener } = useGlobalListeners();\n\n // When the user clicks or drags the track, we want the motion to set and drag the\n // closest thumb. Hence we also need to install useMove() on the track element.\n // Here, we keep track of which index is the \"closest\" to the drag start point.\n // It is set onMouseDown/onTouchDown; see trackProps below.\n const realTimeTrackDraggingIndex = useRef<number | null>(null);\n\n const stateRef = useRef<SliderState>(null);\n stateRef.current = state;\n const reverseX = isReversed || direction === 'rtl';\n\n const currentPosition = useRef<number>(null);\n const { moveProps } = useMove({\n onMoveStart() {\n currentPosition.current = null;\n },\n onMove({ deltaX, deltaY }) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n\n if (currentPosition.current == null) {\n currentPosition.current =\n stateRef.current.getThumbPercent(realTimeTrackDraggingIndex.current) *\n size;\n }\n\n let delta = isVertical ? deltaY : deltaX;\n if (reverseX) {\n if (!isVertical) {\n delta = -delta;\n }\n } else {\n if (isVertical) {\n delta = -delta;\n }\n }\n\n currentPosition.current += delta;\n\n if (realTimeTrackDraggingIndex.current != null) {\n const percent = clamp(currentPosition.current / size, 0, 1);\n stateRef.current.setThumbPercent(\n realTimeTrackDraggingIndex.current,\n percent\n );\n }\n },\n onMoveEnd() {\n if (realTimeTrackDraggingIndex.current != null) {\n stateRef.current.setThumbDragging(\n realTimeTrackDraggingIndex.current,\n false\n );\n realTimeTrackDraggingIndex.current = null;\n }\n },\n });\n\n let currentPointer = useRef<number | null | undefined>(undefined);\n let onDownTrack = (\n e: React.UIEvent,\n id: number,\n clientX: number,\n clientY: number\n ) => {\n // We only trigger track-dragging if the user clicks on the track itself and nothing is currently being dragged.\n if (\n !props.isDisabled &&\n state.values.every((_, i) => !state.isThumbDragging(i))\n ) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n // Find the closest thumb\n const trackPosition = trackLayout[isVertical ? 'top' : 'left'];\n const clickPosition = isVertical ? clientY : clientX;\n const offset = clickPosition - trackPosition;\n let percent = offset / size;\n if (reverseX) {\n if (!isVertical) {\n percent = 1 - percent;\n }\n } else {\n if (isVertical) {\n percent = 1 - percent;\n }\n }\n let value = state.getPercentValue(percent);\n\n // to find the closet thumb we split the array based on the first thumb position to the \"right/end\" of the click.\n let closestThumb;\n let split = state.values.findIndex((v) => value - v < 0);\n if (split === 0) {\n // If the index is zero then the closetThumb is the first one\n closestThumb = split;\n } else if (split === -1) {\n // If no index is found they've clicked past all the thumbs\n closestThumb = state.values.length - 1;\n } else {\n let lastLeft = state.values[split - 1];\n let firstRight = state.values[split];\n // Pick the last left/start thumb, unless they are stacked on top of each other, then pick the right/end one\n if (Math.abs(lastLeft - value) < Math.abs(firstRight - value)) {\n closestThumb = split - 1;\n } else {\n closestThumb = split;\n }\n }\n\n // Confirm that the found closest thumb is editable, not disabled, and move it\n if (closestThumb >= 0 && state.isThumbEditable(closestThumb)) {\n // Don't unfocus anything\n e.preventDefault();\n\n realTimeTrackDraggingIndex.current = closestThumb;\n state.setFocusedThumb(closestThumb);\n currentPointer.current = id;\n\n state.setThumbDragging(realTimeTrackDraggingIndex.current, true);\n state.setThumbValue(closestThumb, value);\n\n addGlobalListener(window, 'mouseup', onUpTrack, false);\n addGlobalListener(window, 'touchend', onUpTrack, false);\n addGlobalListener(window, 'pointerup', onUpTrack, false);\n } else {\n realTimeTrackDraggingIndex.current = null;\n }\n }\n };\n\n let onUpTrack = (e) => {\n let id = e.pointerId ?? e.changedTouches?.[0].identifier;\n if (id === currentPointer.current) {\n if (realTimeTrackDraggingIndex.current != null) {\n state.setThumbDragging(realTimeTrackDraggingIndex.current, false);\n realTimeTrackDraggingIndex.current = null;\n }\n\n removeGlobalListener(window, 'mouseup', onUpTrack, false);\n removeGlobalListener(window, 'touchend', onUpTrack, false);\n removeGlobalListener(window, 'pointerup', onUpTrack, false);\n }\n };\n\n if (labelProps.htmlFor) {\n // Ideally the `for` attribute should point to the first thumb, but VoiceOver on iOS\n // causes this to override the `aria-labelledby` on the thumb. This causes the first\n // thumb to only be announced as the slider label rather than its individual name as well.\n // See https://bugs.webkit.org/show_bug.cgi?id=172464.\n delete labelProps.htmlFor;\n labelProps.onClick = () => {\n // Safari does not focus <input type=\"range\"> elements when clicking on an associated <label>,\n // so do it manually. In addition, make sure we show the focus ring.\n document.getElementById(getSliderThumbId(state, 0))?.focus();\n setInteractionModality('keyboard');\n };\n }\n\n return {\n labelProps,\n // The root element of the Slider will have role=\"group\" to group together\n // all the thumb inputs in the Slider. The label of the Slider will\n // be used to label the group.\n groupProps: {\n role: 'group',\n ...fieldProps,\n },\n trackProps: mergeProps(\n {\n onMouseDown(e: React.MouseEvent<HTMLElement>) {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onDownTrack(e, undefined, e.clientX, e.clientY);\n },\n onPointerDown(e: React.PointerEvent<HTMLElement>) {\n if (\n e.pointerType === 'mouse' &&\n (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)\n ) {\n return;\n }\n onDownTrack(e, e.pointerId, e.clientX, e.clientY);\n },\n onTouchStart(e: React.TouchEvent<HTMLElement>) {\n onDownTrack(\n e,\n e.changedTouches[0].identifier,\n e.changedTouches[0].clientX,\n e.changedTouches[0].clientY\n );\n },\n },\n moveProps\n ),\n outputProps: {\n 'htmlFor': state.values\n .map((_, index) => getSliderThumbId(state, index))\n .join(' '),\n 'aria-live': 'off',\n },\n };\n}\n\nexport const useSlider = (\n props: any,\n state: any,\n ref: any,\n isReversed?: boolean\n) => {\n let { groupProps: webGroupProps, ...rest } = useSliderWeb(\n props,\n state,\n ref,\n isReversed\n );\n let groupProps = mapDomPropsToRN(webGroupProps);\n let labelProps = mapDomPropsToRN(rest.labelProps);\n return { groupProps, ...rest, labelProps };\n};\n"]}
@@ -11,7 +11,7 @@ import { isRTL } from '@react-native-aria/utils';
11
11
  * @param opts Options for this Slider thumb.
12
12
  * @param state Slider state, created via `useSliderState`.
13
13
  */
14
- export function useSliderThumb(opts, state) {
14
+ export function useSliderThumb(opts, state, isReversed) {
15
15
  var _opts$ariaLabelledby;
16
16
 
17
17
  let {
@@ -31,7 +31,7 @@ export function useSliderThumb(opts, state) {
31
31
  });
32
32
  const stateRef = useRef(null);
33
33
  stateRef.current = state;
34
- let reverseX = direction === 'rtl';
34
+ let reverseX = isReversed || direction === 'rtl';
35
35
  let currentPosition = useRef(null);
36
36
  let {
37
37
  moveProps
@@ -53,8 +53,14 @@ export function useSliderThumb(opts, state) {
53
53
 
54
54
  let delta = isVertical ? deltaY : deltaX;
55
55
 
56
- if (isVertical || reverseX) {
57
- delta = -delta;
56
+ if (reverseX) {
57
+ if (!isVertical) {
58
+ delta = -delta;
59
+ }
60
+ } else {
61
+ if (isVertical) {
62
+ delta = -delta;
63
+ }
58
64
  }
59
65
 
60
66
  currentPosition.current += delta;
@@ -1 +1 @@
1
- {"version":3,"sources":["useSliderThumb.ts"],"names":["clamp","getSliderThumbId","sliderIds","useRef","useLabel","useMove","isRTL","useSliderThumb","opts","state","index","isDisabled","trackLayout","isVertical","orientation","direction","undefined","labelId","get","labelProps","fieldProps","trim","stateRef","current","reverseX","currentPosition","moveProps","onMoveStart","setThumbDragging","onMove","deltaX","deltaY","size","height","width","getThumbPercent","delta","setThumbPercent","onMoveEnd","setThumbEditable","onAccessibilityAction","event","max","getThumbMinValue","min","getThumbMaxValue","value","getThumbValue","incrementValue","Math","step","decrementValue","nativeEvent","actionName","setThumbValue","inputProps","disabled","accessibilityRole","accessibilityValue","now","accessibilityActions","name","label","thumbProps"],"mappings":"AACA,SAASA,KAAT,QAAsB,mBAAtB;AACA,SAASC,gBAAT,EAA2BC,SAA3B,QAA4C,SAA5C;AACA,SAASC,MAAT,QAAuB,OAAvB;AAEA,SAASC,QAAT,QAAyB,mBAAzB;AACA,SAASC,OAAT,QAAwB,WAAxB;AACA,SAASC,KAAT,QAAsB,0BAAtB;;AAoBA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAT,CACLC,IADK,EAELC,KAFK,EAGY;AAAA;;AACjB,MAAI;AAAEC,IAAAA,KAAF;AAASC,IAAAA,UAAT;AAAqBC,IAAAA;AAArB,MAAqCJ,IAAzC;AAEA,MAAIK,UAAU,GAAGL,IAAI,CAACM,WAAL,KAAqB,UAAtC;AACA,QAAMC,SAAS,GAAGT,KAAK,KAAK,KAAL,GAAaU,SAApC;AAEA,MAAIC,OAAO,GAAGf,SAAS,CAACgB,GAAV,CAAcT,KAAd,CAAd;AACA,QAAM;AAAEU,IAAAA,UAAF;AAAcC,IAAAA;AAAd,MAA6BhB,QAAQ,CAAC,EAC1C,GAAGI,IADuC;AAE1C,UAA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AAuBjC,KAAvB,CADa;AAElBgC,QAAAA,GAAG,EAAEjC,KAAK,CAACoC,gBAAN,CAAuBnC,KAAvB,CAFa;AAGlBiD,QAAAA,GAAG,EAAElD,KAAK,CAACsC,aAAN,CAAoBrC,KAApB;AAHa,OAJV;AASVkD,MAAAA,oBAAoB,EAAE,CACpB;AACEC,QAAAA,IAAI,EAAE,WADR;AAEEC,QAAAA,KAAK,EAAE;AAFT,OADoB,EAKpB;AACED,QAAAA,IAAI,EAAE,WADR;AAEEC,QAAAA,KAAK,EAAE;AAFT,OALoB,CATZ;AAmBVtB,MAAAA;AAnBU,KADP;AAsBLuB,IAAAA,UAAU,EAAE,CAACpD,UAAD,GAAce,SAAd,GAA0B,EAtBjC;AAuBLP,IAAAA;AAvBK,GAAP;AAyBD","sourcesContent":["import { AriaSliderThumbProps } from '@react-types/slider';\nimport { clamp } from '@react-aria/utils';\nimport { getSliderThumbId, sliderIds } from './utils';\nimport { useRef } from 'react';\nimport { SliderState } from '@react-stately/slider';\nimport { useLabel } from '@react-aria/label';\nimport { useMove } from './useMove';\nimport { isRTL } from '@react-native-aria/utils';\n\ninterface SliderThumbAria {\n /** Props for the root thumb element; handles the dragging motion. */\n thumbProps: any;\n\n /** Props for the visually hidden range input element. */\n inputProps: any;\n\n /** Props for the label element for this thumb (optional). */\n labelProps: any;\n}\n\ninterface SliderThumbOptions extends AriaSliderThumbProps {\n /** A ref to the track element. */\n trackLayout: any;\n /** A ref to the thumb input element. */\n inputRef: any;\n}\n\n/**\n * Provides behavior and accessibility for a thumb of a slider component.\n *\n * @param opts Options for this Slider thumb.\n * @param state Slider state, created via `useSliderState`.\n */\nexport function useSliderThumb(\n opts: SliderThumbOptions,\n state: SliderState\n): SliderThumbAria {\n let { index, isDisabled, trackLayout } = opts;\n\n let isVertical = opts.orientation === 'vertical';\n const direction = isRTL() ? 'rtl' : undefined;\n\n let labelId = sliderIds.get(state);\n const { labelProps, fieldProps } = useLabel({\n ...opts,\n 'id': getSliderThumbId(state, index),\n 'aria-labelledby': `${labelId} ${opts['aria-labelledby'] ?? ''}`.trim(),\n });\n\n const stateRef = useRef<SliderState>(null);\n stateRef.current = state;\n let reverseX = direction === 'rtl';\n let currentPosition = useRef<number>(null);\n let { moveProps } = useMove({\n onMoveStart() {\n currentPosition.current = null;\n state.setThumbDragging(index, true);\n },\n onMove({ deltaX, deltaY }) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n\n if (currentPosition.current == null) {\n currentPosition.current =\n stateRef.current.getThumbPercent(index) * size;\n }\n\n let delta = isVertical ? deltaY : deltaX;\n if (isVertical || reverseX) {\n delta = -delta;\n }\n currentPosition.current += delta;\n stateRef.current.setThumbPercent(\n index,\n clamp(currentPosition.current / size, 0, 1)\n );\n },\n onMoveEnd() {\n state.setThumbDragging(index, false);\n },\n });\n\n state.setThumbEditable(index, !isDisabled);\n\n const onAccessibilityAction = (event: any) => {\n const max = state.getThumbMinValue(index);\n const min = state.getThumbMaxValue(index);\n const value = state.getThumbValue(index);\n\n const incrementValue = Math.min(value + state.step ?? 1, max);\n const decrementValue = Math.max(value - state.step ?? 1, min);\n\n switch (event.nativeEvent.actionName) {\n case 'increment':\n state.setThumbValue(index, incrementValue);\n break;\n case 'decrement':\n state.setThumbValue(index, decrementValue);\n break;\n default:\n break;\n }\n };\n\n return {\n inputProps: {\n ...fieldProps,\n disabled: isDisabled,\n accessibilityRole: 'adjustable',\n accessibilityValue: {\n min: state.getThumbMinValue(index),\n max: state.getThumbMaxValue(index),\n now: state.getThumbValue(index),\n },\n accessibilityActions: [\n {\n name: 'increment',\n label: 'Increment',\n },\n {\n name: 'decrement',\n label: 'Decrement',\n },\n ],\n onAccessibilityAction,\n },\n thumbProps: !isDisabled ? moveProps : {},\n labelProps,\n };\n}\n"]}
1
+ {"version":3,"sources":["useSliderThumb.ts"],"names":["clamp","getSliderThumbId","sliderIds","useRef","useLabel","useMove","isRTL","useSliderThumb","opts","state","isReversed","index","isDisabled","trackLayout","isVertical","orientation","direction","undefined","labelId","get","labelProps","fieldProps","trim","stateRef","current","reverseX","currentPosition","moveProps","onMoveStart","setThumbDragging","onMove","deltaX","deltaY","size","height","width","getThumbPercent","delta","setThumbPercent","onMoveEnd","setThumbEditable","onAccessibilityAction","event","max","getThumbMinValue","min","getThumbMaxValue","value","getThumbValue","incrementValue","Math","step","decrementValue","nativeEvent","actionName","setThumbValue","inputProps","disabled","accessibilityRole","accessibilityValue","now","accessibilityActions","name","label","thumbProps"],"mappings":"AACA,SAASA,KAAT,QAAsB,mBAAtB;AACA,SAASC,gBAAT,EAA2BC,SAA3B,QAA4C,SAA5C;AACA,SAASC,MAAT,QAAuB,OAAvB;AAEA,SAASC,QAAT,QAAyB,mBAAzB;AACA,SAASC,OAAT,QAAwB,WAAxB;AACA,SAASC,KAAT,QAAsB,0BAAtB;;AAoBA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAT,CACLC,IADK,EAELC,KAFK,EAGLC,UAHK,EAIY;AAAA;;AACjB,MAAI;AAAEC,IAAAA,KAAF;AAASC,IAAAA,UAAT;AAAqBC,IAAAA;AAArB,MAAqCL,IAAzC;AAEA,MAAIM,UAAU,GAAGN,IAAI,CAACO,WAAL,KAAqB,UAAtC;AACA,QAAMC,SAAS,GAAGV,KAAK,KAAK,KAAL,GAAaW,SAApC;AAEA,MAAIC,OAAO,GAAGhB,SAAS,CAACiB,GAAV,CAAcV,KAAd,CAAd;AACA,QAAM;AAAEW,IAAAA,UAAF;AAAcC,IAAAA;AAAd,MAA6BjB,QAAQ,CAAC,EAC1C,GAAGI,IADuC;AAE1C,UAAMP,gBAAgB,CAACQ,KAAD,EAAQE,KAAR,CAFoB;AAG1C,uBAAoB,GAAEO,OAAQ,IAAX,wBAAcV,IAAI,CAAC,iBAAD,CAAlB,uEAAyC,EAAG,EAA5C,CAA8Cc,IAA9C;AAHuB,GAAD,CAA3C;AAMA,QAAMC,QAAQ,GAAGpB,MAAM,CAAc,IAAd,CAAvB;AACAoB,EAAA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AAEnD,KAAK,CAACuC,aAAN,CAAoBrC,KAApB;AAHa,OAJV;AASVkD,MAAAA,oBAAoB,EAAE,CACpB;AACEC,QAAAA,IAAI,EAAE,WADR;AAEEC,QAAAA,KAAK,EAAE;AAFT,OADoB,EAKpB;AACED,QAAAA,IAAI,EAAE,WADR;AAEEC,QAAAA,KAAK,EAAE;AAFT,OALoB,CATZ;AAmBVtB,MAAAA;AAnBU,KADP;AAsBLuB,IAAAA,UAAU,EAAE,CAACpD,UAAD,GAAce,SAAd,GAA0B,EAtBjC;AAuBLP,IAAAA;AAvBK,GAAP;AAyBD","sourcesContent":["import { AriaSliderThumbProps } from '@react-types/slider';\nimport { clamp } from '@react-aria/utils';\nimport { getSliderThumbId, sliderIds } from './utils';\nimport { useRef } from 'react';\nimport { SliderState } from '@react-stately/slider';\nimport { useLabel } from '@react-aria/label';\nimport { useMove } from './useMove';\nimport { isRTL } from '@react-native-aria/utils';\n\ninterface SliderThumbAria {\n /** Props for the root thumb element; handles the dragging motion. */\n thumbProps: any;\n\n /** Props for the visually hidden range input element. */\n inputProps: any;\n\n /** Props for the label element for this thumb (optional). */\n labelProps: any;\n}\n\ninterface SliderThumbOptions extends AriaSliderThumbProps {\n /** A ref to the track element. */\n trackLayout: any;\n /** A ref to the thumb input element. */\n inputRef: any;\n}\n\n/**\n * Provides behavior and accessibility for a thumb of a slider component.\n *\n * @param opts Options for this Slider thumb.\n * @param state Slider state, created via `useSliderState`.\n */\nexport function useSliderThumb(\n opts: SliderThumbOptions,\n state: SliderState,\n isReversed?: boolean\n): SliderThumbAria {\n let { index, isDisabled, trackLayout } = opts;\n\n let isVertical = opts.orientation === 'vertical';\n const direction = isRTL() ? 'rtl' : undefined;\n\n let labelId = sliderIds.get(state);\n const { labelProps, fieldProps } = useLabel({\n ...opts,\n 'id': getSliderThumbId(state, index),\n 'aria-labelledby': `${labelId} ${opts['aria-labelledby'] ?? ''}`.trim(),\n });\n\n const stateRef = useRef<SliderState>(null);\n stateRef.current = state;\n let reverseX = isReversed || direction === 'rtl';\n let currentPosition = useRef<number>(null);\n let { moveProps } = useMove({\n onMoveStart() {\n currentPosition.current = null;\n state.setThumbDragging(index, true);\n },\n onMove({ deltaX, deltaY }) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n\n if (currentPosition.current == null) {\n currentPosition.current =\n stateRef.current.getThumbPercent(index) * size;\n }\n\n let delta = isVertical ? deltaY : deltaX;\n if (reverseX) {\n if (!isVertical) {\n delta = -delta;\n }\n } else {\n if (isVertical) {\n delta = -delta;\n }\n }\n currentPosition.current += delta;\n stateRef.current.setThumbPercent(\n index,\n clamp(currentPosition.current / size, 0, 1)\n );\n },\n onMoveEnd() {\n state.setThumbDragging(index, false);\n },\n });\n\n state.setThumbEditable(index, !isDisabled);\n\n const onAccessibilityAction = (event: any) => {\n const max = state.getThumbMinValue(index);\n const min = state.getThumbMaxValue(index);\n const value = state.getThumbValue(index);\n\n const incrementValue = Math.min(value + state.step ?? 1, max);\n const decrementValue = Math.max(value - state.step ?? 1, min);\n\n switch (event.nativeEvent.actionName) {\n case 'increment':\n state.setThumbValue(index, incrementValue);\n break;\n case 'decrement':\n state.setThumbValue(index, decrementValue);\n break;\n default:\n break;\n }\n };\n\n return {\n inputProps: {\n ...fieldProps,\n disabled: isDisabled,\n accessibilityRole: 'adjustable',\n accessibilityValue: {\n min: state.getThumbMinValue(index),\n max: state.getThumbMaxValue(index),\n now: state.getThumbValue(index),\n },\n accessibilityActions: [\n {\n name: 'increment',\n label: 'Increment',\n },\n {\n name: 'decrement',\n label: 'Decrement',\n },\n ],\n onAccessibilityAction,\n },\n thumbProps: !isDisabled ? moveProps : {},\n labelProps,\n };\n}\n"]}
@@ -12,7 +12,7 @@ import { isRTL } from '@react-native-aria/utils';
12
12
  * @param opts Options for this Slider thumb.
13
13
  * @param state Slider state, created via `useSliderState`.
14
14
  */
15
- export function useSliderThumb(opts, state) {
15
+ export function useSliderThumb(opts, state, isReversed) {
16
16
  var _opts$ariaLabelledby;
17
17
 
18
18
  let {
@@ -51,7 +51,7 @@ export function useSliderThumb(opts, state) {
51
51
  }, [isFocused, focusInput]);
52
52
  const stateRef = useRef(null);
53
53
  stateRef.current = state;
54
- let reverseX = direction === 'rtl';
54
+ let reverseX = isReversed || direction === 'rtl';
55
55
  let currentPosition = useRef(null);
56
56
  let {
57
57
  moveProps
@@ -74,14 +74,20 @@ export function useSliderThumb(opts, state) {
74
74
 
75
75
  if (pointerType === 'keyboard') {
76
76
  // (invert left/right according to language direction) + (according to vertical)
77
- let delta = ((reverseX ? -deltaX : deltaX) + (isVertical ? -deltaY : -deltaY)) * stateRef.current.step;
77
+ let delta = ((reverseX ? -deltaX : deltaX) + (reverseX ? deltaY : -deltaY)) * stateRef.current.step;
78
78
  currentPosition.current += delta * size;
79
79
  stateRef.current.setThumbValue(index, stateRef.current.getThumbValue(index) + delta);
80
80
  } else {
81
81
  let delta = isVertical ? deltaY : deltaX;
82
82
 
83
- if (isVertical || reverseX) {
84
- delta = -delta;
83
+ if (reverseX) {
84
+ if (!isVertical) {
85
+ delta = -delta;
86
+ }
87
+ } else {
88
+ if (isVertical) {
89
+ delta = -delta;
90
+ }
85
91
  }
86
92
 
87
93
  currentPosition.current += delta;
@@ -1 +1 @@
1
- {"version":3,"sources":["useSliderThumb.web.ts"],"names":["clamp","focusWithoutScrolling","mergeProps","useGlobalListeners","getSliderThumbId","sliderIds","useCallback","useEffect","useRef","useFocusable","useLabel","useMove","isRTL","useSliderThumb","opts","state","index","isRequired","isDisabled","validationState","trackLayout","inputRef","isVertical","orientation","direction","undefined","addGlobalListener","removeGlobalListener","labelId","get","labelProps","fieldProps","trim","value","values","focusInput","current","isFocused","focusedThumb","stateRef","reverseX","currentPosition","moveProps","onMoveStart","setThumbDragging","onMove","deltaX","deltaY","pointerType","size","height","width","getThumbPercent","delta","step","setThumbValue","getThumbValue","setThumbPercent","onMoveEnd","setThumbEditable","focusableProps","onFocus","setFocusedThumb","onBlur","currentPointer","onDown","id","window","onUp","e","pointerId","changedTouches","identifier","inputProps","getThumbMinValue","getThumbMaxValue","getThumbValueLabel","parseFloat","target","thumbProps","onMouseDown","button","altKey","ctrlKey","metaKey","onPointerDown","onTouchStart"],"mappings":"AACA,SACEA,KADF,EAEEC,qBAFF,EAGEC,UAHF,EAIEC,kBAJF,QAKO,mBALP;AAMA,SAASC,gBAAT,EAA2BC,SAA3B,QAA4C,SAA5C;AACA,SAMEC,WANF,EAOEC,SAPF,EAQEC,MARF,QASO,OATP;AAWA,SAASC,YAAT,QAA6B,mBAA7B;AACA,SAASC,QAAT,QAAyB,mBAAzB;AACA,SAASC,OAAT,QAAwB,WAAxB;AACA,SAASC,KAAT,QAAsB,0BAAtB;;AAoBA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAT,CACLC,IADK,EAELC,KAFK,EAGY;AAAA;;AACjB,MAAI;AACFC,IAAAA,KADE;AAEFC,IAAAA,UAFE;AAGFC,IAAAA,UAHE;AAIFC,IAAAA,eAJE;AAKFC,IAAAA,WALE;AAMFC,IAAAA;AANE,MAOAP,IAPJ;AASA,MAAIQ,UAAU,GAAGR,IAAI,CAACS,WAAL,KAAqB,UAAtC;AAEA,MAAIC,SAAS,GAAGZ,KAAK,KAAK,KAAL,GAAaa,SAAlC;AACA,MAAI;AAAEC,IAAAA,iBAAF;AAAqBC,IAAAA;AAArB,MAA8CxB,kBAAkB,EAApE;AAEA,MAAIyB,OAAO,GAAGvB,SAAS,CAACwB,GAAV,CAAcd,KAAd,CAAd;AACA,QAAM;AAAEe,IAAAA,UAAF;AAAcC,IAAAA;AAAd,MAA6BrB,QAAQ,CAAC,EAC1C,GAAGI,IADuC;AAE1C,UAAMV,gBAAgB,CAACW,KAAD,EAAQC,KAAR,CAFoB;AAG1C,uBAAoB,GAAEY,OAAQ,IAAX,wBAAcd,IAAI,CAAC,iBAAD,CAAlB,uEAAyC,EAAG,EAA5C,CAA8CkB,IAA9C;AAHuB,GAAD,CAA3C;AAMA,QAAMC,KA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AN;AACD,OAZmB;AAapBgB,MAAAA,YAAY,EAAGjB,CAAD,IAAsC;AAClDJ,QAAAA,MAAM,CAACI,CAAC,CAACE,cAAF,CAAiB,CAAjB,EAAoBC,UAArB,CAAN;AACD;AAfmB,KAAZ,CADF,GAkBR,EApCC;AAqCL1C,IAAAA;AArCK,GAAP;AAuCD","sourcesContent":["import { AriaSliderThumbProps } from '@react-types/slider';\nimport {\n clamp,\n focusWithoutScrolling,\n mergeProps,\n useGlobalListeners,\n} from '@react-aria/utils';\nimport { getSliderThumbId, sliderIds } from './utils';\nimport React, {\n ChangeEvent,\n HTMLAttributes,\n InputHTMLAttributes,\n LabelHTMLAttributes,\n RefObject,\n useCallback,\n useEffect,\n useRef,\n} from 'react';\nimport { SliderState } from '@react-stately/slider';\nimport { useFocusable } from '@react-aria/focus';\nimport { useLabel } from '@react-aria/label';\nimport { useMove } from './useMove';\nimport { isRTL } from '@react-native-aria/utils';\n\ninterface SliderThumbAria {\n /** Props for the root thumb element; handles the dragging motion. */\n thumbProps: HTMLAttributes<HTMLElement>;\n\n /** Props for the visually hidden range input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>;\n\n /** Props for the label element for this thumb (optional). */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>;\n}\n\ninterface SliderThumbOptions extends AriaSliderThumbProps {\n /** A ref to the track element. */\n trackLayout: any;\n /** A ref to the thumb input element. */\n inputRef: RefObject<HTMLInputElement>;\n}\n\n/**\n * Provides behavior and accessibility for a thumb of a slider component.\n *\n * @param opts Options for this Slider thumb.\n * @param state Slider state, created via `useSliderState`.\n */\nexport function useSliderThumb(\n opts: SliderThumbOptions,\n state: SliderState\n): SliderThumbAria {\n let {\n index,\n isRequired,\n isDisabled,\n validationState,\n trackLayout,\n inputRef,\n } = opts;\n\n let isVertical = opts.orientation === 'vertical';\n\n let direction = isRTL() ? 'rtl' : undefined;\n let { addGlobalListener, removeGlobalListener } = useGlobalListeners();\n\n let labelId = sliderIds.get(state);\n const { labelProps, fieldProps } = useLabel({\n ...opts,\n 'id': getSliderThumbId(state, index),\n 'aria-labelledby': `${labelId} ${opts['aria-labelledby'] ?? ''}`.trim(),\n });\n\n const value = state.values[index];\n\n const focusInput = useCallback(() => {\n if (inputRef.current) {\n focusWithoutScrolling(inputRef.current);\n }\n }, [inputRef]);\n\n const isFocused = state.focusedThumb === index;\n\n useEffect(() => {\n if (isFocused) {\n focusInput();\n }\n }, [isFocused, focusInput]);\n\n const stateRef = useRef<SliderState>(null);\n stateRef.current = state;\n let reverseX = direction === 'rtl';\n let currentPosition = useRef<number>(null);\n let { moveProps } = useMove({\n onMoveStart() {\n currentPosition.current = null;\n state.setThumbDragging(index, true);\n },\n onMove({ deltaX, deltaY, pointerType }) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n\n if (currentPosition.current == null) {\n currentPosition.current =\n stateRef.current.getThumbPercent(index) * size;\n }\n if (pointerType === 'keyboard') {\n // (invert left/right according to language direction) + (according to vertical)\n let delta =\n ((reverseX ? -deltaX : deltaX) + (isVertical ? -deltaY : -deltaY)) *\n stateRef.current.step;\n currentPosition.current += delta * size;\n stateRef.current.setThumbValue(\n index,\n stateRef.current.getThumbValue(index) + delta\n );\n } else {\n let delta = isVertical ? deltaY : deltaX;\n if (isVertical || reverseX) {\n delta = -delta;\n }\n currentPosition.current += delta;\n stateRef.current.setThumbPercent(\n index,\n clamp(currentPosition.current / size, 0, 1)\n );\n }\n },\n onMoveEnd() {\n state.setThumbDragging(index, false);\n },\n });\n\n // Immediately register editability with the state\n state.setThumbEditable(index, !isDisabled);\n\n const { focusableProps } = useFocusable(\n mergeProps(opts, {\n onFocus: () => state.setFocusedThumb(index),\n onBlur: () => state.setFocusedThumb(undefined),\n }),\n inputRef\n );\n\n let currentPointer = useRef<number | undefined>(undefined);\n let onDown = (id?: number) => {\n focusInput();\n currentPointer.current = id;\n state.setThumbDragging(index, true);\n\n addGlobalListener(window, 'mouseup', onUp, false);\n addGlobalListener(window, 'touchend', onUp, false);\n addGlobalListener(window, 'pointerup', onUp, false);\n };\n\n let onUp = (e) => {\n let id = e.pointerId ?? e.changedTouches?.[0].identifier;\n if (id === currentPointer.current) {\n focusInput();\n state.setThumbDragging(index, false);\n removeGlobalListener(window, 'mouseup', onUp, false);\n removeGlobalListener(window, 'touchend', onUp, false);\n removeGlobalListener(window, 'pointerup', onUp, false);\n }\n };\n\n // We install mouse handlers for the drag motion on the thumb div, but\n // not the key handler for moving the thumb with the slider. Instead,\n // we focus the range input, and let the browser handle the keyboard\n // interactions; we then listen to input's onChange to update state.\n return {\n inputProps: mergeProps(focusableProps, fieldProps, {\n 'type': 'range',\n 'tabIndex': !isDisabled ? 0 : undefined,\n 'min': state.getThumbMinValue(index),\n 'max': state.getThumbMaxValue(index),\n 'step': state.step,\n 'value': value,\n 'disabled': isDisabled,\n 'aria-orientation': opts.orientation,\n 'aria-valuetext': state.getThumbValueLabel(index),\n 'aria-required': isRequired || undefined,\n 'aria-invalid': validationState === 'invalid' || undefined,\n 'aria-errormessage': opts['aria-errormessage'],\n 'onChange': (e: ChangeEvent<HTMLInputElement>) => {\n state.setThumbValue(index, parseFloat(e.target.value));\n },\n }),\n thumbProps: !isDisabled\n ? mergeProps(moveProps, {\n onMouseDown: (e: React.MouseEvent<HTMLElement>) => {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onDown();\n },\n onPointerDown: (e: React.PointerEvent<HTMLElement>) => {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onDown(e.pointerId);\n },\n onTouchStart: (e: React.TouchEvent<HTMLElement>) => {\n onDown(e.changedTouches[0].identifier);\n },\n })\n : {},\n labelProps,\n };\n}\n"]}
1
+ {"version":3,"sources":["useSliderThumb.web.ts"],"names":["clamp","focusWithoutScrolling","mergeProps","useGlobalListeners","getSliderThumbId","sliderIds","useCallback","useEffect","useRef","useFocusable","useLabel","useMove","isRTL","useSliderThumb","opts","state","isReversed","index","isRequired","isDisabled","validationState","trackLayout","inputRef","isVertical","orientation","direction","undefined","addGlobalListener","removeGlobalListener","labelId","get","labelProps","fieldProps","trim","value","values","focusInput","current","isFocused","focusedThumb","stateRef","reverseX","currentPosition","moveProps","onMoveStart","setThumbDragging","onMove","deltaX","deltaY","pointerType","size","height","width","getThumbPercent","delta","step","setThumbValue","getThumbValue","setThumbPercent","onMoveEnd","setThumbEditable","focusableProps","onFocus","setFocusedThumb","onBlur","currentPointer","onDown","id","window","onUp","e","pointerId","changedTouches","identifier","inputProps","getThumbMinValue","getThumbMaxValue","getThumbValueLabel","parseFloat","target","thumbProps","onMouseDown","button","altKey","ctrlKey","metaKey","onPointerDown","onTouchStart"],"mappings":"AACA,SACEA,KADF,EAEEC,qBAFF,EAGEC,UAHF,EAIEC,kBAJF,QAKO,mBALP;AAMA,SAASC,gBAAT,EAA2BC,SAA3B,QAA4C,SAA5C;AACA,SAMEC,WANF,EAOEC,SAPF,EAQEC,MARF,QASO,OATP;AAWA,SAASC,YAAT,QAA6B,mBAA7B;AACA,SAASC,QAAT,QAAyB,mBAAzB;AACA,SAASC,OAAT,QAAwB,WAAxB;AACA,SAASC,KAAT,QAAsB,0BAAtB;;AAoBA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAT,CACLC,IADK,EAELC,KAFK,EAGLC,UAHK,EAIY;AAAA;;AACjB,MAAI;AACFC,IAAAA,KADE;AAEFC,IAAAA,UAFE;AAGFC,IAAAA,UAHE;AAIFC,IAAAA,eAJE;AAKFC,IAAAA,WALE;AAMFC,IAAAA;AANE,MAOAR,IAPJ;AASA,MAAIS,UAAU,GAAGT,IAAI,CAACU,WAAL,KAAqB,UAAtC;AAEA,MAAIC,SAAS,GAAGb,KAAK,KAAK,KAAL,GAAac,SAAlC;AACA,MAAI;AAAEC,IAAAA,iBAAF;AAAqBC,IAAAA;AAArB,MAA8CzB,kBAAkB,EAApE;AAEA,MAAI0B,OAAO,GAAGxB,SAAS,CAACyB,GAAV,CAAcf,K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;AACjD,YAAIA,CAAC,CAACY,MAAF,KAAa,CAAb,IAAkBZ,CAAC,CAACa,MAApB,IAA8Bb,CAAC,CAACc,OAAhC,IAA2Cd,CAAC,CAACe,OAAjD,EAA0D;AACxD;AACD;;AACDnB,QAAAA,MAAM;AACP,OANmB;AAOpBoB,MAAAA,aAAa,EAAGhB,CAAD,IAAwC;AACrD,YAAIA,CAAC,CAACY,MAAF,KAAa,CAAb,IAAkBZ,CAAC,CAACa,MAApB,IAA8Bb,CAAC,CAACc,OAAhC,IAA2Cd,CAAC,CAACe,OAAjD,EAA0D;AACxD;AACD;;AACDnB,QAAAA,MAAM,CAACI,CAAC,CAACC,SAAH,CAAN;AACD,OAZmB;AAapBgB,MAAAA,YAAY,EAAGjB,CAAD,IAAsC;AAClDJ,QAAAA,MAAM,CAACI,CAAC,CAACE,cAAF,CAAiB,CAAjB,EAAoBC,UAArB,CAAN;AACD;AAfmB,KAAZ,CADF,GAkBR,EApCC;AAqCL1C,IAAAA;AArCK,GAAP;AAuCD","sourcesContent":["import { AriaSliderThumbProps } from '@react-types/slider';\nimport {\n clamp,\n focusWithoutScrolling,\n mergeProps,\n useGlobalListeners,\n} from '@react-aria/utils';\nimport { getSliderThumbId, sliderIds } from './utils';\nimport React, {\n ChangeEvent,\n HTMLAttributes,\n InputHTMLAttributes,\n LabelHTMLAttributes,\n RefObject,\n useCallback,\n useEffect,\n useRef,\n} from 'react';\nimport { SliderState } from '@react-stately/slider';\nimport { useFocusable } from '@react-aria/focus';\nimport { useLabel } from '@react-aria/label';\nimport { useMove } from './useMove';\nimport { isRTL } from '@react-native-aria/utils';\n\ninterface SliderThumbAria {\n /** Props for the root thumb element; handles the dragging motion. */\n thumbProps: HTMLAttributes<HTMLElement>;\n\n /** Props for the visually hidden range input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>;\n\n /** Props for the label element for this thumb (optional). */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>;\n}\n\ninterface SliderThumbOptions extends AriaSliderThumbProps {\n /** A ref to the track element. */\n trackLayout: any;\n /** A ref to the thumb input element. */\n inputRef: RefObject<HTMLInputElement>;\n}\n\n/**\n * Provides behavior and accessibility for a thumb of a slider component.\n *\n * @param opts Options for this Slider thumb.\n * @param state Slider state, created via `useSliderState`.\n */\nexport function useSliderThumb(\n opts: SliderThumbOptions,\n state: SliderState,\n isReversed?: boolean\n): SliderThumbAria {\n let {\n index,\n isRequired,\n isDisabled,\n validationState,\n trackLayout,\n inputRef,\n } = opts;\n\n let isVertical = opts.orientation === 'vertical';\n\n let direction = isRTL() ? 'rtl' : undefined;\n let { addGlobalListener, removeGlobalListener } = useGlobalListeners();\n\n let labelId = sliderIds.get(state);\n const { labelProps, fieldProps } = useLabel({\n ...opts,\n 'id': getSliderThumbId(state, index),\n 'aria-labelledby': `${labelId} ${opts['aria-labelledby'] ?? ''}`.trim(),\n });\n\n const value = state.values[index];\n\n const focusInput = useCallback(() => {\n if (inputRef.current) {\n focusWithoutScrolling(inputRef.current);\n }\n }, [inputRef]);\n\n const isFocused = state.focusedThumb === index;\n\n useEffect(() => {\n if (isFocused) {\n focusInput();\n }\n }, [isFocused, focusInput]);\n\n const stateRef = useRef<SliderState>(null);\n stateRef.current = state;\n let reverseX = isReversed || direction === 'rtl';\n let currentPosition = useRef<number>(null);\n let { moveProps } = useMove({\n onMoveStart() {\n currentPosition.current = null;\n state.setThumbDragging(index, true);\n },\n onMove({ deltaX, deltaY, pointerType }) {\n let size = isVertical ? trackLayout.height : trackLayout.width;\n\n if (currentPosition.current == null) {\n currentPosition.current =\n stateRef.current.getThumbPercent(index) * size;\n }\n if (pointerType === 'keyboard') {\n // (invert left/right according to language direction) + (according to vertical)\n let delta =\n ((reverseX ? -deltaX : deltaX) + (reverseX ? deltaY : -deltaY)) *\n stateRef.current.step;\n currentPosition.current += delta * size;\n stateRef.current.setThumbValue(\n index,\n stateRef.current.getThumbValue(index) + delta\n );\n } else {\n let delta = isVertical ? deltaY : deltaX;\n if (reverseX) {\n if (!isVertical) {\n delta = -delta;\n }\n } else {\n if (isVertical) {\n delta = -delta;\n }\n }\n currentPosition.current += delta;\n stateRef.current.setThumbPercent(\n index,\n clamp(currentPosition.current / size, 0, 1)\n );\n }\n },\n onMoveEnd() {\n state.setThumbDragging(index, false);\n },\n });\n\n // Immediately register editability with the state\n state.setThumbEditable(index, !isDisabled);\n\n const { focusableProps } = useFocusable(\n mergeProps(opts, {\n onFocus: () => state.setFocusedThumb(index),\n onBlur: () => state.setFocusedThumb(undefined),\n }),\n inputRef\n );\n\n let currentPointer = useRef<number | undefined>(undefined);\n let onDown = (id?: number) => {\n focusInput();\n currentPointer.current = id;\n state.setThumbDragging(index, true);\n\n addGlobalListener(window, 'mouseup', onUp, false);\n addGlobalListener(window, 'touchend', onUp, false);\n addGlobalListener(window, 'pointerup', onUp, false);\n };\n\n let onUp = (e) => {\n let id = e.pointerId ?? e.changedTouches?.[0].identifier;\n if (id === currentPointer.current) {\n focusInput();\n state.setThumbDragging(index, false);\n removeGlobalListener(window, 'mouseup', onUp, false);\n removeGlobalListener(window, 'touchend', onUp, false);\n removeGlobalListener(window, 'pointerup', onUp, false);\n }\n };\n\n // We install mouse handlers for the drag motion on the thumb div, but\n // not the key handler for moving the thumb with the slider. Instead,\n // we focus the range input, and let the browser handle the keyboard\n // interactions; we then listen to input's onChange to update state.\n return {\n inputProps: mergeProps(focusableProps, fieldProps, {\n 'type': 'range',\n 'tabIndex': !isDisabled ? 0 : undefined,\n 'min': state.getThumbMinValue(index),\n 'max': state.getThumbMaxValue(index),\n 'step': state.step,\n 'value': value,\n 'disabled': isDisabled,\n 'aria-orientation': opts.orientation,\n 'aria-valuetext': state.getThumbValueLabel(index),\n 'aria-required': isRequired || undefined,\n 'aria-invalid': validationState === 'invalid' || undefined,\n 'aria-errormessage': opts['aria-errormessage'],\n 'onChange': (e: ChangeEvent<HTMLInputElement>) => {\n state.setThumbValue(index, parseFloat(e.target.value));\n },\n }),\n thumbProps: !isDisabled\n ? mergeProps(moveProps, {\n onMouseDown: (e: React.MouseEvent<HTMLElement>) => {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onDown();\n },\n onPointerDown: (e: React.PointerEvent<HTMLElement>) => {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onDown(e.pointerId);\n },\n onTouchStart: (e: React.TouchEvent<HTMLElement>) => {\n onDown(e.changedTouches[0].identifier);\n },\n })\n : {},\n labelProps,\n };\n}\n"]}
@@ -20,5 +20,5 @@ interface SliderAria {
20
20
  * accepts click and drag motions, so that the closest thumb will follow clicks and drags on
21
21
  * the track.
22
22
  */
23
- export declare function useSlider(props: AriaSliderProps, state: SliderState, trackLayout: any): SliderAria;
23
+ export declare function useSlider(props: AriaSliderProps, state: SliderState, trackLayout: any, isReversed?: boolean): SliderAria;
24
24
  export {};
@@ -1,4 +1,4 @@
1
- export declare const useSlider: (props: any, state: any, ref: any) => {
1
+ export declare const useSlider: (props: any, state: any, ref: any, isReversed?: boolean) => {
2
2
  labelProps: any;
3
3
  /** Props for the track element. */
4
4
  trackProps: any;
@@ -20,5 +20,5 @@ interface SliderThumbOptions extends AriaSliderThumbProps {
20
20
  * @param opts Options for this Slider thumb.
21
21
  * @param state Slider state, created via `useSliderState`.
22
22
  */
23
- export declare function useSliderThumb(opts: SliderThumbOptions, state: SliderState): SliderThumbAria;
23
+ export declare function useSliderThumb(opts: SliderThumbOptions, state: SliderState, isReversed?: boolean): SliderThumbAria;
24
24
  export {};
@@ -21,5 +21,5 @@ interface SliderThumbOptions extends AriaSliderThumbProps {
21
21
  * @param opts Options for this Slider thumb.
22
22
  * @param state Slider state, created via `useSliderState`.
23
23
  */
24
- export declare function useSliderThumb(opts: SliderThumbOptions, state: SliderState): SliderThumbAria;
24
+ export declare function useSliderThumb(opts: SliderThumbOptions, state: SliderState, isReversed?: boolean): SliderThumbAria;
25
25
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-aria/slider",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "useSlider - React Native Aria",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
package/src/useSlider.ts CHANGED
@@ -32,7 +32,8 @@ interface SliderAria {
32
32
  export function useSlider(
33
33
  props: AriaSliderProps,
34
34
  state: SliderState,
35
- trackLayout: any
35
+ trackLayout: any,
36
+ isReversed?: boolean
36
37
  ): SliderAria {
37
38
  let { labelProps, fieldProps } = useLabel(props);
38
39
 
@@ -48,6 +49,7 @@ export function useSlider(
48
49
  clientY: number
49
50
  ) => {
50
51
  const direction = isRTL() ? 'rtl' : undefined;
52
+ const reverseX = isReversed || direction === 'rtl';
51
53
  if (
52
54
  !props.isDisabled &&
53
55
  state.values.every((_, i) => !state.isThumbDragging(i))
@@ -58,8 +60,14 @@ export function useSlider(
58
60
  const clickPosition = isVertical ? clientY : clientX;
59
61
  const offset = clickPosition - trackPosition;
60
62
  let percent = offset / size;
61
- if (direction === 'rtl' || isVertical) {
62
- percent = 1 - percent;
63
+ if (reverseX) {
64
+ if (!isVertical) {
65
+ percent = 1 - percent;
66
+ }
67
+ } else {
68
+ if (isVertical) {
69
+ percent = 1 - percent;
70
+ }
63
71
  }
64
72
  let value = state.getPercentValue(percent);
65
73
  // to find the closet thumb we split the array based on the first thumb position to the "right/end" of the click.
@@ -32,7 +32,8 @@ function useSliderWeb(
32
32
  left: number;
33
33
  x: number;
34
34
  y: number;
35
- }
35
+ },
36
+ isReversed?: boolean
36
37
  ): SliderAria {
37
38
  let { labelProps, fieldProps } = useLabel(props);
38
39
 
@@ -53,7 +54,8 @@ function useSliderWeb(
53
54
 
54
55
  const stateRef = useRef<SliderState>(null);
55
56
  stateRef.current = state;
56
- const reverseX = direction === 'rtl';
57
+ const reverseX = isReversed || direction === 'rtl';
58
+
57
59
  const currentPosition = useRef<number>(null);
58
60
  const { moveProps } = useMove({
59
61
  onMoveStart() {
@@ -69,8 +71,14 @@ function useSliderWeb(
69
71
  }
70
72
 
71
73
  let delta = isVertical ? deltaY : deltaX;
72
- if (isVertical || reverseX) {
73
- delta = -delta;
74
+ if (reverseX) {
75
+ if (!isVertical) {
76
+ delta = -delta;
77
+ }
78
+ } else {
79
+ if (isVertical) {
80
+ delta = -delta;
81
+ }
74
82
  }
75
83
 
76
84
  currentPosition.current += delta;
@@ -112,8 +120,14 @@ function useSliderWeb(
112
120
  const clickPosition = isVertical ? clientY : clientX;
113
121
  const offset = clickPosition - trackPosition;
114
122
  let percent = offset / size;
115
- if (direction === 'rtl' || isVertical) {
116
- percent = 1 - percent;
123
+ if (reverseX) {
124
+ if (!isVertical) {
125
+ percent = 1 - percent;
126
+ }
127
+ } else {
128
+ if (isVertical) {
129
+ percent = 1 - percent;
130
+ }
117
131
  }
118
132
  let value = state.getPercentValue(percent);
119
133
 
@@ -232,8 +246,18 @@ function useSliderWeb(
232
246
  };
233
247
  }
234
248
 
235
- export const useSlider = (props: any, state: any, ref: any) => {
236
- let { groupProps: webGroupProps, ...rest } = useSliderWeb(props, state, ref);
249
+ export const useSlider = (
250
+ props: any,
251
+ state: any,
252
+ ref: any,
253
+ isReversed?: boolean
254
+ ) => {
255
+ let { groupProps: webGroupProps, ...rest } = useSliderWeb(
256
+ props,
257
+ state,
258
+ ref,
259
+ isReversed
260
+ );
237
261
  let groupProps = mapDomPropsToRN(webGroupProps);
238
262
  let labelProps = mapDomPropsToRN(rest.labelProps);
239
263
  return { groupProps, ...rest, labelProps };
@@ -33,7 +33,8 @@ interface SliderThumbOptions extends AriaSliderThumbProps {
33
33
  */
34
34
  export function useSliderThumb(
35
35
  opts: SliderThumbOptions,
36
- state: SliderState
36
+ state: SliderState,
37
+ isReversed?: boolean
37
38
  ): SliderThumbAria {
38
39
  let { index, isDisabled, trackLayout } = opts;
39
40
 
@@ -49,7 +50,7 @@ export function useSliderThumb(
49
50
 
50
51
  const stateRef = useRef<SliderState>(null);
51
52
  stateRef.current = state;
52
- let reverseX = direction === 'rtl';
53
+ let reverseX = isReversed || direction === 'rtl';
53
54
  let currentPosition = useRef<number>(null);
54
55
  let { moveProps } = useMove({
55
56
  onMoveStart() {
@@ -65,8 +66,14 @@ export function useSliderThumb(
65
66
  }
66
67
 
67
68
  let delta = isVertical ? deltaY : deltaX;
68
- if (isVertical || reverseX) {
69
- delta = -delta;
69
+ if (reverseX) {
70
+ if (!isVertical) {
71
+ delta = -delta;
72
+ }
73
+ } else {
74
+ if (isVertical) {
75
+ delta = -delta;
76
+ }
70
77
  }
71
78
  currentPosition.current += delta;
72
79
  stateRef.current.setThumbPercent(
@@ -48,7 +48,8 @@ interface SliderThumbOptions extends AriaSliderThumbProps {
48
48
  */
49
49
  export function useSliderThumb(
50
50
  opts: SliderThumbOptions,
51
- state: SliderState
51
+ state: SliderState,
52
+ isReversed?: boolean
52
53
  ): SliderThumbAria {
53
54
  let {
54
55
  index,
@@ -89,7 +90,7 @@ export function useSliderThumb(
89
90
 
90
91
  const stateRef = useRef<SliderState>(null);
91
92
  stateRef.current = state;
92
- let reverseX = direction === 'rtl';
93
+ let reverseX = isReversed || direction === 'rtl';
93
94
  let currentPosition = useRef<number>(null);
94
95
  let { moveProps } = useMove({
95
96
  onMoveStart() {
@@ -106,7 +107,7 @@ export function useSliderThumb(
106
107
  if (pointerType === 'keyboard') {
107
108
  // (invert left/right according to language direction) + (according to vertical)
108
109
  let delta =
109
- ((reverseX ? -deltaX : deltaX) + (isVertical ? -deltaY : -deltaY)) *
110
+ ((reverseX ? -deltaX : deltaX) + (reverseX ? deltaY : -deltaY)) *
110
111
  stateRef.current.step;
111
112
  currentPosition.current += delta * size;
112
113
  stateRef.current.setThumbValue(
@@ -115,8 +116,14 @@ export function useSliderThumb(
115
116
  );
116
117
  } else {
117
118
  let delta = isVertical ? deltaY : deltaX;
118
- if (isVertical || reverseX) {
119
- delta = -delta;
119
+ if (reverseX) {
120
+ if (!isVertical) {
121
+ delta = -delta;
122
+ }
123
+ } else {
124
+ if (isVertical) {
125
+ delta = -delta;
126
+ }
120
127
  }
121
128
  currentPosition.current += delta;
122
129
  stateRef.current.setThumbPercent(