Skip to content

Commit bdffd38

Browse files
authored
Merge pull request #14 from Vaibhav2002/JetpackCompose
Compose Documentation
2 parents c1f9946 + 8972f8b commit bdffd38

1 file changed

Lines changed: 76 additions & 1 deletion

File tree

README.md

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ dependencies {
5656

5757
## 💻 Usage
5858

59-
In XMl you need to define the button with your parameters to acheive the desired the design
59+
In XMl you need to define the button with your parameters to achieve the desired the design
6060

6161
#### Notes -
6262
* To use vibration on click please add the following permission in android manifest
@@ -202,6 +202,81 @@ binding.progressButton.attachToLiveData(buttonState)
202202
Just post the button state to the livedata like
203203
`livedata.postValue(ButtonStates.LOADING)` and button will change to loading state automatically
204204

205+
## Jetpack Compose
206+
207+
If you are using Jetpack Compose, all you have to do it to call the ProgressButton composable
208+
209+
### Composable function
210+
211+
```kotlin
212+
@Composable
213+
fun ProgressButton(
214+
buttonState: ButtonState,
215+
text: String,
216+
completedText: String,
217+
modifier: Modifier = Modifier,
218+
shape: Shape = RoundedCornerShape(4.dp),
219+
progressBarStrokeWidth: Dp = 3.dp,
220+
progressButtonColors: ProgressButtonColors = ProgressButtonColors(),
221+
progressButtonElevation: ProgressButtonElevation = ProgressButtonElevation(),
222+
textStyle: TextStyle = defaultTextStyle,
223+
onClick: () -> Unit
224+
)
225+
```
226+
227+
### Parameters
228+
229+
| Explanation | Paramter name | Type | Default value |
230+
|------|------|------|------|
231+
| Current state of button | buttonState | ButtonState | none |
232+
| Text shown in button | text | String | none |
233+
| Text shown in completed State | text | String | none |
234+
| Modifier for button | modifier | Modifier | Modifier |
235+
| Shape of button | shape | Shape | RoundedCornerShape with 4dp radius |
236+
| Stroke width of the progress bar inside button | progressBarStrokeWidth | Dp | 3.dp |
237+
| Colors used in button | progressButtonColors | ProgressButtonColors | ProgressButtonColors() |
238+
| Elevation used in button states | progressButtonElevation | ProgressButtonElevation | ProgressButtonElevation() |
239+
| Text Style of text inside button | textStyle | TextStyle | TextStyle(color = Color.White, fontSize = 16.sp, fontWeight = FontWeight.Bold) |
240+
| Lambda function to be called on button press | onClick | () -> Unit | none |
241+
242+
### Helper Classes
243+
244+
```kotlin
245+
//This class holds data of the colors used in button
246+
data class ProgressButtonColors(
247+
val backgroundColor: Color = DEFAULT_COLOR, //#0052FE
248+
val disabledColor: Color = DISABLED_COLOR, //#537CD3
249+
val finishedColor: Color = FINISHED_COLOR, //#27AE60
250+
val contentColor: Color = CONTENT_COLOR //#FFFFFF
251+
)
252+
253+
//This class holds data for the elevation used in button
254+
data class ProgressButtonElevation(
255+
val defaultElevation: Dp = DEFAULT_ELEVATION, //8dp
256+
val elevationOnPress: Dp = DEFAULT_ELEVATION_ON_PRESS //12dp
257+
)
258+
```
259+
260+
### Sample code
261+
262+
```kotlin
263+
fun MainScreenContent() {
264+
//mutable State to holf button state
265+
var buttonState by remember {
266+
mutableStateOf(ButtonState.DISABLED)
267+
}
268+
ProgressButton(
269+
buttonState = buttonState,
270+
text = "Button",
271+
completedText = "Finished",
272+
shape = RoundedCornerShape(12.dp),
273+
modifier = Modifier.fillMaxWidth()
274+
) {
275+
}
276+
277+
}
278+
```
279+
205280
🌟 You are all set!
206281

207282
## 🍰 Contribute

0 commit comments

Comments
 (0)