Skip to content

Commit 05d8984

Browse files
committed
Refactor CircularDraggableSlider: Adjust radius and clean up unused code and comments
1 parent 3a20b45 commit 05d8984

File tree

1 file changed

+4
-32
lines changed

1 file changed

+4
-32
lines changed

src/components/circle-time/index.tsx

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,14 @@ export type DraggableSliderProps = {
4343
};
4444

4545
const { height: WindowHeight } = Dimensions.get('window');
46-
const radius = 250;
46+
const radius = 200;
4747

4848
export type CircularDraggableSliderRefType = {
4949
resetTimer: () => void;
5050
runTimer: (to: number) => void;
5151
stopTimer: () => void;
5252
};
5353

54-
// This one was really challening :)
55-
// The idea is to use a custom pan gesture handler to handle the drag event and update the progress value accordingly.
56-
// Once the user drags, the progress gets converted to radians and then to seconds.
57-
58-
// To map the translation to an angle I've used the interpolate function.
59-
// Here's the idea.
60-
// Let's imagine that you don't see a circle but a straight line | | | | | | | | | | |
61-
// What's the distance between two ticks? It's the straight line length divided by the amount of ticks.
62-
// But actually the straight line length is our diameter of the circle, so it's 2 * PI * radius.
63-
// const distanceBetweenTwoTicks = diameter / linesAmount; -> 2 * PI * radius / linesAmount
64-
65-
// Once we have this knowledge we can remap the progress value to radians.
66-
// ->
67-
// inputRange: [0, listWidth]
68-
// outputRange: [0, 2 * Math.PI]
69-
// I have added an offset in the actual code to rotate the circle by 90 degrees at the very beginning
70-
7154
export const CircularDraggableSlider = forwardRef<
7255
CircularDraggableSliderRefType,
7356
DraggableSliderProps
@@ -168,14 +151,12 @@ export const CircularDraggableSlider = forwardRef<
168151
pointerEvents="none"
169152
style={[
170153
{
171-
position: 'absolute',
172-
justifyContent: 'center',
173-
alignItems: 'center',
174154
height: radius * 2,
175155
width: radius * 2,
156+
right: 50,
176157
transform: [
177158
{
178-
translateY: WindowHeight / 2 - radius / 2,
159+
translateY: WindowHeight / 2 - radius - 36,
179160
},
180161
],
181162
},
@@ -240,20 +221,11 @@ export const CircularDraggableSlider = forwardRef<
240221

241222
const styles = StyleSheet.create({
242223
container: {
243-
alignItems: 'center',
244-
height: '100%',
245-
justifyContent: 'center',
246-
position: 'absolute',
247224
width: '100%',
248-
transform: [
249-
{
250-
rotate: '90deg',
251-
},
252-
],
253225
},
254226
timer: {
255227
bottom: 0,
256228
position: 'absolute',
257229
width: '100%',
258230
},
259-
});
231+
});

0 commit comments

Comments
 (0)