Skip to content

Commit 79921af

Browse files
committed
Refactor CircularDraggableSlider and LineTime: Improve medium line handling and adjust tick positioning
1 parent 303e205 commit 79921af

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

src/components/circle-time/index.tsx

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ export const CircularDraggableSlider = forwardRef<
9494
const diameter = 2 * Math.PI * radius;
9595
const distanceBetweenTwoTicks = diameter / linesAmount;
9696
const listWidth = diameter;
97+
const mediumLineHeight =
98+
minLineHeight + (maxLineHeight - minLineHeight) / 2;
99+
const mediumLineIndexWithinGroup =
100+
bigLineIndexOffset > 1 ? Math.round(bigLineIndexOffset / 2) : null;
97101

98102
const { runTimer, stopTimer, resetTimer, isTimerEnabled } = useTimer({
99103
progress,
@@ -182,30 +186,28 @@ export const CircularDraggableSlider = forwardRef<
182186
]}>
183187
<Animated.View pointerEvents="none">
184188
{new Array(linesAmount).fill(0).map((_, index) => {
185-
// Determine line type based on position
186-
const isBigLine = index % bigLineIndexOffset === 0;
189+
const groupPosition =
190+
bigLineIndexOffset > 0
191+
? index % bigLineIndexOffset
192+
: index;
193+
const isBigLine =
194+
bigLineIndexOffset > 0 && groupPosition === 0;
195+
const isMediumLine =
196+
!isBigLine &&
197+
mediumLineIndexWithinGroup !== null &&
198+
groupPosition === mediumLineIndexWithinGroup;
187199

188-
// Calculate the midpoint between consecutive big lines
189-
const midpointOffset = bigLineIndexOffset / 2;
190-
const isMediumLine = !isBigLine && index % bigLineIndexOffset === midpointOffset;
200+
const height = isBigLine
201+
? maxLineHeight
202+
: isMediumLine
203+
? mediumLineHeight
204+
: minLineHeight;
191205

192-
// Calculate medium line height as the average of max and min
193-
const mediumLineHeight = (maxLineHeight + minLineHeight) / 2;
194-
195-
// Determine height based on line type
196-
let height: number;
197-
let color: string;
198-
199-
if (isBigLine) {
200-
height = maxLineHeight;
201-
color = bigLineColor;
202-
} else if (isMediumLine) {
203-
height = mediumLineHeight;
204-
color = mediumLineColor;
205-
} else {
206-
height = minLineHeight;
207-
color = lineColor;
208-
}
206+
const color = isBigLine
207+
? bigLineColor
208+
: isMediumLine
209+
? mediumLineColor
210+
: lineColor;
209211

210212
return (
211213
<LineTime
@@ -256,4 +258,4 @@ const styles = StyleSheet.create({
256258
position: 'absolute',
257259
width: '100%',
258260
},
259-
});
261+
});

src/components/circle-time/line-time.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ export const LineTime: React.FC<TickLineProps> = ({
2929
const rStyle = useAnimatedStyle(() => {
3030
const angle =
3131
((2 * Math.PI) / linesAmount) * index - progressRadiants.value;
32-
const x = Math.cos(angle) * radius;
33-
const y = Math.sin(angle) * radius;
32+
// Shift radius so each tick originates at the circle and points outward
33+
const effectiveRadius = radius + height / 2;
34+
const x = Math.cos(angle) * effectiveRadius;
35+
const y = Math.sin(angle) * effectiveRadius;
3436
const rotation = -Math.atan2(x, y);
3537

3638
return {
@@ -63,4 +65,4 @@ export const LineTime: React.FC<TickLineProps> = ({
6365
]}
6466
/>
6567
);
66-
};
68+
};

0 commit comments

Comments
 (0)