Skip to content

Commit 303e205

Browse files
committed
Refactor CircularDraggableSlider: Adjust line heights and add medium line type
1 parent 9d85fb7 commit 303e205

File tree

2 files changed

+45
-36
lines changed

2 files changed

+45
-36
lines changed

App.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,15 @@ export default function App() {
2626
style={{
2727
marginBottom: 256,
2828
}}>
29-
{/* <AnimatedCount
30-
count={animatedNumber}
31-
maxDigits={5}
32-
textDigitWidth={68}
33-
textDigitHeight={120}
34-
fontSize={100}
35-
color="#fff"
36-
gradientAccentColor="#000"
37-
/> */}
3829
</View>
3930
<CircularDraggableSlider
4031
ref={circularSliderRef}
4132
bigLineIndexOffset={10}
4233
linesAmount={LinesAmount}
43-
indicatorColor={'orange'}
44-
maxLineHeight={40}
34+
maxLineHeight={20}
4535
lineColor="rgba(255,255,255,0.5)"
4636
bigLineColor="white"
47-
minLineHeight={30}
37+
minLineHeight={8}
4838
onCompletion={async () => {
4939

5040
}}

src/components/circle-time/index.tsx

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import { forwardRef, useImperativeHandle } from 'react';
44

55
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
66
import Animated, {
7-
cancelAnimation,
8-
interpolate,
9-
useAnimatedReaction,
10-
useDerivedValue,
11-
useSharedValue,
12-
withDecay,
13-
withTiming,
7+
cancelAnimation,
8+
interpolate,
9+
useAnimatedReaction,
10+
useDerivedValue,
11+
useSharedValue,
12+
withDecay,
13+
withTiming,
1414
} from 'react-native-reanimated';
1515

1616
import { useTimer } from '../useTimer';
@@ -37,11 +37,13 @@ export type DraggableSliderProps = {
3737
lineColor?: string;
3838
// Optional: The color of the big lines (default is #c6c6c6)
3939
bigLineColor?: string;
40+
// Optional: The color of the medium lines (default is #c6c6c6)
41+
mediumLineColor?: string;
4042
onCompletion?: () => void;
4143
};
4244

4345
const { height: WindowHeight } = Dimensions.get('window');
44-
const radius = 280;
46+
const radius = 250;
4547

4648
export type CircularDraggableSliderRefType = {
4749
resetTimer: () => void;
@@ -78,9 +80,9 @@ export const CircularDraggableSlider = forwardRef<
7880
bigLineIndexOffset = 10,
7981
lineWidth = 1.5,
8082
onProgressChange,
81-
indicatorColor,
8283
lineColor = '#c6c6c6',
8384
bigLineColor = '#c6c6c6',
85+
mediumLineColor = '#c6c6c6',
8486
onCompletion,
8587
},
8688
ref,
@@ -122,7 +124,7 @@ export const CircularDraggableSlider = forwardRef<
122124
if (isTimerEnabled.value) {
123125
return;
124126
}
125-
progress.value = event.translationX + previousProgress.value;
127+
progress.value = event.translationY + previousProgress.value;
126128
})
127129
.onFinalize(event => {
128130
if (isTimerEnabled.value) {
@@ -134,11 +136,12 @@ export const CircularDraggableSlider = forwardRef<
134136
return;
135137
}
136138
progress.value = withDecay({
137-
velocity: event.velocityX,
139+
velocity: event.velocityY,
138140
});
139141
});
140142

141-
const offset = Math.PI / 2;
143+
// Offset set to 0 for 90-degree rotation (indicator at right side)
144+
const offset = 0;
142145
const progressRadiants = useDerivedValue(() => {
143146
return interpolate(
144147
-progress.value,
@@ -177,21 +180,32 @@ export const CircularDraggableSlider = forwardRef<
177180
],
178181
},
179182
]}>
180-
<View
181-
style={{
182-
position: 'absolute',
183-
top: -maxLineHeight / 2,
184-
zIndex: 10,
185-
height: maxLineHeight * 1.2,
186-
width: lineWidth * 2,
187-
backgroundColor: indicatorColor,
188-
}}
189-
/>
190183
<Animated.View pointerEvents="none">
191184
{new Array(linesAmount).fill(0).map((_, index) => {
185+
// Determine line type based on position
192186
const isBigLine = index % bigLineIndexOffset === 0;
193-
const height = isBigLine ? maxLineHeight : minLineHeight;
194-
const color = isBigLine ? bigLineColor : lineColor;
187+
188+
// Calculate the midpoint between consecutive big lines
189+
const midpointOffset = bigLineIndexOffset / 2;
190+
const isMediumLine = !isBigLine && index % bigLineIndexOffset === midpointOffset;
191+
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+
}
195209

196210
return (
197211
<LineTime
@@ -231,6 +245,11 @@ const styles = StyleSheet.create({
231245
justifyContent: 'center',
232246
position: 'absolute',
233247
width: '100%',
248+
transform: [
249+
{
250+
rotate: '90deg',
251+
},
252+
],
234253
},
235254
timer: {
236255
bottom: 0,

0 commit comments

Comments
 (0)