Sliders for compose with custom styles

Overview

Custom compose sliders

This package allows you to build highly customizable sliders and tracks for compose for android

showcase

Add to your project

Release

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

Add the dependency

implementation "com.github.krottv:compose-sliders:$compose_sliders_version"

Simple Usage

var stateSlider2 by remember { mutableStateOf(0.5f) }
SliderValueHorizontal(
    stateSlider2, { stateSlider2 = it },
    modifier = Modifier
        .fillMaxWidth()
        .height(80.dp), steps = 10,
    thumbHeightMax = true,
    track = { modifier: Modifier,
                fraction: Float,
                interactionSource: MutableInteractionSource,
                tickFractions: List<Float>,
                enabled: Boolean ->

        DefaultTrack(
            modifier,
            fraction,
            interactionSource,
            tickFractions,
            enabled,
            height = 4.dp
        )
    },
    thumb = { modifier: Modifier,
                offset: Dp,
                interactionSource: MutableInteractionSource,
                enabled: Boolean,
                thumbSize: DpSize ->

        DefaultThumb(
            modifier, offset, interactionSource, enabled, thumbSize,
            color = Color.Blue,
            scaleOnPress = 1.3f
        )
    }
)

Advanced Usage

It allows to use custom composables for track and thumb. For detailed usage see sample/MainActivity

var stateSlider3 by remember { mutableStateOf(0.5f) }

SliderValueHorizontal(
    stateSlider3, { stateSlider3 = it },
    modifier = Modifier
        .fillMaxWidth(),
    thumbHeightMax = false,
    track = { modifier: Modifier,
                progress: Float,
                _, _, _ ->

        Box(
            Modifier.padding(vertical = 30.dp)
                .height(8.dp).then(modifier)
        ) {
            val bgTrack = Modifier.background(
                Color.Magenta.copy(alpha = 0.5f),
                RoundedCornerShape(100)
            )

            Spacer(bgTrack.fillMaxHeight().then(modifier))

            val bgProgress = Modifier.background(
                Brush.linearGradient(
                    listOf(
                        Color.Green,
                        Color.Red,
                        Color.Blue
                    )
                ),
                RoundedCornerShape(100)
            )

            Spacer(
                bgProgress.fillMaxHeight()
                    .fillMaxWidth(fraction = progress)
                    .then(modifier)
            )
        }
    }, thumb = { modifier, _: Dp,
                    mutableSource,
                    _, _ ->

        var isPressed by remember { mutableStateOf(false) }
        mutableSource.ListenOnPressed { isPressed = it }

        val color by animateColorAsState(
            if (isPressed) Color.Red else Color.Yellow,
            TweenSpec(durationMillis = 200)
        )

        Spacer(
            modifier.background(color)
                .border(1.dp, Color.Red)
        )

    },
    thumbSizeInDp = DpSize(60.dp, 30.dp)
)

About

The code is mainly based on Slider from compose material package with the abilities of additional customization. This project is inspired by swiftui-sliders. Currently we have only SliderValueHorizontal and in the future it is possible to add SliderValueVertical, SliderRangeHorizonta, SliderRangeVertical if there is a demand for it.

License

Copyright 2021 compose-sliders Contributors

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

https://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.
You might also like...
This is a android custom view , like a scratch card effect!
This is a android custom view , like a scratch card effect!

ScratchView This is a android custom view , like a scratch card effect! Last Update 采纳DearZack童鞋的优化思路,把计算擦除面积比例的操作放在手指离开屏幕时,以降低对CPU的占用。 Articles Scrat

An Android custom view to display digits rendered as dots in a grid, with a style like a 1970s LED clock.
An Android custom view to display digits rendered as dots in a grid, with a style like a 1970s LED clock.

#DotMatrixView This is an Android library project providing a custom view that can display things on a grid of dots. When the displayed value changes,

a custom view that provides dragged and scaled
a custom view that provides dragged and scaled

