-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from VictorKabata/main
Added support for compose multiplatform
- Loading branch information
Showing
13 changed files
with
600 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
.idea/* | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
*/build/* | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties | ||
*.podspec |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
plugins { | ||
kotlin("multiplatform") | ||
kotlin("native.cocoapods") | ||
id("com.android.library") | ||
id("org.jetbrains.compose") | ||
id("maven-publish") | ||
} | ||
|
||
@OptIn(org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi::class) | ||
kotlin { | ||
targetHierarchy.default() | ||
|
||
android() | ||
|
||
iosX64() | ||
iosArm64() | ||
iosSimulatorArm64() | ||
|
||
jvm() | ||
|
||
cocoapods { | ||
summary = "Some description for the Shared Module" | ||
homepage = "Link to the Shared Module homepage" | ||
version = "1.0" | ||
ios.deploymentTarget = "14.1" | ||
framework { | ||
baseName = "ratingbar-multiplatform" | ||
isStatic = true | ||
} | ||
} | ||
|
||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
implementation(compose.runtime) | ||
implementation(compose.foundation) | ||
implementation(compose.material) | ||
|
||
implementation("org.jetbrains.kotlinx:atomicfu:0.21.0") | ||
} | ||
} | ||
val commonTest by getting { | ||
dependencies { | ||
implementation(kotlin("test")) | ||
} | ||
} | ||
} | ||
} | ||
|
||
android { | ||
namespace = "com.gowtham.compose_ratingbar_multiplatform" | ||
compileSdk = 33 | ||
defaultConfig { | ||
minSdk = 21 | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} | ||
} | ||
|
||
afterEvaluate { | ||
publishing { | ||
publications.withType<MavenPublication> { | ||
pom { | ||
groupId = "com.gowtham.composeratingbar" | ||
artifactId = "compose-ratingbar-multiplatform" | ||
version = "1.0.0" | ||
} | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...commonMain/kotlin/com/gowtham/compose_ratingbar_multiplatform/FractionalRectangleShape.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,31 @@ | ||
package com.gowtham.compose_ratingbar_multiplatform | ||
|
||
import androidx.compose.runtime.Stable | ||
import androidx.compose.ui.geometry.Rect | ||
import androidx.compose.ui.geometry.Size | ||
import androidx.compose.ui.graphics.Outline | ||
import androidx.compose.ui.graphics.Shape | ||
import androidx.compose.ui.unit.Density | ||
import androidx.compose.ui.unit.LayoutDirection | ||
|
||
@Stable | ||
class FractionalRectangleShape( | ||
private val startFraction: Float, | ||
private val endFraction: Float | ||
) : Shape { | ||
override fun createOutline( | ||
size: Size, | ||
layoutDirection: LayoutDirection, | ||
density: Density | ||
): Outline { | ||
return Outline.Rectangle( | ||
Rect( | ||
left = (startFraction * size.width).coerceAtMost(size.width - 1f), | ||
top = 0f, | ||
right = (endFraction * size.width).coerceAtLeast(1f), | ||
bottom = size.height | ||
) | ||
) | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...iplatform/src/commonMain/kotlin/com/gowtham/compose_ratingbar_multiplatform/LogMessage.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,15 @@ | ||
package com.gowtham.compose_ratingbar_multiplatform | ||
|
||
object LogMessage { | ||
|
||
private const val logVisible = false | ||
|
||
internal fun v(msg: String) { | ||
if (logVisible) println("Compose-Ratingbar :$msg") | ||
} | ||
|
||
internal fun e(msg: String) { | ||
if (logVisible) println("Compose-Ratingbar: $msg") | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...tform/src/commonMain/kotlin/com/gowtham/compose_ratingbar_multiplatform/PathExtensions.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,48 @@ | ||
package com.gowtham.compose_ratingbar_multiplatform | ||
|
||
import androidx.compose.ui.geometry.Size | ||
import androidx.compose.ui.graphics.Path | ||
import kotlin.math.PI | ||
import kotlin.math.cos | ||
import kotlin.math.sin | ||
|
||
fun Path.addStar( | ||
size: Size, | ||
spikes: Int = 5, | ||
outerRadiusFraction: Float = 0.5f, | ||
innerRadiusFraction: Float = 0.2f | ||
): Path { | ||
val outerRadius = size.minDimension * outerRadiusFraction | ||
val innerRadius = size.minDimension * innerRadiusFraction | ||
|
||
val centerX = size.width / 2 | ||
val centerY = size.height / 2 | ||
|
||
var totalAngle = PI / 2 // Since we start at the top center, the initial angle will be 90° | ||
val degreesPerSection = (2 * PI) / spikes | ||
|
||
moveTo(centerX, 0f) // Starts at the top center of the bounds | ||
|
||
var x: Double | ||
var y: Double | ||
|
||
for (i in 1..spikes) { | ||
// Line going inwards from outerCircle to innerCircle | ||
totalAngle += degreesPerSection / 2 | ||
x = centerX + cos(totalAngle) * innerRadius | ||
y = centerY - sin(totalAngle) * innerRadius | ||
lineTo(x.toFloat(), y.toFloat()) | ||
|
||
|
||
// Line going outwards from innerCircle to outerCircle | ||
totalAngle += degreesPerSection / 2 | ||
x = centerX + cos(totalAngle) * outerRadius | ||
y = centerY - sin(totalAngle) * outerRadius | ||
lineTo(x.toFloat(), y.toFloat()) | ||
} | ||
|
||
// Path should be closed to ensure it's not an open shape | ||
close() | ||
|
||
return this | ||
} |
Oops, something went wrong.