Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
a914-gowtham authored Oct 30, 2023
2 parents faa091f + 7682b49 commit 72f231b
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down
19 changes: 10 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion jitpack.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
jdk:
- openjdk11
- openjdk17
10 changes: 4 additions & 6 deletions ratingbar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ afterEvaluate {
from components.release
groupId = 'com.gowtham.composeratingbar'
artifactId = 'compose-ratingbar'
version = '1.3.4'
version = '1.3.7'
}
}
}
Expand All @@ -37,8 +37,6 @@ android {
minSdk rootProject.minSdk
targetSdk rootProject.targetSdk

versionCode 1
versionName "1.0"
consumerProguardFiles "consumer-rules.pro"
}

Expand All @@ -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
Expand Down
49 changes: 25 additions & 24 deletions ratingbar/src/main/java/com/gowtham/ratingbar/RatingBar.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -102,7 +101,7 @@ internal fun RatingBar(
Row(modifier = modifier
.onSizeChanged { rowSize = it.toSize() }
.pointerInput(
Unit
onValueChange
) {
//handling dragging events
detectHorizontalDragGestures(
Expand All @@ -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,
Expand Down

0 comments on commit 72f231b

Please sign in to comment.