@@ -8,7 +8,6 @@ import androidx.compose.ui.graphics.Path
88import androidx.compose.ui.unit.Dp
99import androidx.compose.ui.unit.LayoutDirection
1010import androidx.graphics.shapes.CornerRounding
11- import androidx.graphics.shapes.Cubic
1211import androidx.graphics.shapes.RoundedPolygon
1312
1413fun Path.Companion.smoothRoundedRectangle (
@@ -20,6 +19,7 @@ fun Path.Companion.smoothRoundedRectangle(
2019 bottomRight : Float
2120): Path {
2221 if (size.width <= 0f || size.height <= 0f ) return Path ()
22+ val clampedSmoothing = smoothing.coerceIn(0f , 1f )
2323
2424 return RoundedPolygon (
2525 vertices = floatArrayOf(
@@ -29,10 +29,10 @@ fun Path.Companion.smoothRoundedRectangle(
2929 0f , size.height
3030 ),
3131 perVertexRounding = listOf (
32- CornerRounding (radius = topLeft, smoothing = smoothing ),
33- CornerRounding (radius = topRight, smoothing = smoothing ),
34- CornerRounding (radius = bottomRight, smoothing = smoothing ),
35- CornerRounding (radius = bottomLeft, smoothing = smoothing ),
32+ CornerRounding (radius = topLeft, smoothing = clampedSmoothing ),
33+ CornerRounding (radius = topRight, smoothing = clampedSmoothing ),
34+ CornerRounding (radius = bottomRight, smoothing = clampedSmoothing ),
35+ CornerRounding (radius = bottomLeft, smoothing = clampedSmoothing ),
3636 )
3737 ).toComposePath()
3838}
@@ -105,36 +105,32 @@ class SmoothRoundedCornerShape(
105105 size = size,
106106 topLeft = topLeft,
107107 topRight = topRight,
108- bottomRight = bottomRight,
109108 bottomLeft = bottomLeft,
109+ bottomRight = bottomRight
110110 )
111111 return Outline .Generic (path)
112112 }
113113}
114114
115115fun RoundedPolygon.toComposePath (path : Path = Path ()): Path {
116- pathFromCubicList(path, cubics)
117- return path
118- }
119-
120- private fun pathFromCubicList (
121- path : Path ,
122- cubicList : List <Cubic >
123- ) {
124- var first = true
125116 path.rewind()
126- for (element in cubicList) {
127- if (first) {
128- path.moveTo(element.anchor0X, element.anchor0Y)
129- first = false
130- }
117+
118+ if (cubics.isEmpty()) return path
119+ path.moveTo(cubics[0 ].anchor0X, cubics[0 ].anchor0Y)
120+ for (cubic in cubics) {
131121 path.cubicTo(
132- element.control0X, element.control0Y, element.control1X, element.control1Y,
133- element.anchor1X, element.anchor1Y
122+ cubic.control0X, cubic.control0Y,
123+ cubic.control1X, cubic.control1Y,
124+ cubic.anchor1X, cubic.anchor1Y
134125 )
135126 }
127+
136128 path.close()
129+ return path
137130}
138131
132+ /* *
133+ * Default smoothing value for [SmoothRoundedCornerShape].
134+ */
139135const val DefaultSmoothing = 0.6f
140136
0 commit comments