Skip to content

Commit

Permalink
Merge pull request #37 from yangsooplus/feature/alphaslider-initial-c…
Browse files Browse the repository at this point in the history
…olor

Add initialColor to AlphaSlider
  • Loading branch information
skydoves authored Sep 13, 2023
2 parents ace8470 + ff35553 commit f4d2422
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion colorpicker-compose/api/colorpicker-compose.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
public final class com/github/skydoves/colorpicker/compose/AlphaSliderKt {
public static final fun AlphaSlider-VVBY8Eo (Landroidx/compose/ui/Modifier;Lcom/github/skydoves/colorpicker/compose/ColorPickerController;FFJLandroidx/compose/ui/graphics/ImageBitmap;FJFLandroidx/compose/ui/graphics/Paint;JJFLandroidx/compose/runtime/Composer;III)V
public static final fun AlphaSlider-I89wPZw (Landroidx/compose/ui/Modifier;Lcom/github/skydoves/colorpicker/compose/ColorPickerController;FFJLandroidx/compose/ui/graphics/ImageBitmap;FJFLandroidx/compose/ui/graphics/Paint;JJFLandroidx/compose/ui/graphics/Color;Landroidx/compose/runtime/Composer;III)V
}

public final class com/github/skydoves/colorpicker/compose/AlphaTileDrawable : android/graphics/drawable/Drawable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.geometry.Offset
Expand Down Expand Up @@ -60,6 +64,8 @@ import androidx.compose.ui.unit.dp
* @param tileOddColor Color of the odd tiles.
* @param tileEvenColor Color of the even tiles.
* @param tileSize DP size of tiles.
* @param initialColor [Color] of the initial state. This property works for [HsvColorPicker] and
* it will be selected on rightmost of slider if you give null value.
*/
@Composable
public fun AlphaSlider(
Expand All @@ -79,6 +85,7 @@ public fun AlphaSlider(
tileOddColor: Color = defaultTileOddColor,
tileEvenColor: Color = defaultTileEvenColor,
tileSize: Dp = 12.dp,
initialColor: Color? = null,
) {
val density = LocalDensity.current
var backgroundBitmap: ImageBitmap? = null
Expand All @@ -91,6 +98,7 @@ public fun AlphaSlider(
val colorPaint: Paint = Paint().apply {
color = controller.pureSelectedColor.value
}
var isInitialized by remember { mutableStateOf(false) }

SideEffect {
controller.isAttachedAlphaSlider = true
Expand Down Expand Up @@ -225,6 +233,10 @@ public fun AlphaSlider(
)
}
}
if (initialColor != null && !isInitialized) {
isInitialized = true
controller.setAlpha(alpha = initialColor.alpha, fromUser = false)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import kotlin.math.max
* @param wheelColor [Color] of th wheel.
* @param wheelPaint [Paint] to draw the wheel.
* @param initialColor [Color] of the initial state. This property works for [HsvColorPicker] and
* it will be selected on center if you give null value.
* it will be selected on rightmost of slider if you give null value.
*/
@Composable
public fun BrightnessSlider(
Expand Down

0 comments on commit f4d2422

Please sign in to comment.