Skip to content

Commit d3afa93

Browse files
committed
Improve choose arrow view
1 parent ce8d0fa commit d3afa93

File tree

1 file changed

+49
-59
lines changed

1 file changed

+49
-59
lines changed

Diff for: presentation/src/main/kotlin/app/web/drjackycv/presentation/base/view/ChooseArrowView.kt

+49-59
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,23 @@ import androidx.compose.animation.core.rememberInfiniteTransition
99
import androidx.compose.animation.core.tween
1010
import androidx.compose.foundation.Canvas
1111
import androidx.compose.foundation.layout.Box
12-
import androidx.compose.foundation.layout.absoluteOffset
1312
import androidx.compose.foundation.layout.padding
1413
import androidx.compose.foundation.layout.requiredHeight
1514
import androidx.compose.foundation.layout.requiredWidth
15+
import androidx.compose.foundation.layout.size
1616
import androidx.compose.runtime.Composable
1717
import androidx.compose.runtime.getValue
1818
import androidx.compose.ui.Modifier
19-
import androidx.compose.ui.draw.rotate
20-
import androidx.compose.ui.geometry.Offset
21-
import androidx.compose.ui.geometry.Rect
22-
import androidx.compose.ui.graphics.Outline
23-
import androidx.compose.ui.graphics.Paint
24-
import androidx.compose.ui.graphics.PaintingStyle
19+
import androidx.compose.ui.geometry.CornerRadius
20+
import androidx.compose.ui.graphics.Color
2521
import androidx.compose.ui.graphics.Path
26-
import androidx.compose.ui.graphics.PathEffect
27-
import androidx.compose.ui.graphics.StrokeCap
28-
import androidx.compose.ui.graphics.drawOutline
29-
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
22+
import androidx.compose.ui.graphics.drawscope.Stroke
23+
import androidx.compose.ui.graphics.drawscope.rotate
24+
import androidx.compose.ui.graphics.drawscope.translate
3025
import androidx.compose.ui.tooling.preview.Preview
3126
import androidx.compose.ui.unit.Dp
3227
import androidx.compose.ui.unit.dp
3328
import app.web.drjackycv.presentation.base.theme.purple600
34-
import app.web.drjackycv.presentation.base.theme.red200
35-
import app.web.drjackycv.presentation.extension.lineTo
36-
import app.web.drjackycv.presentation.extension.percentOf
3729
import app.web.drjackycv.presentation.products.choose.CirclePosition
3830

3931

@@ -78,56 +70,54 @@ fun ChooseArrowAnimation(
7870
modifier = Modifier
7971
.requiredWidth(200.dp)
8072
.requiredHeight(100.dp)
73+
.size(200.dp, 100.dp)
8174
.padding(16.dp)
8275
) {
83-
val rect = Rect(Offset.Zero, size)
84-
val percent = 65.percentOf(rect.minDimension)
85-
val ovalPath = Path().apply {
86-
with(rect) {
87-
lineTo(topRight)
88-
lineTo(bottomRight)
89-
lineTo(bottomLeft)
90-
lineTo(topLeft)
91-
close()
92-
}
93-
}
76+
val canvasWidth = size.width
77+
val canvasHeight = size.height
78+
val circleRadius = 30.dp.toPx()
79+
val arrowLength = 20.dp.toPx()
80+
val arrowThickness = 3.dp.toPx()
81+
val padding = 4.dp.toPx() // Add padding to prevent overlap
9482

95-
drawIntoCanvas { canvas ->
96-
canvas.drawOutline(
97-
outline = Outline.Generic(ovalPath),
98-
paint = Paint().apply {
99-
color = purple600
100-
strokeWidth = 10f
101-
pathEffect = PathEffect.cornerPathEffect(percent)
102-
style = PaintingStyle.Stroke
103-
}
104-
)
105-
}
106-
}
107-
108-
Canvas(
109-
modifier = Modifier
110-
.requiredWidth(96.dp)
111-
.requiredHeight(96.dp)
112-
.padding(20.dp)
113-
.absoluteOffset(x = offsetAnimation, y = 2.dp)
114-
.rotate(angle)
115-
) {
116-
drawCircle(red200)
117-
drawLine(
83+
// Draw the rounded rectangle
84+
drawRoundRect(
11885
color = purple600,
119-
start = Offset(82f, 105f),
120-
end = Offset(54f, 77f),
121-
strokeWidth = 8f,
122-
cap = StrokeCap.Round
123-
)
124-
drawLine(
125-
color = purple600,
126-
start = Offset(54f, 77f),
127-
end = Offset(82f, 49f),
128-
strokeWidth = 8f,
129-
cap = StrokeCap.Round
86+
size = size,
87+
cornerRadius = CornerRadius(50.dp.toPx(), 50.dp.toPx()),
88+
style = Stroke(width = 4.dp.toPx())
13089
)
90+
91+
// Calculate the circle's position with padding
92+
val circleX = padding + circleRadius + offsetAnimation.toPx()
93+
val circleY = canvasHeight / 2
94+
95+
// Draw the red circle
96+
translate(left = circleX - circleRadius, top = circleY - circleRadius) {
97+
rotate(
98+
angle,
99+
pivot = androidx.compose.ui.geometry.Offset(circleRadius, circleRadius)
100+
) {
101+
drawCircle(
102+
color = Color(0xFFE27170),
103+
radius = circleRadius,
104+
center = androidx.compose.ui.geometry.Offset(circleRadius, circleRadius)
105+
)
106+
107+
// Draw the ">" arrow inside the circle
108+
val arrowPath = Path().apply {
109+
moveTo(circleRadius - arrowLength / 4, circleRadius - arrowLength / 2)
110+
lineTo(circleRadius + arrowLength / 4, circleRadius)
111+
lineTo(circleRadius - arrowLength / 4, circleRadius + arrowLength / 2)
112+
}
113+
114+
drawPath(
115+
path = arrowPath,
116+
color = Color(0xFF3F0071),
117+
style = Stroke(width = arrowThickness)
118+
)
119+
}
120+
}
131121
}
132122
}
133123

0 commit comments

Comments
 (0)