Skip to content

Commit 20bb4e6

Browse files
Merge pull request #18 from SimformSolutionsPvtLtd/fix/UNT-T8179
Solve RadialSlider lack issue and update README file
2 parents 46474a2 + 9c325f4 commit 20bb4e6

File tree

8 files changed

+123
-113
lines changed

8 files changed

+123
-113
lines changed

README.md

Lines changed: 77 additions & 78 deletions
Large diffs are not rendered by default.

src/components/RadialSlider/LineContent.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ const LineContent = (props: RadialSliderProps & typeof defaultProps) => {
8181
? false
8282
: isMarkerLine;
8383

84+
const radialCircleLineRotation = isRadialCircleVariant ? 86 : 90;
85+
8486
return (
8587
<G key={index.toString()}>
8688
{(index % lineSpace === 0 ||
@@ -97,7 +99,9 @@ const LineContent = (props: RadialSliderProps & typeof defaultProps) => {
9799
: radius + lineHeight
98100
}
99101
x2={radius + lineHeight / 2 + isSpeedoMarker}
100-
transform={`rotate(${index + 90 + angle})`}
102+
transform={`rotate(${
103+
index + radialCircleLineRotation + angle
104+
})`}
101105
strokeWidth={2}
102106
stroke={
103107
activeIndex > index ||

src/components/RadialSlider/MarkerValueContent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const MarkerValueContent = (
2020
markerValueColor,
2121
} = props;
2222

23-
const { lineHeight, lineCount, angle, marks } = useRadialSlider(props);
23+
const { lineHeight, lineCount, angle, marks, centerValue } =
24+
useRadialSlider(props);
2425

2526
return (
2627
<>
@@ -43,7 +44,6 @@ const MarkerValueContent = (
4344
const markerInnerValue = Math.round(
4445
(max / markerValueInterval) as number
4546
);
46-
const centerValue = Math.round((max - min) / 2) as number;
4747

4848
// if number is below 99(two digit number) then we set -2 for x property in svg Text
4949
const twoDigitsPositionValue = max < 99 ? -2 : -3;

src/components/RadialSlider/RadialSlider.tsx

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Svg, {
88
Color,
99
NumberProp,
1010
} from 'react-native-svg';
11-
import { View, Platform } from 'react-native';
11+
import { View, Platform, StyleSheet } from 'react-native';
1212
import type { RadialSliderProps } from './types';
1313
import { styles } from './styles';
1414
import { Colors } from '../../theme';
@@ -44,6 +44,8 @@ const RadialSlider = (props: RadialSliderProps & typeof defaultProps) => {
4444
isHideTailText,
4545
isHideButtons,
4646
isHideLines,
47+
leftIconStyle,
48+
rightIconStyle,
4749
} = props;
4850

4951
const { panResponder, value, setValue, curPoint, currentRadian } =
@@ -55,12 +57,25 @@ const RadialSlider = (props: RadialSliderProps & typeof defaultProps) => {
5557
startPoint,
5658
endPoint,
5759
startRadian,
58-
leftButtonStyle,
59-
rightButtonStyle,
6060
radianValue,
6161
isRadialCircleVariant,
62+
centerValue,
6263
} = useRadialSlider(props);
6364

65+
const leftButtonStyle = StyleSheet.flatten([
66+
leftIconStyle,
67+
(disabled || min === value) && {
68+
opacity: 0.5,
69+
},
70+
]);
71+
72+
const rightButtonStyle = StyleSheet.flatten([
73+
rightIconStyle,
74+
(disabled || max === value) && {
75+
opacity: 0.5,
76+
},
77+
]);
78+
6479
const onLayout = () => {
6580
const ref = containerRef.current as any;
6681
if (ref) {
@@ -76,6 +91,14 @@ const RadialSlider = (props: RadialSliderProps & typeof defaultProps) => {
7691
}
7792
};
7893

94+
const circleXPosition = isRadialCircleVariant
95+
? centerValue < value
96+
? -7
97+
: 4
98+
: 0;
99+
100+
const strokeLinecap = isRadialCircleVariant ? 'square' : 'round';
101+
79102
return (
80103
<View
81104
onLayout={onLayout}
@@ -112,7 +135,7 @@ const RadialSlider = (props: RadialSliderProps & typeof defaultProps) => {
112135
strokeWidth={sliderWidth}
113136
stroke={sliderTrackColor}
114137
fill="none"
115-
strokeLinecap="round"
138+
strokeLinecap={strokeLinecap}
116139
d={`M${startPoint.x},${startPoint.y} A ${radius},${radius},0,${
117140
startRadian - radianValue >= Math.PI ? '1' : '0'
118141
},1,${endPoint.x},${endPoint.y}`}
@@ -121,13 +144,13 @@ const RadialSlider = (props: RadialSliderProps & typeof defaultProps) => {
121144
strokeWidth={sliderWidth}
122145
stroke="url(#gradient)"
123146
fill="none"
124-
strokeLinecap="round"
147+
strokeLinecap={strokeLinecap}
125148
d={`M${startPoint.x},${startPoint.y} A ${radius},${radius},0,${
126149
startRadian - currentRadian >= Math.PI ? '1' : '0'
127150
},1,${curPoint.x},${curPoint.y}`}
128151
/>
129152
<Circle
130-
cx={curPoint.x}
153+
cx={curPoint.x + circleXPosition}
131154
cy={curPoint.y}
132155
r={thumbRadius}
133156
fill={thumbColor || thumbBorderColor}

src/components/RadialSlider/SliderDefaultProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const defaultProps = {
3636
valueStyle: {},
3737
unitStyle: {},
3838
buttonContainerStyle: {},
39-
letIconStyle: {},
39+
leftIconStyle: {},
4040
rightIconStyle: {},
4141
openingRadian: Math.PI / 3,
4242
dynamicMarker: false,

src/components/RadialSlider/SpeedometerDefaultProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const defaultSpeedoMeterProps = {
3636
valueStyle: {},
3737
unitStyle: {},
3838
buttonContainerStyle: {},
39-
letIconStyle: {},
39+
leftIconStyle: {},
4040
rightIconStyle: {},
4141
openingRadian: Math.PI / 3,
4242
dynamicMarker: false,

src/components/RadialSlider/hooks/useRadialSlider.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useMemo } from 'react';
2-
import { StyleSheet } from 'react-native';
32
import {
43
createRange,
54
getExtraSize,
@@ -17,24 +16,24 @@ const useRadialSlider = (props: RadialSliderProps & typeof defaultProps) => {
1716
thumbRadius,
1817
thumbBorderWidth,
1918
min,
20-
letIconStyle,
21-
disabled,
22-
value,
23-
rightIconStyle,
2419
max,
2520
variant,
2621
step,
2722
} = props;
2823

24+
const centerValue = Math.round((max - min) / 2) as number;
25+
2926
const isRadialCircleVariant = variant === appConstants.radialCircleSlider;
3027

31-
const radianValue = isRadialCircleVariant ? 0.01 : openingRadian;
28+
const radianValue = isRadialCircleVariant ? 0.057 : openingRadian;
3229

3330
const isMarkerVariant = variant === appConstants.speedoMeterMarker;
3431

3532
const angle = (radianValue * 180.0) / Math.PI;
3633

37-
const lineCount = (360 - angle * 2) as number;
34+
const addRadialCircleCount = isRadialCircleVariant ? 6 : 0;
35+
36+
const lineCount = (360 - angle * 2 + addRadialCircleCount) as number;
3837

3938
const lines = createRange(min, lineCount + min, 1);
4039

@@ -65,20 +64,6 @@ const useRadialSlider = (props: RadialSliderProps & typeof defaultProps) => {
6564
thumbBorderWidth
6665
);
6766

68-
const leftButtonStyle = StyleSheet.flatten([
69-
letIconStyle,
70-
(disabled || min === value) && {
71-
opacity: 0.5,
72-
},
73-
]);
74-
75-
const rightButtonStyle = StyleSheet.flatten([
76-
rightIconStyle,
77-
(disabled || max === value) && {
78-
opacity: 0.5,
79-
},
80-
]);
81-
8267
const marks = useMemo(() => {
8368
const stepsLength = Math.round((max - min) / step);
8469

@@ -102,12 +87,11 @@ const useRadialSlider = (props: RadialSliderProps & typeof defaultProps) => {
10287
startPoint,
10388
endPoint,
10489
startRadian,
105-
leftButtonStyle,
106-
rightButtonStyle,
10790
radianValue,
10891
isMarkerVariant,
10992
marks,
11093
isRadialCircleVariant,
94+
centerValue,
11195
};
11296
};
11397

src/components/RadialSlider/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export interface RadialSliderProps {
131131
/**
132132
* Left Icon styling.
133133
*/
134-
letIconStyle?: StyleProp<ViewStyle>;
134+
leftIconStyle?: StyleProp<ViewStyle>;
135135
/**
136136
* Right Icon styling.
137137
*/

0 commit comments

Comments
 (0)