diff --git a/.idea/misc.xml b/.idea/misc.xml index 61659b1..49539a6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -65,7 +65,7 @@ - + diff --git a/app/build.gradle b/app/build.gradle index 5b5ad13..8c40486 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,11 +32,11 @@ android { } } compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = JavaVersion.VERSION_11.toString() + jvmTarget = JavaVersion.VERSION_17.toString() } buildFeatures { compose true @@ -54,7 +54,7 @@ dependencies { implementation "androidx.compose.material:material:$compose_version" implementation "androidx.compose.ui:ui-tooling:$compose_version" implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1' - implementation 'androidx.activity:activity-compose:1.5.1' + implementation 'androidx.activity:activity-compose:1.8.0' testImplementation 'junit:junit:4.13.2' implementation "androidx.compose.runtime:runtime:$compose_version" diff --git a/app/src/main/java/com/gowtham/compose_ratingbar/MainActivity.kt b/app/src/main/java/com/gowtham/compose_ratingbar/MainActivity.kt index 9e6fae9..086c516 100644 --- a/app/src/main/java/com/gowtham/compose_ratingbar/MainActivity.kt +++ b/app/src/main/java/com/gowtham/compose_ratingbar/MainActivity.kt @@ -13,7 +13,7 @@ import androidx.compose.material.MaterialTheme import androidx.compose.material.Surface import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.mutableFloatStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment @@ -54,8 +54,8 @@ fun MyApp() { @Composable fun MainScreen() { - var ratingOne: Float by rememberSaveable { mutableStateOf(1.4f) } - var ratingTwo: Float by rememberSaveable { mutableStateOf(initialRating) } + var ratingOne: Float by rememberSaveable { mutableFloatStateOf(1.4f) } + var ratingTwo: Float by rememberSaveable { mutableFloatStateOf(initialRating) } Column( modifier = Modifier.fillMaxSize(), diff --git a/build.gradle b/build.gradle index 7f5fd46..ae49337 100644 --- a/build.gradle +++ b/build.gradle @@ -2,12 +2,13 @@ buildscript { ext { - compileSdk = 33 + compileSdk = 34 minSdk = 21 - targetSdk = 33 + targetSdk = 34 - compose_version = '1.2.1' - compose_compiler = '1.4.5' + + compose_version = '1.5.1' + compose_compiler = '1.5.3' } repositories { @@ -17,11 +18,11 @@ buildscript { } plugins { - id 'com.android.application' version '8.0.2' apply false - id 'com.android.library' version '8.0.2' apply false - id 'org.jetbrains.kotlin.android' version '1.8.20' apply false - id 'org.jetbrains.kotlin.multiplatform' version '1.8.20' apply false - id 'org.jetbrains.compose' version '1.4.1' apply false + 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) { diff --git a/jitpack.yml b/jitpack.yml index 46c8529..efde7bf 100644 --- a/jitpack.yml +++ b/jitpack.yml @@ -1,2 +1,2 @@ jdk: - - openjdk11 \ No newline at end of file + - openjdk17 diff --git a/ratingbar/build.gradle b/ratingbar/build.gradle index 3eac529..a4e01c7 100644 --- a/ratingbar/build.gradle +++ b/ratingbar/build.gradle @@ -14,7 +14,7 @@ afterEvaluate { from components.release groupId = 'com.gowtham.composeratingbar' artifactId = 'compose-ratingbar' - version = '1.3.4' + version = '1.3.7' } } } @@ -37,8 +37,6 @@ android { minSdk rootProject.minSdk targetSdk rootProject.targetSdk - versionCode 1 - versionName "1.0" consumerProguardFiles "consumer-rules.pro" } @@ -49,12 +47,12 @@ android { } } compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = JavaVersion.VERSION_11.toString() + jvmTarget = JavaVersion.VERSION_17.toString() } buildFeatures { buildConfig false diff --git a/ratingbar/src/main/java/com/gowtham/ratingbar/RatingBar.kt b/ratingbar/src/main/java/com/gowtham/ratingbar/RatingBar.kt index 661cb32..a3f4e37 100644 --- a/ratingbar/src/main/java/com/gowtham/ratingbar/RatingBar.kt +++ b/ratingbar/src/main/java/com/gowtham/ratingbar/RatingBar.kt @@ -1,8 +1,8 @@ package com.gowtham.ratingbar import android.util.Log -import android.view.MotionEvent import androidx.compose.foundation.gestures.detectHorizontalDragGestures +import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size @@ -13,7 +13,6 @@ import androidx.compose.ui.geometry.Size import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.input.pointer.pointerInput -import androidx.compose.ui.input.pointer.pointerInteropFilter import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalLayoutDirection @@ -102,7 +101,7 @@ internal fun RatingBar( Row(modifier = modifier .onSizeChanged { rowSize = it.toSize() } .pointerInput( - Unit + onValueChange ) { //handling dragging events detectHorizontalDragGestures( @@ -128,34 +127,36 @@ internal fun RatingBar( paddingInPx, numOfStars, stepSize, starSizeInPx ) - - if (direction == LayoutDirection.Rtl) - calculatedStars = numOfStars - calculatedStars + if (direction == LayoutDirection.Rtl) { + // calculatedStars -> reversed + // 1 -> 5, 2 -> 4, 3 -> 3, 4 -> 2,5 -> 1 + calculatedStars = (numOfStars - calculatedStars) + } onValueChange(calculatedStars) lastDraggedValue = calculatedStars } ) } - .pointerInteropFilter { - if (isIndicator || hideInactiveStars) - return@pointerInteropFilter false + .pointerInput(onValueChange) { //handling when click events - when (it.action) { - MotionEvent.ACTION_DOWN -> { - val dragX = it.x.coerceIn(-1f, rowSize.width) - var calculatedStars = - RatingBarUtils.calculateStars( - dragX, - paddingInPx, - numOfStars, stepSize, starSizeInPx - ) - if (direction == LayoutDirection.Rtl) - calculatedStars = numOfStars - calculatedStars - onValueChange(calculatedStars) - onRatingChanged(calculatedStars) + detectTapGestures(onTap = { + if (isIndicator || hideInactiveStars) + return@detectTapGestures + val dragX = it.x.coerceIn(-1f, rowSize.width) + var calculatedStars = + RatingBarUtils.calculateStars( + dragX, + paddingInPx, + numOfStars, stepSize, starSizeInPx + ) + if (direction == LayoutDirection.Rtl) { + // calculatedStars -> reversed + // 1 -> 5, 2 -> 4, 3 -> 3, 4 -> 2,5 -> 1 + calculatedStars = (numOfStars - calculatedStars) + 1 } - } - true + onValueChange(calculatedStars) + onRatingChanged(calculatedStars) + }) }) { ComposeStars( value,