Skip to content

Commit

Permalink
Develop to main (#54)
Browse files Browse the repository at this point in the history
* 🐎 UNT-13932 Disabled button click when it's in loading state

* 🐎 #38 Added shouldAutoMoveToIdleState parameter.

* ⚡ Dependency version updated.

* ⚡ jitpack yml updated

* Readme updated

---------
  • Loading branch information
purvesh-d committed Mar 20, 2024
1 parent 3a27c59 commit 19b7a1f
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 60 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SSJetPackComposeProgressButton
### _SSJetPackComposeProgressButton is an elegant button with a different loading animations which makes your app attractive._

[![Build Status](https://travis-ci.org/joemccann/dillinger.svg?branch=master)][git-repo-url] [![](https://jitpack.io/v/SimformSolutionsPvtLtd/SSJetPackComposeProgressButton.svg)](https://jitpack.io/#SimformSolutionsPvtLtd/SSJetPackComposeProgressButton) [![Kotlin Version](https://img.shields.io/badge/Kotlin-v1.5.10-blue.svg)](https://kotlinlang.org) [![Platform](https://img.shields.io/badge/Platform-Android-green.svg?style=flat)](https://www.android.com/) [![API](https://img.shields.io/badge/API-21%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=21) [![Android Arsenal]( https://img.shields.io/badge/Android%20Arsenal-SSJetPackComposeProgressButton-green.svg?style=flat )]( https://android-arsenal.com/details/1/8302 )
[![CI Status](https://img.shields.io/github/v/release/SimformSolutionsPvtLtd/SSJetPackComposeProgressButton?style=flat)](https://travis-ci.org/SimformSolutionsPvtLtd/SSJetPackComposeProgressButton) [![](https://jitpack.io/v/SimformSolutionsPvtLtd/SSJetPackComposeProgressButton.svg)](https://jitpack.io/#SimformSolutionsPvtLtd/SSJetPackComposeProgressButton) [![Kotlin Version](https://img.shields.io/badge/Kotlin-v1.5.10-blue.svg)](https://kotlinlang.org) [![Platform](https://img.shields.io/badge/Platform-Android-green.svg?style=flat)](https://www.android.com/) [![API](https://img.shields.io/badge/API-21%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=21) [![Android Arsenal]( https://img.shields.io/badge/Android%20Arsenal-SSJetPackComposeProgressButton-green.svg?style=flat )]( https://android-arsenal.com/details/1/8302 )

# Jetpack Compose
Jetpack Compose is Android’s modern toolkit for building native UI. It simplifies and accelerates UI development on Android. Quickly bring your app to life with less code, powerful tools, and intuitive Kotlin APIs.
Expand Down Expand Up @@ -48,7 +48,7 @@ Please get **Android Studio Arctic Fox 2020.3.1** or above [from here](https://d

```groovy
dependencies {
implementation 'com.github.SimformSolutionsPvtLtd:SSJetPackComposeProgressButton:1.0.7'
implementation 'com.github.SimformSolutionsPvtLtd:SSJetPackComposeProgressButton:1.0.8'
}
```

Expand Down Expand Up @@ -155,6 +155,7 @@ Please get **Android Studio Arctic Fox 2020.3.1** or above [from here](https://d
| `customLoadingIconPainter` | painter [Painter] to draw your custom loading icon. | `painterResource(id = R.drawable.simform_logo)` |
| `customLoadingEffect` | Custom loading animation type like roation, zoom in out etc. | `SSCustomLoadingEffect( rotation = false, zoomInOut = false, colorChanger = false)` |
| `customLoadingPadding` | Spacing between button border and loading icon. | `0` |
| `shouldAutoMoveToIdleState` | In case of success/failure state after defined time it move back to idle state. | `true` |

## Our JetPackCompose Sample
[SSComposeCookBook](https://github.com/SimformSolutionsPvtLtd/SSComposeCookBook) : A Collection of major Jetpack compose UI components which are commonly used.
Expand Down
18 changes: 9 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ plugins {
}

android {
compileSdk 33
compileSdk 34

defaultConfig {
applicationId "com.simform.ssjetpackcomposeprogressbutton"
minSdk 21
targetSdk 33
targetSdk 34
versionCode 2
versionName "1.0.7"

Expand All @@ -26,11 +26,11 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '11'
jvmTarget = '17'
}
buildFeatures {
compose true
Expand All @@ -41,11 +41,11 @@ android {
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.6.0-rc01'
implementation 'com.google.android.material:material:1.6.1'
implementation "androidx.compose.ui:ui:1.2.1"
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.11.0'
implementation "androidx.compose.ui:ui:1.5.4"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation 'androidx.activity:activity-compose:1.5.1'
implementation 'androidx.activity:activity-compose:1.8.2'
implementation project(path: ':ssjetpackcomposeprogressbutton')
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fun SSLoadingButtonExample() {
item {
SSJetPackComposeProgressButton(
assetColor = colorResource(id = R.color.pink),
colors = ButtonDefaults.buttonColors(backgroundColor = Color.White),
colors = ButtonDefaults.buttonColors(backgroundColor = Color.White, disabledBackgroundColor = Color.White),
buttonBorderStroke = BorderStroke(COMMON_BORDER_WIDTH.dp, SolidColor(colorResource(id = R.color.pink))),
type = SSButtonType.CIRCLE,
onClick = { roundedProgressState2 = SSButtonState.LOADING },
Expand All @@ -174,11 +174,12 @@ fun SSLoadingButtonExample() {
height = COMMON_HEIGHT.dp,
padding = PaddingValues(TWELVE.dp),
cornerRadius = COMMON_CORNER_RADIUS,
leftImagePainter = rememberVectorPainter(image = Icons.Default.Home)
leftImagePainter = rememberVectorPainter(image = Icons.Default.Home),
shouldAutoMoveToIdleState = false
)
SSJetPackComposeProgressButton(
assetColor = colorResource(id = R.color.pink),
colors = ButtonDefaults.buttonColors(backgroundColor = Color.White),
colors = ButtonDefaults.buttonColors(backgroundColor = Color.White, disabledBackgroundColor = Color.White),
buttonBorderStroke = BorderStroke(
COMMON_BORDER_WIDTH.dp,
SolidColor(colorResource(id = R.color.pink))
Expand All @@ -194,7 +195,7 @@ fun SSLoadingButtonExample() {
)
SSJetPackComposeProgressButton(
assetColor = colorResource(id = R.color.pink),
colors = ButtonDefaults.buttonColors(backgroundColor = Color.White),
colors = ButtonDefaults.buttonColors(backgroundColor = Color.White, disabledBackgroundColor = Color.White),
buttonBorderStroke = BorderStroke(COMMON_BORDER_WIDTH.dp, SolidColor(colorResource(id = R.color.pink))),
type = SSButtonType.ZOOM_IN_OUT_CIRCLE,
onClick = { zoomInOutState = SSButtonState.LOADING },
Expand All @@ -207,7 +208,7 @@ fun SSLoadingButtonExample() {
)
SSJetPackComposeProgressButton(
assetColor = colorResource(id = R.color.pink),
colors = ButtonDefaults.buttonColors(backgroundColor = Color.White),
colors = ButtonDefaults.buttonColors(backgroundColor = Color.White, disabledBackgroundColor = Color.White),
buttonBorderStroke = BorderStroke(COMMON_BORDER_WIDTH.dp, SolidColor(colorResource(id = R.color.pink))),
type = SSButtonType.CLOCK,
onClick = { clockState = SSButtonState.LOADING },
Expand All @@ -220,7 +221,7 @@ fun SSLoadingButtonExample() {
)
SSJetPackComposeProgressButton(
assetColor = colorResource(id = R.color.pink),
colors = ButtonDefaults.buttonColors(backgroundColor = Color.White),
colors = ButtonDefaults.buttonColors(backgroundColor = Color.White, disabledBackgroundColor = Color.White),
buttonBorderStroke = BorderStroke(COMMON_BORDER_WIDTH.dp, SolidColor(colorResource(id = R.color.pink))),
type = SSButtonType.SPIRAL,
onClick = { spiralState = SSButtonState.LOADING },
Expand All @@ -233,7 +234,7 @@ fun SSLoadingButtonExample() {
)
SSJetPackComposeProgressButton(
assetColor = Color.White,
colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink)),
colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink), disabledBackgroundColor = colorResource(id = R.color.pink)),
type = SSButtonType.CIRCLE,
onClick = { roundedProgressState = SSButtonState.LOADING },
buttonState = roundedProgressState,
Expand All @@ -254,12 +255,12 @@ fun SSLoadingButtonExample() {
leftImagePainter = rememberVectorPainter(image = Icons.Default.FavoriteBorder),
padding = PaddingValues(TWELVE.dp),
cornerRadius = COMMON_CORNER_RADIUS,
colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink)),
colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink), disabledBackgroundColor = colorResource(id = R.color.pink)),
hourHandColor = colorResource(id = R.color.handColor)
)
SSJetPackComposeProgressButton(
assetColor = Color.White,
colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink)),
colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink), disabledBackgroundColor = colorResource(id = R.color.pink)),
type = SSButtonType.ZOOM_IN_OUT_CIRCLE,
onClick = { ssTextButtonState = SSButtonState.LOADING },
buttonState = ssTextButtonState,
Expand Down Expand Up @@ -290,7 +291,7 @@ fun SSLoadingButtonExample() {
blinkingIcon = true,
padding = PaddingValues(TWELVE.dp),
cornerRadius = COMMON_CORNER_RADIUS,
colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink))
colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink), disabledBackgroundColor = colorResource(id = R.color.pink))
)
SSJetPackComposeProgressButton(
assetColor = Color.White,
Expand All @@ -307,7 +308,7 @@ fun SSLoadingButtonExample() {
fontWeight = FontWeight.Bold,
padding = PaddingValues(TWELVE.dp),
cornerRadius = COMMON_CORNER_RADIUS,
colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink))
colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(id = R.color.pink), disabledBackgroundColor = colorResource(id = R.color.pink))
)
Spacer(modifier = Modifier.size(COMMON_HEIGHT.dp))
SSJetPackComposeProgressButton(
Expand All @@ -324,7 +325,7 @@ fun SSLoadingButtonExample() {
zoomInOut = false,
colorChanger = false
),
colors = ButtonDefaults.buttonColors(backgroundColor = Color.White),
colors = ButtonDefaults.buttonColors(backgroundColor = Color.White, disabledBackgroundColor = Color.White),
padding = PaddingValues(TWELVE.dp),
cornerRadius = COMMON_CORNER_RADIUS,
text = stringResource(id = R.string.simform),
Expand All @@ -348,7 +349,7 @@ fun SSLoadingButtonExample() {
zoomInOut = true,
colorChanger = false
),
colors = ButtonDefaults.buttonColors(backgroundColor = Color.White),
colors = ButtonDefaults.buttonColors(backgroundColor = Color.White, disabledBackgroundColor = Color.White),
padding = PaddingValues(TWELVE.dp),
cornerRadius = COMMON_CORNER_RADIUS,
text = stringResource(id = R.string.simform),
Expand All @@ -372,7 +373,7 @@ fun SSLoadingButtonExample() {
zoomInOut = false,
colorChanger = true
),
colors = ButtonDefaults.buttonColors(backgroundColor = Color.White),
colors = ButtonDefaults.buttonColors(backgroundColor = Color.White, disabledBackgroundColor = Color.White),
padding = PaddingValues(ten.dp),
cornerRadius = COMMON_CORNER_RADIUS,
text = stringResource(id = R.string.simform),
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
buildscript {
ext {
compose_version = '1.2.1'
compose_version = '1.5.4'
compose_compiler = '1.3.1'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10'
}
configurations {
all {
configureEach {
exclude group: 'androidx.lifecycle', module: 'lifecycle-viewmodel-ktx'
}
}
}

task clean(type: Delete) {
tasks.register('clean', Delete) {
delete rootProject.buildDir
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu May 06 09:44:53 IST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
5 changes: 4 additions & 1 deletion jitpack.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
jdk:
- openjdk11
- openjdk17
before_install:
- sdk install java 17.0.3-tem
- sdk use java 17.0.3-tem
14 changes: 7 additions & 7 deletions ssjetpackcomposeprogressbutton/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ afterEvaluate {
}

android {
compileSdk 33
compileSdk 34

defaultConfig {
minSdk 21
targetSdk 33
targetSdk 34

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand All @@ -37,12 +37,12 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = '11'
jvmTarget = '17'
}

buildFeatures {
Expand All @@ -58,8 +58,8 @@ android {
dependencies {

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import kotlinx.coroutines.delay
* @param customLoadingIconPainter painter [Painter] to draw your custom loading icon.
* @param customLoadingEffect custom loading animation type.
* @param customLoadingPadding spacing between button border and loading icon.
* @param shouldAutoMoveToIdleState In case of success/failure state after defined time it move back to idle state
*/

@Composable
Expand Down Expand Up @@ -124,7 +125,8 @@ fun SSJetPackComposeProgressButton(
zoomInOut = false,
colorChanger = false
),
customLoadingPadding: Int = ZERO
customLoadingPadding: Int = ZERO,
shouldAutoMoveToIdleState: Boolean = true
) {
var buttonWidth by remember { mutableStateOf(width) }
var buttonHeight by remember { mutableStateOf(height) }
Expand Down Expand Up @@ -175,17 +177,20 @@ fun SSJetPackComposeProgressButton(
successIconAlphaValue = oneFloat
progressAlphaValue = zeroFloat
cornerRadiusValue = fifty
//Delay to show success icon and then IDLE state
delay((speedMillis * two).toLong())
if (height > width) {
buttonHeight = height
} else {
buttonWidth = width

if (shouldAutoMoveToIdleState) {
//Delay to show success icon and then IDLE state
delay((speedMillis * two).toLong())
if (height > width) {
buttonHeight = height
} else {
buttonWidth = width
}
iconAlphaValue = oneFloat
failureAlphaValue = zeroFloat
successIconAlphaValue = zeroFloat
cornerRadiusValue = cornerRadius
}
iconAlphaValue = oneFloat
failureAlphaValue = zeroFloat
successIconAlphaValue = zeroFloat
cornerRadiusValue = cornerRadius
})
}
SSButtonState.FAILURE -> {
Expand All @@ -200,17 +205,21 @@ fun SSJetPackComposeProgressButton(
progressAlphaValue = zeroFloat
failureAlphaValue = oneFloat
cornerRadiusValue = fifty
//Delay to show failure icon and then IDLE state
delay((speedMillis * two).toLong())
if (height > width) {
buttonHeight = height
} else {
buttonWidth = width

if (shouldAutoMoveToIdleState) {
//Delay to show failure icon and then IDLE state
delay((speedMillis * two).toLong())

if (height > width) {
buttonHeight = height
} else {
buttonWidth = width
}
iconAlphaValue = oneFloat
failureAlphaValue = zeroFloat
successIconAlphaValue = zeroFloat
cornerRadiusValue = cornerRadius
}
iconAlphaValue = oneFloat
failureAlphaValue = zeroFloat
successIconAlphaValue = zeroFloat
cornerRadiusValue = cornerRadius
})
}
}
Expand All @@ -230,7 +239,7 @@ fun SSJetPackComposeProgressButton(
durationMillis = speedMillis
)
),
enabled = enabled,
enabled = enabled && buttonState != SSButtonState.LOADING,
elevation = elevation,
shape = RoundedCornerShape(ssAnimateIntAsState(cornerRadiusValue, speedMillis)),
border = buttonBorderStroke,
Expand Down

0 comments on commit 19b7a1f

Please sign in to comment.