Skip to content

Commit

Permalink
Merge pull request #27 from SimformSolutionsPvtLtd/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mobile-simformsolutions authored Jul 22, 2021
2 parents 7939034 + 6557173 commit 0418449
Show file tree
Hide file tree
Showing 16 changed files with 416 additions and 193 deletions.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,58 @@
| `fontSize` | The size of glyphs to use when painting the text. | `TextUnit.Unspecified` |
| `fontStyle` | The typeface variant to use when drawing the letters (e.g., italic). | `null` |
| `fontFamily` | The font family to be used when rendering the text. | `null` |
| `fontWeight` | The typeface thickness to use when painting the text (e.g., [FontWeight.Bold]). | `null` |
| `hourHandColor` | Color will be apply to hour hand in clock type animation only. | `Color.Black` |
| `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` |

## Customization
* You can customize loading icon and animation effect according to your requirement.You can apply multiple animation effect from roationm, zoom-in-out and color changer.

```kotlin
var submitButtonState by remember { mutableStateOf(SSButtonState.IDLE) }
SSJetPackComposeProgressButton(
type = SSButtonType.CLOCK,
width = 300.dp,
height = 50.dp,
onClick = {
//Perform action on click of button and make it state to LOADING
submitButtonState = SSButtonState.LOADING
},
assetColor = Color.Red,
buttonState = submitButtonState,
successIconPainter = painterResource(id = R.drawable.custom_success),
failureIconPainter = painterResource(id = R.drawable.custom_fail),
colors = ButtonDefaults.buttonColors(backgroundColor = Color.White),
padding = PaddingValues(six.dp),
text = stringResource(id = R.string.simform),
textModifier = Modifier.padding(ten.dp),
fontWeight = FontWeight.Bold,
leftImagePainter = painterResource(id = R.drawable.simform_logo),
buttonBorderStroke = BorderStroke(two.dp, colorResource(id = R.color.pink)),
customLoadingIconPainter = painterResource(id = R.drawable.simform_logo),
customLoadingEffect = SSCustomLoadingEffect(
rotation = false,
zoomInOut = true,
colorChanger = false
)
)
```
```kotlin
// On Success change submitButtonState to success state
submitButtonState = SSButtonState.SUCCESS
```
```kotlin
// On Failure change submitButtonState to failure state
submitButtonState = SSButtonState.FAILIURE
```

# 🎬 Custom loading animation

