-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
218 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Fri Jul 30 21:49:10 CEST 2021 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip | ||
distributionPath=wrapper/dists | ||
zipStorePath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
library/src/main/java/app/juky/squircleview/utils/SquircleComposeShape.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package app.juky.squircleview.utils | ||
|
||
|
||
import android.graphics.RectF | ||
import androidx.annotation.IntRange | ||
import androidx.compose.ui.geometry.Size | ||
import androidx.compose.ui.graphics.Outline | ||
import androidx.compose.ui.graphics.Path | ||
import androidx.compose.ui.graphics.Shape | ||
import androidx.compose.ui.unit.Density | ||
import androidx.compose.ui.unit.LayoutDirection | ||
import app.juky.squircleview.data.Constants.DEFAULT_CORNER_SMOOTHING | ||
import app.juky.squircleview.utils.SquirclePath.getRadiusByHeightOrWidth | ||
|
||
object SquircleComposeShape { | ||
fun getSquirclePath( | ||
size: Size, | ||
@IntRange(from = 0, to = DEFAULT_CORNER_SMOOTHING) | ||
cornerSmoothing: Int = DEFAULT_CORNER_SMOOTHING.toInt() | ||
): Path { | ||
return getSquirclePath( | ||
rect = RectF(0f, 0f, size.width, size.height), | ||
width = size.width.toInt(), | ||
height = size.height.toInt(), | ||
cornerSmoothing = cornerSmoothing | ||
) | ||
} | ||
|
||
fun getSquirclePath( | ||
rect: RectF, | ||
width: Int, | ||
height: Int, | ||
@IntRange(from = 0, to = DEFAULT_CORNER_SMOOTHING) | ||
cornerSmoothing: Int = DEFAULT_CORNER_SMOOTHING.toInt() | ||
): Path { | ||
val radius = getRadiusByHeightOrWidth(height, width, cornerSmoothing) | ||
|
||
val startX = rect.left | ||
val endX = rect.right | ||
val startY = rect.top | ||
val endY = rect.bottom | ||
|
||
val path = Path() | ||
|
||
path.moveTo(x = startX, y = (height / 2).toFloat()) | ||
|
||
// Top left corner | ||
path.cubicTo( | ||
x1 = startX, | ||
y1 = startY, | ||
x2 = startX, | ||
y2 = startY, | ||
x3 = startX + radius, | ||
y3 = startY | ||
) | ||
|
||
// Top line | ||
path.lineTo(x = endX - radius, y = startY) | ||
|
||
// Top right corner | ||
path.cubicTo( | ||
x1 = endX, | ||
y1 = startY, | ||
x2 = endX, | ||
y2 = startY, | ||
x3 = endX, | ||
y3 = startY + radius, | ||
) | ||
|
||
// Right line | ||
path.lineTo(x = endX, y = endY - radius) | ||
|
||
// Bottom right corner | ||
path.cubicTo( | ||
x1 = endX, | ||
y1 = endY, | ||
x2 = endX, | ||
y2 = endY, | ||
x3 = endX - radius, | ||
y3 = endY, | ||
) | ||
|
||
// Bottom line | ||
path.lineTo(x = startX + radius, y = endY) | ||
|
||
// Bottom left corner | ||
path.cubicTo( | ||
x1 = startX, | ||
y1 = endY, | ||
x2 = startX, | ||
y2 = endY, | ||
x3 = startX, | ||
y3 = endY - radius, | ||
) | ||
|
||
path.lineTo(x = startX, y = (height / 2).toFloat()) | ||
|
||
return path | ||
} | ||
|
||
class SquircleComposeShape( | ||
@IntRange(from = 0, to = DEFAULT_CORNER_SMOOTHING) | ||
val cornerSmoothing: Int = DEFAULT_CORNER_SMOOTHING.toInt() | ||
) : Shape { | ||
override fun createOutline(size: Size, layoutDirection: LayoutDirection, density: Density): Outline { | ||
return Outline.Generic( | ||
getSquirclePath( | ||
rect = RectF(0f, 0f, size.width, size.height), | ||
width = size.width.toInt(), | ||
height = size.height.toInt(), | ||
cornerSmoothing = cornerSmoothing | ||
) | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters