@@ -9,31 +9,23 @@ import androidx.compose.animation.core.rememberInfiniteTransition
9
9
import androidx.compose.animation.core.tween
10
10
import androidx.compose.foundation.Canvas
11
11
import androidx.compose.foundation.layout.Box
12
- import androidx.compose.foundation.layout.absoluteOffset
13
12
import androidx.compose.foundation.layout.padding
14
13
import androidx.compose.foundation.layout.requiredHeight
15
14
import androidx.compose.foundation.layout.requiredWidth
15
+ import androidx.compose.foundation.layout.size
16
16
import androidx.compose.runtime.Composable
17
17
import androidx.compose.runtime.getValue
18
18
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
25
21
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
30
25
import androidx.compose.ui.tooling.preview.Preview
31
26
import androidx.compose.ui.unit.Dp
32
27
import androidx.compose.ui.unit.dp
33
28
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
37
29
import app.web.drjackycv.presentation.products.choose.CirclePosition
38
30
39
31
@@ -78,56 +70,54 @@ fun ChooseArrowAnimation(
78
70
modifier = Modifier
79
71
.requiredWidth(200 .dp)
80
72
.requiredHeight(100 .dp)
73
+ .size(200 .dp, 100 .dp)
81
74
.padding(16 .dp)
82
75
) {
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
94
82
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(
118
85
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())
130
89
)
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
+ }
131
121
}
132
122
}
133
123
0 commit comments