| On Success | On Failure |
|--|--|
| ![](https://github.com/SimformSolutionsPvtLtd/SSJetPackComposeProgressButton/blob/main/gif/custom_success.gif) | ![](https://github.com/SimformSolutionsPvtLtd/SSJetPackComposeProgressButton/blob/main/gif/custom_fail.gif) |


## Find this library useful? ❤️
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "com.simform.ssjetpackcomposeprogressbutton"
minSdk 21
targetSdk 30
versionCode 1
versionName "1.0.0"
versionCode 2
versionName "1.0.5"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down

Large diffs are not rendered by default.

Binary file added app/src/main/res/drawable/custom_fail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/custom_success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
<color name="dark_green">#07a34d</color>
<color name="yellow">#ffbb00</color>
<color name="light_blue">#23395D</color>
<color name="pink">#ff1731</color>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<string name="with_text">With Text</string>
<string name="on_success">On Success</string>
<string name="on_failure">On Failure</string>
<string name="simform">SIMFORM</string>

</resources>
Binary file added gif/custom_fail.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gif/custom_success.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions ssjetpackcomposeprogressbutton/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ afterEvaluate {
release(MavenPublication) {
from components.release
groupId = 'com.simform.ssloadingbuttonlibrary'
artifactId = 'ssloadingbuttonlibrary'
version = '1.0.0'
artifactId = 'ssjetpackcomposeprogressbutton'
version = '1.0.5'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.simform.ssjetpackcomposeprogressbuttonlibrary

data class SSCustomLoadingEffect (
var rotation: Boolean = false,
var zoomInOut: Boolean = false,
var colorChanger: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ enum class SSButtonState {
}

enum class SSButtonType {
CIRCLE, WHEEL, ZOOM_IN_OUT_CIRCLE, CLOCK, SPIRAL
CIRCLE, WHEEL, ZOOM_IN_OUT_CIRCLE, CLOCK, SPIRAL, CUSTOM
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.simform.ssjetpackcomposeprogressbuttonlibrary.utils.ZERO
import com.simform.ssjetpackcomposeprogressbuttonlibrary.utils.ten
import com.simform.ssjetpackcomposeprogressbuttonlibrary.utils.three
import com.simform.ssjetpackcomposeprogressbuttonlibrary.utils.threeSixtyFloat
Expand All @@ -23,7 +25,10 @@ fun PrintLoadingBar(
assetColor: Color,
minHeightWidth: Dp,
durationMillis: Int,
hourHandColor: Color
hourHandColor: Color,
customLoadingIconPainter: Painter,
customLoadingEffect: SSCustomLoadingEffect,
customLoadingPadding: Int = ZERO
) {
when (type) {
SSButtonType.CIRCLE -> {
Expand Down Expand Up @@ -93,5 +98,43 @@ fun PrintLoadingBar(
tint = assetColor
)
}
SSButtonType.CUSTOM -> {
val customColor = ssRepeatedColorAnimation(
assetColor, if (customLoadingEffect.colorChanger) {
Color.White
} else {
assetColor
}, durationMillis
)
val customRotation = ssRepeatedFloatAnimation(
initialValue = if (customLoadingEffect.rotation) {
threeSixtyFloat
} else {
zeroFloat
},
targetValue = zeroFloat,
durationMillis = durationMillis
)

val customSize = ssRepeatedDpAnimation(
initialValue = minHeightWidth - customLoadingPadding.dp,
targetValue = if (customLoadingEffect.zoomInOut) {
ten.dp
} else {
minHeightWidth - customLoadingPadding.dp
},
durationMillis = durationMillis
)
Icon(
painter = customLoadingIconPainter,
contentDescription = null,
modifier = Modifier
.size(customSize)
.graphicsLayer { alpha = progressAlpha }
.rotate(customRotation),
tint = customColor
)
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import com.simform.ssjetpackcomposeprogressbuttonlibrary.utils.LAUNCH_EFFECT_KEY
import com.simform.ssjetpackcomposeprogressbuttonlibrary.utils.ZERO
import com.simform.ssjetpackcomposeprogressbuttonlibrary.utils.fifty
import com.simform.ssjetpackcomposeprogressbuttonlibrary.utils.oneFloat
import com.simform.ssjetpackcomposeprogressbuttonlibrary.utils.ten
Expand Down Expand Up @@ -76,7 +79,11 @@ import kotlinx.coroutines.delay
* @param fontSize The size of glyphs to use when painting the text. See [TextStyle.fontSize].
* @param fontStyle The typeface variant to use when drawing the letters (e.g., italic).
* @param fontFamily The font family to be used when rendering the text. See [TextStyle.fontFamily].
* @param fontWeight The typeface thickness to use when painting the text (e.g., [FontWeight.Bold]).
* @param hourHandColor Color will be apply to hour hand in clock type animation only.
* @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.
*/

@Composable
Expand Down Expand Up @@ -105,7 +112,15 @@ fun SSJetPackComposeProgressButton(
fontSize: TextUnit = TextUnit.Unspecified,
fontStyle: FontStyle? = null,
fontFamily: FontFamily? = null,
hourHandColor: Color = Color.Black
fontWeight: FontWeight? = null,
hourHandColor: Color = Color.Black,
customLoadingIconPainter: Painter = painterResource(id = R.drawable.simform_logo),
customLoadingEffect: SSCustomLoadingEffect = SSCustomLoadingEffect(
rotation = false,
zoomInOut = false,
colorChanger = false
),
customLoadingPadding: Int = ZERO
) {
var buttonWidth by remember { mutableStateOf(width) }
var buttonHeight by remember { mutableStateOf(height) }
Expand Down Expand Up @@ -264,7 +279,8 @@ fun SSJetPackComposeProgressButton(
color = assetColor,
fontSize = fontSize,
fontStyle = fontStyle,
fontFamily = fontFamily
fontFamily = fontFamily,
fontWeight = fontWeight
)
}
}
Expand Down Expand Up @@ -339,7 +355,10 @@ fun SSJetPackComposeProgressButton(
assetColor = assetColor,
minHeightWidth = effectiveMinHeight,
durationMillis = speedMillis,
hourHandColor = hourHandColor
hourHandColor = hourHandColor,
customLoadingIconPainter = customLoadingIconPainter,
customLoadingEffect = customLoadingEffect,
customLoadingPadding = customLoadingPadding
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.simform.ssjetpackcomposeprogressbuttonlibrary.utils
const val zeroFloat = 0f
const val oneFloat = 1f
const val threeSixtyFloat = 360f
const val ZERO = 0
const val two = 2
const val three = 3
const val six = 6
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0418449

Please sign in to comment.