Skip to content

Commit 1eaf112

Browse files
committed
Refactor CircularDraggableSlider and TimeRange components: Remove unused overlay logic and improve scroll handling for smoother duration updates
1 parent c5cad85 commit 1eaf112

File tree

2 files changed

+10
-54
lines changed

2 files changed

+10
-54
lines changed

src/components/circle-time/index.tsx

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import Animated, {
1010
useAnimatedReaction,
1111
useAnimatedStyle,
1212
useDerivedValue,
13-
useSharedValue,
14-
withTiming,
13+
useSharedValue
1514
} from 'react-native-reanimated';
1615

1716
import { LineTime } from './line-time';
@@ -73,33 +72,7 @@ export const CircularDraggableSlider = forwardRef<
7372
);
7473
}, [listWidth]);
7574

76-
const overlayStyle = useAnimatedStyle(() => {
77-
const angleStep = (2 * Math.PI) / linesAmount;
78-
const hourIndexRatio = progressRadiants.value / (angleStep * bigLineIndexOffset);
79-
const boundedHourIndex = Math.max(
80-
1,
81-
Math.min(HOUR_LABELS_AMOUNT, Math.round(hourIndexRatio)),
82-
);
83-
const requestedTickIndex = boundedHourIndex * bigLineIndexOffset;
84-
if (requestedTickIndex > linesAmount) {
85-
return { opacity: 0 };
86-
}
87-
88-
const targetTickIndex = Math.min(linesAmount - 1, requestedTickIndex);
89-
const labelRadius = radius + LABEL_RADIUS_OFFSET;
90-
const angle = angleStep * targetTickIndex - progressRadiants.value;
91-
const x = Math.cos(angle) * labelRadius;
92-
const y = Math.sin(angle) * labelRadius;
93-
94-
return {
95-
opacity: 1,
96-
transform: [
97-
{ translateX: x - LABEL_WIDTH / 2 },
98-
{ translateY: y - LABEL_HEIGHT / 2 },
99-
],
100-
};
101-
}, [bigLineIndexOffset, linesAmount, radius]);
102-
75+
10376
useAnimatedReaction(
10477
() => selectedDuration?.value ?? null,
10578
duration => {
@@ -115,7 +88,8 @@ export const CircularDraggableSlider = forwardRef<
11588
const targetProgress = -distanceBetweenTwoTicks * targetIndex;
11689

11790
cancelAnimation(progress);
118-
progress.value = withTiming(targetProgress, { duration: 250 });
91+
// Use immediate update for real-time synchronization during scroll
92+
progress.value = targetProgress;
11993
},
12094
[bigLineIndexOffset, distanceBetweenTwoTicks, selectedDuration],
12195
);
@@ -190,26 +164,6 @@ export const CircularDraggableSlider = forwardRef<
190164
/>
191165
);
192166
})}
193-
<Animated.View
194-
pointerEvents="none"
195-
style={[styles.hourLabelOverlay, overlayStyle]}
196-
>
197-
<LinearGradient
198-
start={{
199-
x: 0,
200-
y: 0
201-
}}
202-
end={{
203-
x: 0,
204-
y: 1
205-
}}
206-
colors={['transparent','#00000080', '#000000', '#000000', '#000000' , '#00000080', 'transparent']}
207-
style={{
208-
height: "100%",
209-
width: "100%",
210-
}}
211-
/>
212-
</Animated.View>
213167
</Animated.View>
214168
<LinearGradient
215169
colors={['#000000', '#000000', '#000000', '#00000070', 'transparent']}
@@ -308,7 +262,7 @@ const styles = StyleSheet.create({
308262
position: 'absolute',
309263
width: LABEL_WIDTH,
310264
height: LABEL_HEIGHT,
311-
backgroundColor: '#000',
265+
// backgroundColor: 'red',
312266
borderRadius: LABEL_HEIGHT / 2,
313267
zIndex: 1,
314268
left: 10,

src/components/time-range/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,16 @@ export const TimeRange: React.FC<TimeRangeProps> = ({
4040
const onScroll = useAnimatedScrollHandler({
4141
onScroll: event => {
4242
const { contentOffset } = event;
43+
// Interpolate to get smooth continuous values during scroll
4344
const interpolatedDuration = interpolate(
4445
contentOffset.y,
4546
DurationSnapOffsets,
4647
DurationOptions,
4748
);
49+
// Clamp to valid range but keep fractional values for smooth animation
4850
const clampedDuration = Math.min(
4951
DurationOptions[DurationOptions.length - 1],
50-
Math.max(DurationOptions[0], Math.round(interpolatedDuration)),
52+
Math.max(DurationOptions[0], interpolatedDuration),
5153
);
5254
onDurationChange?.(clampedDuration);
5355
},
@@ -76,7 +78,7 @@ export const TimeRange: React.FC<TimeRangeProps> = ({
7678
style={{
7779
position: 'absolute',
7880
top: 0,
79-
left: 0,
81+
left: 40,
8082
right: 0,
8183
height: 16,
8284
}}
@@ -86,7 +88,7 @@ export const TimeRange: React.FC<TimeRangeProps> = ({
8688
style={{
8789
position: 'absolute',
8890
bottom: 0,
89-
left: 0,
91+
left: 40,
9092
right: 0,
9193
height: 16,
9294
}}

0 commit comments

Comments
 (0)