Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initialColor to AlphaSlider #37

Merged
merged 4 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading