-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from Trendyol/feature/quantityPickerCompose
Feature/quantity picker compose
- Loading branch information
Showing
29 changed files
with
986 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
quantityPickerComposeVersion= **quantity-picker-compose-1.0.1** [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) | ||
|
||
## QuantityPicker | ||
|
||
QuantityPicker is compose component to add/remove anything | ||
|
||
<img src="../../images/quantity-picker-compose.gif" width="240"/> | ||
|
||
## Installation | ||
|
||
- To implement **QuantityPicker** to your Android project via Gradle, you need to add JitPack repository to your root/project level build.gradle. | ||
|
||
```gradle | ||
allprojects { | ||
repositories { ... maven { url 'https://jitpack.io' } } | ||
} | ||
``` | ||
|
||
- After adding JitPack repository, you can add **QuantityPicker** dependency to your app/module level build.gradle. | ||
|
||
```gradle | ||
dependencies { | ||
implementation "com.github.Trendyol.android-ui-components:quantity-picker-compose:$quantityPickerComposeVersion" | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
You can add **QuantityPicker** wherever you want with your modifier | ||
|
||
|
||
| Attribute | Type | Description | | ||
| ------------------- | ----------------------- | ------------------------------------------------------------ | | ||
| modifier | Modifier | Compose modifier for QuantityPicker | | ||
| direction | QuantityPickerDirection | Picker Direction Vertical or Horizontal | | ||
| icons | QuantityIcons | Drawables for add subtract remove and colors | | ||
| quantityTextShape | QuantityPickerShape | Compose shape for quantity text. | | ||
| quantityPickerShape | QuantityPickerShape | Background of all view also defines border if it is not null | | ||
| textStyle | TextStyle | Text style for quantity text | | ||
| quantityData | QuantityData | Quantity values. It has min,max,current and postfix | | ||
| showLoading | Boolean | Loading state | | ||
| progressColor | Color | Color for loading progress indicator | | ||
| onAddClick | (() -> Unit) | Listener for add button clicks | | ||
| onSubtractClick | (() -> Unit) | Listener for subtract clicks | | ||
|
||
## Implementation | ||
|
||
If you don't need any customization | ||
|
||
```kotlin | ||
QuantityPicker( | ||
modifier = modifier, | ||
quantityData = quantityData, | ||
showLoading = isLoading, | ||
onAddClick = { }, | ||
onSubtractClick = { } | ||
) | ||
``` | ||
|
||
If you need background or custom modifier for quantity text and all view | ||
|
||
```kotlin | ||
QuantityPicker( | ||
textStyle = Typography.body2, | ||
quantityData = quantityData, | ||
icons: QuantityIcons = QuantityIcons( // QuantityIcons.default | ||
addIconResId = R.drawable.ic_plus, | ||
subtractIconResId = R.drawable.ic_subtract, | ||
removeIconResId = R.drawable.ic_trash, | ||
iconColor = QuantityPickerDefaults.defaultColor, | ||
disabledColor = QuantityPickerDefaults.disabledColor | ||
), | ||
quantityPickerShape = QuantityPickerShape( // QuantityPickerDefaults.quantityShape, | ||
shape = RoundedCornerShape(50), | ||
borderColor = MyQuantityPickerPrimaryColor, | ||
borderWidth = 1.dp | ||
), | ||
quantityTextShape = QuantityPickerShape( // QuantityPickerDefaults.quantityTextShape | ||
shape = RoundedCornerShape(50), | ||
borderColor = MyQuantityPickerPrimaryColor, | ||
borderWidth = 1.dp | ||
), | ||
showLoading = isLoading, | ||
progressColor = MyQuantityPickerPrimaryColor, // QuantityPickerDefaults.defaultColor | ||
onAddClick = { }, | ||
onSubtractClick = { } | ||
) | ||
``` | ||
|
||
# Contributors | ||
|
||
This library is maintained mainly by Trendyol Android Team members but also other Android lovers contributes. | ||
|
||
# License | ||
|
||
``` | ||
Copyright 2023 Trendyol.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
plugins { | ||
id(Plugins.androidLibrary) | ||
id(Plugins.kotlinAndroid) | ||
id(Plugins.mavenPublish) | ||
id(Plugins.compose) version "2.0.0" | ||
} | ||
|
||
kotlin.jvmToolchain(17) | ||
|
||
android { | ||
namespace = "com.trendyol.quantitypickercompose" | ||
compileSdk = 33 | ||
|
||
defaultConfig { | ||
minSdk = Configs.minSdkVersion | ||
vectorDrawables.useSupportLibrary = true | ||
} | ||
|
||
buildTypes { | ||
getByName<com.android.build.gradle.internal.dsl.BuildType>("release") { | ||
isMinifyEnabled = false | ||
setProguardFiles( | ||
mutableListOf( | ||
getDefaultProguardFile("proguard-android.txt"), | ||
"proguard-rules.pro" | ||
) | ||
) | ||
} | ||
} | ||
buildFeatures { | ||
compose = true | ||
} | ||
|
||
composeOptions { | ||
kotlinCompilerExtensionVersion = Dependencies.kotlinCompilerExtensionVersion | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
val composeBom = platform(Dependencies.composeBom) | ||
implementation(composeBom) | ||
implementation(Dependencies.composeMaterial) | ||
implementation(Dependencies.composeUiTooling) | ||
implementation(Dependencies.composeCoil) | ||
implementation(Dependencies.composeRuntime) | ||
implementation(Dependencies.composeConstraintLayout) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
2 changes: 2 additions & 0 deletions
2
libraries/quantity-picker-compose/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest/> |
31 changes: 31 additions & 0 deletions
31
...-picker-compose/src/main/java/com/trendyol/uicomponents/quantitypicker/QuantityAddIcon.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.trendyol.uicomponents.quantitypicker | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Icon | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
internal fun QuantityAddIcon( | ||
icons: QuantityIcons, | ||
quantityData: QuantityPickerViewData, | ||
onAddClick: (() -> Unit)? | ||
) { | ||
Icon( | ||
painter = painterResource(id = icons.addIconResId), | ||
tint = quantityData.getAddIconColor(icons.iconColor, icons.disabledColor), | ||
contentDescription = null, | ||
modifier = Modifier | ||
.clickable( | ||
enabled = quantityData.isAddButtonEnabled(), | ||
onClick = { onAddClick?.invoke() }, | ||
interactionSource = MutableInteractionSource(), | ||
indication = null, | ||
) | ||
.padding(8.dp) | ||
) | ||
} |
25 changes: 25 additions & 0 deletions
25
...ty-picker-compose/src/main/java/com/trendyol/uicomponents/quantitypicker/QuantityIcons.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.trendyol.uicomponents.quantitypicker | ||
|
||
import androidx.annotation.DrawableRes | ||
import androidx.compose.ui.graphics.Color | ||
import com.trendyol.quantitypickercompose.R | ||
|
||
data class QuantityIcons( | ||
@DrawableRes val addIconResId: Int = R.drawable.ic_plus, | ||
@DrawableRes val subtractIconResId: Int = R.drawable.ic_subtract, | ||
@DrawableRes val removeIconResId: Int? = R.drawable.ic_trash, | ||
val iconColor: Color, | ||
val disabledColor: Color, | ||
) { | ||
companion object { | ||
val default = QuantityIcons( | ||
addIconResId = R.drawable.ic_plus, | ||
subtractIconResId = R.drawable.ic_subtract, | ||
removeIconResId = R.drawable.ic_trash, | ||
iconColor = QuantityPickerDefaults.defaultColor, | ||
disabledColor = QuantityPickerDefaults.disabledColor | ||
) | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.