DragScaleCircleView A custom imageview that provides the circle window can be dragged and scaled, crop image. How does it look? Why? Sometimes need to

 NumberPickerView - Custom Android View to provide a user friendly way of picking numbers. 🧪
NumberPickerView - Custom Android View to provide a user friendly way of picking numbers. 🧪

🚀 Custom view for Android which provides a modern design and gestures for picking numbers in a user friendly way.

Custom & highly configurable seek slider with sliding intervals, disabled state and every possible setting to tackle!
Custom & highly configurable seek slider with sliding intervals, disabled state and every possible setting to tackle!

LabeledSeekSlider Custom & highly configurable seek slider with sliding intervals, disabled state and every possible setting to tackle! Minimum target

A custom liquidbounce for redesky.com

FDPClient A free mixin-based injection hacked-client for Minecraft using Minecraft Forge based on LiquidBounce. Website: https://fdp.liulihaocai.pw/ L

Android Custom CountDownView
Android Custom CountDownView

Android Custom CountDownView

DailyTags - a flexible markdown library that supports custom tags and markups
DailyTags - a flexible markdown library that supports custom tags and markups

The library parses a given markup into rich text for Jetpack Compose. DailyTags comes with Markdown and HTML support by default (please, see the supported features) and is very easy to extend to support custom markups.

 🗨️ Beautiful Dialog is a Simple and Beautiful custom dialog
🗨️ Beautiful Dialog is a Simple and Beautiful custom dialog

Beautiful Dialog 🗨️ Beautiful Dialog is a Simple and Beautiful custom dialog. Screenshots Including in your project Gradle Add below codes to your ro

Releases(0.1.4)
Owner
Vladislav Krot
I launch android / ios apps with KMM and learn data science
Vladislav Krot
Useful library to use custom fonts in your android app

EasyFonts A simple and useful android library to use custom fonts in android apps without adding fonts into asset/resource folder.Also by using this l

Vijay Vankhede 419 Sep 9, 2022
(Deprecated) A custom view component that mimics the new Material Design Bottom Navigation pattern.

BottomBar (Deprecated) I don't have time to maintain this anymore. I basically wrote the whole library in a rush, without tests, while being a serious

Iiro Krankka 8.4k Dec 29, 2022
Custom android music player view.

InteractivePlayerView Custom android music player view. Screen Check it on youtube Usage(XML) Define it in your xml file. <co.mobiwise.library.Intera

Mert Şimşek 744 Dec 25, 2022
Android Library for Custom Switches.

Android Library for Custom Switches.

Angad Singh 376 Jan 4, 2023
Custom wheel widget for android

Wheel widget for Android To include the wheel widget in the current layout, you should add in the layout xml this lines: <it.sephiroth.android

Alessandro Crugnola 384 Nov 21, 2022
IconicDroid is a custom Android Drawable which allows to draw icons from several iconic fonts.

IconicDroid IconicDroid is a custom Android Drawable which allows to draw icons from several iconic fonts. Try out the sample application on the Googl

Artur Termenji 387 Nov 20, 2022
Set custom font in Android application

MagicViews Provides a simple way to set custom font in Android application. Adding to your project Add the library as a dependency to your build.gradl

Ivan Kocijan 225 Nov 20, 2022
A beautiful Android custom View that works similar to a range or seekbar. With animations.

ValueBar A beautiful Android custom View that works similar to a range or seekbar. Selection by gesture. With animations. Supporting API level 11+. De

Philipp Jahoda 147 Nov 20, 2022
An android custom view that displays a circle with a colored arc given a mark

MarkView An android custom view that displays a circle with a colored arc given a mark. Usage Add as a dependency compile 'com.github.xiprox.markv

İhsan Işık 200 Nov 25, 2022
Custom UI control for android which is showing data as a segments and a value inside them.

Segmented Bar View for Android Custom UI control for android which is showing data as a segments and a value inside them. Screenshots Install From rep

GSPD 354 Nov 10, 2022