Skip to content

Commit

Permalink
Merge pull request #35 from VictorKabata/main
Browse files Browse the repository at this point in the history
Added support for compose multiplatform
  • Loading branch information
a914-gowtham authored Oct 30, 2023
2 parents 7682b49 + 72f231b commit 0b6ecf8
Show file tree
Hide file tree
Showing 13 changed files with 600 additions and 12 deletions.
8 changes: 3 additions & 5 deletions .gitignore
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
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ plugins {
android {
compileSdk rootProject.compileSdk

namespace("com.gowtham.compose_ratingbar")

defaultConfig {
applicationId "com.gowtham.compose_ratingbar"
minSdk rootProject.minSdk
Expand Down Expand Up @@ -42,7 +44,6 @@ android {
composeOptions {
kotlinCompilerExtensionVersion compose_compiler
}
namespace 'com.gowtham.compose_ratingbar'
}

dependencies {
Expand All @@ -62,6 +63,7 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.2.1"
implementation project(path: ':ratingbar')

implementation project(path: ':ratingbar-multiplatform')

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.gowtham.compose_ratingbar.MainActivity.Companion.initialRating
import com.gowtham.compose_ratingbar.ui.theme.JetpackComposeTheme
import com.gowtham.ratingbar.RatingBar
import com.gowtham.ratingbar.RatingBarStyle
import com.gowtham.ratingbar.StepSize
import com.gowtham.compose_ratingbar_multiplatform.RatingBar
import com.gowtham.compose_ratingbar_multiplatform.RatingBarStyle
import com.gowtham.compose_ratingbar_multiplatform.StepSize


class MainActivity : ComponentActivity() {

Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ buildscript {
minSdk = 21
targetSdk = 34


compose_version = '1.5.1'
compose_compiler = '1.5.3'

Expand All @@ -20,6 +21,8 @@ plugins {
id 'com.android.application' version '8.1.1' apply false
id 'com.android.library' version '8.1.1' apply false
id 'org.jetbrains.kotlin.android' version '1.9.10' apply false
id 'org.jetbrains.kotlin.multiplatform' version '1.9.10' apply false
id 'org.jetbrains.compose' version '1.5.3' apply false
}

task clean(type: Delete) {
Expand Down
6 changes: 5 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ android.useAndroidX=true
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
-Xopt-in=kotlin.RequiresOptIn
#-Xopt-in=kotlin.RequiresOptIn

# Compose Multiplatform
org.jetbrains.compose.experimental.uikit.enabled=true
kotlin.native.cacheKind=none

GROUP=io.github.a914-gowtham
POM_ARTIFACT_ID=compose-ratingbar
Expand Down
73 changes: 73 additions & 0 deletions ratingbar-multiplatform/build.gradle.kts
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"
}
}
}
}
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
)
)
}

}
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")
}

}
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
}
Loading

0 comments on commit 0b6ecf8

Please sign in to comment.