Skip to content

Commit 34ff552

Browse files
Merge pull request #49 from SimformSolutionsPvtLtd/feature/UNT-T22232_format_custom_start_point_code
feat: UNT-T22232 format custom start point code
2 parents f555279 + 765123f commit 34ff552

File tree

14 files changed

+193
-94
lines changed

14 files changed

+193
-94
lines changed

README.md

Lines changed: 69 additions & 70 deletions
Large diffs are not rendered by default.
File renamed without changes.
File renamed without changes.

example/.prettierrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
2+
bracketSameLine: true,
23
bracketSpacing: true,
34
bracketSameLine: true,
45
singleQuote: true,

src/components/RadialSlider/LineContent.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,20 @@ const LineContent = (props: LineContentProps) => {
8080
? false
8181
: isMarkerLine;
8282

83-
const radialCircleLineRotation = isRadialCircleVariant ? 86 : 90;
83+
// Calculate the slider point adjustment based on the provided start point
84+
// The values -4 and -2 are used for fine-tuning the adjustment
85+
// -4 accounts for a base adjustment, and -2 is a multiplier applied to the start point
86+
const sliderPointAdjustment = -4 - 2 * (props?.startAngle || 0);
87+
88+
// Adjust the slider start point based on variant type or use a default value (86)
89+
const adjustedSliderStartPoint =
90+
isRadialCircleVariant && props?.startAngle != null
91+
? props.startAngle + sliderPointAdjustment
92+
: 86;
93+
94+
const radialCircleLineRotation = isRadialCircleVariant
95+
? adjustedSliderStartPoint
96+
: 90;
8497

8598
return (
8699
<G key={index.toString()}>

src/components/RadialSlider/RadialSlider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { View, Platform, StyleSheet } from 'react-native';
1111
import type { RadialSliderProps } from './types';
1212
import { styles } from './styles';
1313
import { Colors } from '../../theme';
14-
import { useSilderAnimation, useRadialSlider } from './hooks';
14+
import { useSliderAnimation, useRadialSlider } from './hooks';
1515
import { defaultProps } from './SliderDefaultProps';
1616
import ButtonContent from './ButtonContent';
1717
import CenterContent from './CenterContent';
@@ -50,7 +50,7 @@ const RadialSlider = (props: RadialSliderProps & typeof defaultProps) => {
5050
} = props;
5151

5252
const { panResponder, value, setValue, curPoint, currentRadian, prevValue } =
53-
useSilderAnimation(props);
53+
useSliderAnimation(props);
5454

5555
const {
5656
svgSize,

src/components/RadialSlider/SpeedoMeter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Svg, {
1010
import { View, Platform } from 'react-native';
1111
import type { SpeedoMeterProps } from './types';
1212
import { styles } from './styles';
13-
import { useSilderAnimation, useRadialSlider } from './hooks';
13+
import { useSliderAnimation, useRadialSlider } from './hooks';
1414
import CenterContent from './CenterContent';
1515
import TailText from './TailText';
1616
import LineContent from './LineContent';
@@ -48,7 +48,7 @@ const SpeedoMeter = (
4848
setValue,
4949
curPoint,
5050
currentRadian,
51-
} = useSilderAnimation(props);
51+
} = useSliderAnimation(props);
5252

5353
useEffect(() => {
5454
if (value < min) {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import useSilderAnimation from './useSilderAnimation';
1+
import useSliderAnimation from './useSliderAnimation';
22
import useRadialSlider from './useRadialSlider';
33

4-
export { useRadialSlider, useSilderAnimation };
4+
export { useRadialSlider, useSliderAnimation };

src/components/RadialSlider/hooks/useRadialSlider.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ const useRadialSlider = (props: RadialSliderHookProps) => {
1616
thumbBorderWidth = 5,
1717
min = 0,
1818
max = 200,
19-
variant,
19+
variant = 'default',
2020
step = 1,
21+
startAngle = 270,
2122
} = props;
2223

2324
const centerValue = Math.round((max - min) / 2) as number;
@@ -72,15 +73,19 @@ const useRadialSlider = (props: RadialSliderHookProps) => {
7273
radius,
7374
sliderWidth,
7475
thumbRadius,
75-
thumbBorderWidth
76+
thumbBorderWidth,
77+
startAngle,
78+
variant
7679
);
7780

7881
const endPoint = polarToCartesian(
7982
radianValue,
8083
radius,
8184
sliderWidth,
8285
thumbRadius,
83-
thumbBorderWidth
86+
thumbBorderWidth,
87+
startAngle,
88+
variant
8489
);
8590

8691
const marks = useMemo(() => {

src/components/RadialSlider/hooks/useSilderAnimation.ts renamed to src/components/RadialSlider/hooks/useSliderAnimation.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface StartCartesianProps {
1818
y: number;
1919
}
2020

21-
const useSilderAnimation = (props: RadialSliderAnimationHookProps) => {
21+
const useSliderAnimation = (props: RadialSliderAnimationHookProps) => {
2222
const {
2323
step = 1,
2424
radius = 100,
@@ -30,6 +30,8 @@ const useSilderAnimation = (props: RadialSliderAnimationHookProps) => {
3030
onChange = () => {},
3131
max = 100,
3232
onComplete = () => {},
33+
startAngle = 270,
34+
variant = 'default',
3335
} = props;
3436

3537
let moveStartValue: number;
@@ -78,7 +80,9 @@ const useSilderAnimation = (props: RadialSliderAnimationHookProps) => {
7880
radius,
7981
sliderWidth,
8082
thumbRadius,
81-
thumbBorderWidth as number
83+
thumbBorderWidth as number,
84+
startAngle,
85+
variant
8286
);
8387
return true;
8488
};
@@ -100,7 +104,9 @@ const useSilderAnimation = (props: RadialSliderAnimationHookProps) => {
100104
radius,
101105
sliderWidth,
102106
thumbRadius,
103-
thumbBorderWidth as number
107+
thumbBorderWidth as number,
108+
startAngle,
109+
variant
104110
);
105111

106112
const ratio =
@@ -154,7 +160,9 @@ const useSilderAnimation = (props: RadialSliderAnimationHookProps) => {
154160
radius,
155161
sliderWidth,
156162
thumbRadius,
157-
thumbBorderWidth as number
163+
thumbBorderWidth as number,
164+
startAngle,
165+
variant
158166
);
159167

160168
return {
@@ -167,4 +175,4 @@ const useSilderAnimation = (props: RadialSliderAnimationHookProps) => {
167175
};
168176
};
169177

170-
export default useSilderAnimation;
178+
export default useSliderAnimation;

0 commit comments

Comments
 (0)