Skip to content

Commit cecc6a1

Browse files
committed
Refactor CircleTime and TimeRange components: Clean up CircleTime rendering, adjust gradient colors, and enhance TimeRange with initial scroll index and item layout
1 parent 6cdc2ad commit cecc6a1

File tree

6 files changed

+51
-27
lines changed

6 files changed

+51
-27
lines changed

App.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ export default function App() {
2020
<Header />
2121
<Queued />
2222
<View style={styles.container}>
23-
<CircleTime selectedDuration={selectedDuration}
24-
/>
23+
<CircleTime selectedDuration={selectedDuration}/>
2524
<TimeRange selectedDuration={selectedDuration} />
2625
</View>
2726
<Footer />

assets/images/avatar.jpg

-771 KB
Loading

src/components/circle-time/index.tsx

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ export const CircleTime: React.FC<DraggableSliderProps> = ({
100100
]}>
101101

102102
<Animated.View pointerEvents="none">
103-
104103
{lineIndices.map(index => {
105104
const isBigLine = index % bigLineIndexOffset === 0;
106105
const midpointOffset = bigLineIndexOffset / 2;
@@ -133,11 +132,11 @@ export const CircleTime: React.FC<DraggableSliderProps> = ({
133132
/>
134133
);
135134
})}
135+
136136
{hourLabels.map(({ label, tickIndex }) => {
137137
if (tickIndex > linesAmount) {
138138
return null;
139139
}
140-
141140
return (
142141
<HourLabel
143142
key={label}
@@ -151,7 +150,7 @@ export const CircleTime: React.FC<DraggableSliderProps> = ({
151150
})}
152151
</Animated.View>
153152
<LinearGradient
154-
colors={['#000000', '#000000', '#000000', '#00000070', 'transparent']}
153+
colors={['#000000', '#000000', '#000000', '#000000f9', '#000000b2', 'transparent']}
155154
start={{
156155
x: 0,
157156
y: 0
@@ -166,20 +165,32 @@ export const CircleTime: React.FC<DraggableSliderProps> = ({
166165
width: radius * 2 + 94,
167166
left: -220,
168167
top: -(WindowHeight / 2 - radius + 8),
169-
// backgroundColor: 'red',
170-
borderRadius: 1000
168+
borderRadius: 1000,
169+
alignItems: "flex-end",
170+
justifyContent: "center",
171171
}}
172-
/>
172+
>
173+
<LinearGradient
174+
colors={['transparent', '#000000', '#000000', '#000000', 'transparent']}
175+
start={{
176+
x: 0,
177+
y: 0
178+
}}
179+
end={{
180+
x: 0,
181+
y: 1.1
182+
}}
183+
style={{
184+
height: LABEL_HEIGHT,
185+
width: LABEL_WIDTH,
186+
borderRadius: 1000,
187+
zIndex: 1,
188+
left: 4,
189+
top: -3
190+
}}
191+
/>
192+
</LinearGradient>
173193
</View>
174-
<Animated.View
175-
pointerEvents="none"
176-
style={[
177-
{
178-
height: WindowHeight / 2,
179-
},
180-
styles.timer,
181-
]}
182-
/>
183194
</View>
184195
);
185196
};
@@ -193,7 +204,7 @@ type HourLabelProps = {
193204
};
194205

195206
const LABEL_WIDTH = 60;
196-
const LABEL_HEIGHT = 28;
207+
const LABEL_HEIGHT = 30;
197208
const LABEL_RADIUS_OFFSET = 40;
198209

199210
const HourLabel: React.FC<HourLabelProps> = ({

src/components/footer/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const styles = StyleSheet.create({
5252
paddingVertical: 16,
5353
alignItems: 'center',
5454
justifyContent: 'center',
55-
borderWidth: 1,
55+
borderWidth: 2,
5656
borderColor: '#333333',
5757
},
5858
backButtonText: {

src/components/header/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const Header = () => {
2929
<View style={{
3030
alignItems: "center",
3131
flexDirection: "row",
32-
columnGap: 6
32+
columnGap: 8
3333
}}>
3434
<Image source={require("../../../assets/images/avatar.jpg")} style={{
3535
width: 32,
@@ -47,7 +47,7 @@ export const Header = () => {
4747
justifyContent: "center",
4848
alignItems: "center",
4949
}}>
50-
<FontAwesome name="bell" size={14} color="#63666aff" />
50+
<FontAwesome name="gear" size={16} color="#63666aff" />
5151
</View>
5252

5353
</View>;

src/components/time-range/index.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const TimeRangeHeight = ITEM_HEIGHT;
1919
const ArrowWrapperHeight = 24 * SCALE_FACTOR;
2020
const ArrowIconSize = 10 * SCALE_FACTOR;
2121
const LabelFontSize = 28 * SCALE_FACTOR;
22-
const ListWidth = 100 * SCALE_FACTOR;
22+
const ListWidth = 100 * SCALE_FACTOR - 66;
2323
const ContainerHeight = TimeRangeHeight + ArrowWrapperHeight * 2;
2424
const DurationOptions = Array.from({ length: 10 }, (_, index) => index + 1);
2525
const DurationSnapOffsets = DurationOptions.map((_, index) => index * ITEM_HEIGHT);
@@ -37,6 +37,19 @@ export const TimeRange: React.FC<TimeRangeProps> = ({
3737
[],
3838
);
3939

40+
const getItemLayout = useCallback(
41+
(_: unknown, index: number) => ({
42+
length: ITEM_HEIGHT,
43+
offset: ITEM_HEIGHT * index,
44+
index,
45+
}),
46+
[],
47+
);
48+
49+
const initialScrollIndex = Math.max(
50+
0,
51+
DurationOptions.indexOf(Math.round(selectedDuration.value)),
52+
);
4053

4154
const onScroll = useAnimatedScrollHandler({
4255
onScroll: event => {
@@ -68,6 +81,8 @@ export const TimeRange: React.FC<TimeRangeProps> = ({
6881
scrollEventThrottle={16}
6982
decelerationRate="fast"
7083
snapToAlignment="center"
84+
getItemLayout={getItemLayout}
85+
initialScrollIndex={initialScrollIndex}
7186
snapToOffsets={DurationSnapOffsets}
7287
contentContainerStyle={styles.scrollViewContent}
7388
showsVerticalScrollIndicator={false}
@@ -81,7 +96,7 @@ export const TimeRange: React.FC<TimeRangeProps> = ({
8196
style={{
8297
position: 'absolute',
8398
top: 0,
84-
left: 40,
99+
left: 0,
85100
right: 0,
86101
height: 16,
87102
}}
@@ -91,7 +106,7 @@ export const TimeRange: React.FC<TimeRangeProps> = ({
91106
style={{
92107
position: 'absolute',
93108
bottom: 0,
94-
left: 40,
109+
left: 0,
95110
right: 0,
96111
height: 16,
97112
}}
@@ -109,9 +124,8 @@ const styles = StyleSheet.create({
109124
container: {
110125
height: ContainerHeight,
111126
position: "absolute",
112-
width: ListWidth - 30,
113-
right: 0,
114-
justifyContent: 'space-between',
127+
width: ListWidth,
128+
right: 0
115129
},
116130
arrowWrapper: {
117131
alignItems: 'center',

0 commit comments

Comments
 (0)