@newtonedev/components 0.1.10 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2493,6 +2493,7 @@ function Slider({
2493
2493
  const trackRef = React14.useRef(null);
2494
2494
  const trackWidth = React14.useRef(0);
2495
2495
  const trackPageX = React14.useRef(0);
2496
+ const [layoutWidth, setLayoutWidth] = React14.useState(0);
2496
2497
  const onValueChangeRef = React14.useRef(onValueChange);
2497
2498
  const minRef = React14.useRef(min);
2498
2499
  const maxRef = React14.useRef(max);
@@ -2533,9 +2534,21 @@ function Slider({
2533
2534
  })
2534
2535
  ).current;
2535
2536
  const ratio = max > min ? (value - min) / (max - min) : 0;
2536
- const usableWidth = Math.max(0, trackWidth.current - THUMB_SIZE2);
2537
+ const usableWidth = Math.max(0, layoutWidth - THUMB_SIZE2);
2537
2538
  const thumbLeft = ratio * usableWidth;
2538
- const fillWidth = thumbLeft + THUMB_SIZE2 / 2;
2539
+ const isCenterOrigin = min < 0 && max > 0;
2540
+ let fillLeft;
2541
+ let fillWidth;
2542
+ if (isCenterOrigin) {
2543
+ const centerRatio = (0 - min) / (max - min);
2544
+ const centerX = centerRatio * usableWidth + THUMB_SIZE2 / 2;
2545
+ const thumbCenterX = thumbLeft + THUMB_SIZE2 / 2;
2546
+ fillLeft = Math.min(centerX, thumbCenterX);
2547
+ fillWidth = Math.abs(thumbCenterX - centerX);
2548
+ } else {
2549
+ fillLeft = 0;
2550
+ fillWidth = thumbLeft + THUMB_SIZE2 / 2;
2551
+ }
2539
2552
  const handleValueTextSubmit = React14.useCallback(
2540
2553
  (text) => {
2541
2554
  const raw = Number(text);
@@ -2568,7 +2581,9 @@ function Slider({
2568
2581
  ref: trackRef,
2569
2582
  style: styles.trackContainer,
2570
2583
  onLayout: (e) => {
2571
- trackWidth.current = e.nativeEvent.layout.width;
2584
+ const w = e.nativeEvent.layout.width;
2585
+ trackWidth.current = w;
2586
+ setLayoutWidth(w);
2572
2587
  trackRef.current?.measure((_x, _y, _w, _h, pageX) => {
2573
2588
  if (pageX != null) trackPageX.current = pageX;
2574
2589
  });
@@ -2576,7 +2591,7 @@ function Slider({
2576
2591
  ...panResponder.panHandlers
2577
2592
  },
2578
2593
  /* @__PURE__ */ React14.createElement(View, { style: styles.trackRail }),
2579
- /* @__PURE__ */ React14.createElement(View, { style: [styles.trackFill, { width: fillWidth }] }),
2594
+ /* @__PURE__ */ React14.createElement(View, { style: [styles.trackFill, { left: fillLeft, width: fillWidth }] }),
2580
2595
  /* @__PURE__ */ React14.createElement(View, { style: [styles.thumb, { left: thumbLeft }] })
2581
2596
  ));
2582
2597
  }
@@ -2711,6 +2726,7 @@ function HueSlider({
2711
2726
  const trackRef = React14.useRef(null);
2712
2727
  const trackWidth = React14.useRef(0);
2713
2728
  const trackPageX = React14.useRef(0);
2729
+ const [layoutWidth, setLayoutWidth] = React14.useState(0);
2714
2730
  const onValueChangeRef = React14.useRef(onValueChange);
2715
2731
  const minRef = React14.useRef(min);
2716
2732
  const maxRef = React14.useRef(max);
@@ -2748,7 +2764,7 @@ function HueSlider({
2748
2764
  ).current;
2749
2765
  const sliderValue = max > 359 && value < min ? value + 360 : value;
2750
2766
  const ratio = max > min ? (sliderValue - min) / (max - min) : 0;
2751
- const usableWidth = Math.max(0, trackWidth.current - THUMB_SIZE3);
2767
+ const usableWidth = Math.max(0, layoutWidth - THUMB_SIZE3);
2752
2768
  const thumbLeft = ratio * usableWidth;
2753
2769
  const handleValueTextSubmit = React14.useCallback(
2754
2770
  (text) => {
@@ -2782,7 +2798,9 @@ function HueSlider({
2782
2798
  ref: trackRef,
2783
2799
  style: styles.trackContainer,
2784
2800
  onLayout: (e) => {
2785
- trackWidth.current = e.nativeEvent.layout.width;
2801
+ const w = e.nativeEvent.layout.width;
2802
+ trackWidth.current = w;
2803
+ setLayoutWidth(w);
2786
2804
  trackRef.current?.measure((_x, _y, _w, _h, pageX) => {
2787
2805
  if (pageX != null) trackPageX.current = pageX;
2788
2806
  });
@@ -2870,6 +2888,7 @@ function ColorScaleSlider({
2870
2888
  const trackPageX = React14.useRef(0);
2871
2889
  const isDragging = React14.useRef(false);
2872
2890
  const thumbAnim = React14.useRef(new Animated.Value(0)).current;
2891
+ const [layoutWidth, setLayoutWidth] = React14.useState(0);
2873
2892
  const onValueChangeRef = React14.useRef(onValueChange);
2874
2893
  const disabledRef = React14.useRef(disabled);
2875
2894
  const colorsLengthRef = React14.useRef(colors.length);
@@ -2931,7 +2950,7 @@ function ColorScaleSlider({
2931
2950
  const range = maxNV - minNV;
2932
2951
  const clampedValue = value !== void 0 ? Math.min(maxNV, Math.max(minNV, value)) : (maxNV + minNV) / 2;
2933
2952
  const ratio = range > 0 ? (maxNV - clampedValue) / range : 0.5;
2934
- const usableWidth = Math.max(0, trackWidth.current - THUMB_SIZE4);
2953
+ const usableWidth = Math.max(0, layoutWidth - THUMB_SIZE4);
2935
2954
  const thumbLeft = ratio * usableWidth;
2936
2955
  React14.useEffect(() => {
2937
2956
  if (isDragging.current || !animateValue) {
@@ -2950,9 +2969,9 @@ function ColorScaleSlider({
2950
2969
  ref: trackRef,
2951
2970
  style: styles.trackContainer,
2952
2971
  onLayout: (e) => {
2953
- trackWidth.current = e.nativeEvent.layout.width;
2954
- const newUsableWidth = Math.max(0, e.nativeEvent.layout.width - THUMB_SIZE4);
2955
- thumbAnim.setValue(ratio * newUsableWidth);
2972
+ const w = e.nativeEvent.layout.width;
2973
+ trackWidth.current = w;
2974
+ setLayoutWidth(w);
2956
2975
  trackRef.current?.measure((_x, _y, _w, _h, pageX) => {
2957
2976
  if (pageX != null) trackPageX.current = pageX;
2958
2977
  });