Giter Club home page Giter Club logo

compose-numberpicker's Introduction

Jetpack Compose Number Picker

Android library providing a Number Picker for Jetpack Compose.

chargemap

Maven version

License MIT Android minimuml version

Showcase

Installation

In your module build.gradle :

dependencies {
  implementation "com.chargemap.compose:numberpicker:latestVersion"
}

Usage

Simple NumberPicker

var pickerValue by remember { mutableStateOf(0) }

NumberPicker(
    value = pickerValue,
    range = 0..10,
    onValueChange = {
        pickerValue = it
    }
)

24 hours HoursNumberPicker

var pickerValue by remember { mutableStateOf<Hours>(FullHours(12, 43)) }

HoursNumberPicker(
    dividersColor = MaterialTheme.colors.primary,
    leadingZero = false,
    value = pickerValue,
    onValueChange = {
        pickerValue = it
    },
    hoursDivider = {
        Text(
            modifier = Modifier.size(24.dp),
            textAlign = TextAlign.Center,
            text = ":"
        )
    }
)

AM/PM HoursNumberPicker

var pickerValue by remember { mutableStateOf<Hours>(AMPMHours(9, 12, AMPMHours.DayTime.PM )) }

HoursNumberPicker(
    dividersColor = MaterialTheme.colors.primary,
    value = pickerValue,
    onValueChange = {
        pickerValue = it
    },
    hoursDivider = {
        Text(
            modifier = Modifier.padding(horizontal = 8.dp),
            textAlign = TextAlign.Center,
            text = "hours"
        )
    },
    minutesDivider = {
        Text(
            modifier = Modifier.padding(horizontal = 8.dp),
            textAlign = TextAlign.Center,
            text = "minutes"
        )
    }
)

List Picker

val possibleValues = listOf("🍎", "🍊", "πŸ‰", "πŸ₯­", "🍈", "πŸ‡", "🍍")
var state by remember { mutableStateOf(possibleValues[0]) }
ListItemPicker(
    label = { it },
    value = state,
    onValueChange = { state = it },
    list = possibleValues
)

Contributors

chargemap Chargemap Author
pandasys Eric A. Snell Pull Request
pandasys Christian R Pull Request

compose-numberpicker's People

Contributors

cjrcodes avatar pandasys avatar r4phab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

compose-numberpicker's Issues

Suggestion: Accessibility Improvements

Hello!

Consider making this component accessible meaning that it could be used with e.g. TalkBack and keyboards/Dpads. The picker doesn't seem to work on either currently.

Suggestion: Allow horizontal list item picker option

So currently the picker only seems to work vertically, you can scroll the items up and down.

But maybe it would be cool to enable left and right scrolling instead for the picker?

Just an idea, Happy to pick this up and try and have a go at implementing this option if thats ok with you?

Compose 1.4 and higher causes flicker

See the resulting flickering behavior when the spinner switches values.

sampleA.webm

To reproduce it, upgrate to latest compose by adding this to your build.gradle.kts. Any version of compose greater than 1.3.3 has the same behavior

    implementation(platform("androidx.compose:compose-bom:2023.05.01"))
    implementation("androidx.compose.ui:ui")
    implementation("androidx.compose.ui:ui-tooling")
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.material:material")
    implementation("androidx.compose.material:material-icons-core")
    implementation("androidx.compose.material:material-icons-extended")
    implementation("androidx.compose.runtime:runtime-livedata")
    implementation("androidx.activity:activity-compose:1.5.1")
``` `


Larger fonts cause line offset errors

As the font size of the items increases via the textStyle parameter, the values and lines above and below the center value get further and further away from their expected locations. (Adding lineHeight to the TextStyle makes no difference.)

Reference Code:

    val possibleValues = (1945..1975).map { it.toString() }
    var state by remember { mutableStateOf(possibleValues[8]) }
    Spacer(modifier = Modifier.height(40.dp))
    ListItemPicker(
        label = { it },
        list = possibleValues,
        value = state,
        onValueChange = { state = it },
        textStyle = TextStyle(fontSize = 36.sp, fontWeight = FontWeight.Normal),
    )

Result at 16.dp font size:
image

Result at 24.dp font size:
image

Result at 36.dp font size:
image

Consider supporting negative numbers or some type of "rollover"

Example, I display hours minutes seconds to allow the user to enter the duration of a piece of media. They can perform searches on how long a song is - show me all songs over 10 minutes.

For my seconds picker I give the range -1..60. My label function emits an empty string for -1 and 60. When the picker hits 60, I increment my "minutes" and set the "seconds" picker value to 0. Effectively the change is from 0:0:59 to 0:1:0. Works nicely with little effort on my part. The opposite does not work as the picker can never go below 0.

If I set a picker to -1..N, it will display -1 as the smallest value but does not allow me to move to that number. I've only glanced at the code, but could the picker possibly be genericized to work over any ClosedRange using start, endInclusive, and step functions? I'm only concerned with numbers at the moment, but seems this could be an even more versitale widget - a range value picker.

Thanks for publishing this. Very useful as is.

Create a license

There is currently no license on this project so it's unknown on the legality of using this code in other projects. Please add one so others can know what is possible to do with this code.

Layout bug when in ConstraintLayout

Layout bug when in ConstraintLayout (compose)

Here is the screenshot:
θž’εΉ•ζˆͺεœ– 2022-02-04 上午11 00 52

Attached my compose layout code:

ConstraintLayout(
                    modifier = Modifier.fillMaxSize(),
                ) {
                    val (title, picker, btn) = createRefs()
                    var pickerValue by remember { mutableStateOf(2) }
                    Text(text = "Select Next No of People", modifier = Modifier.constrainAs(title) {
                        centerHorizontallyTo(parent)
                        top.linkTo(parent.top)
                    })
                    NumberPicker(
                        modifier = Modifier
                            .constrainAs(picker) {
                                centerHorizontallyTo(parent)
                                top.linkTo(title.bottom)
                            }
                            .size(100.dp, 200.dp),
                        value = pickerValue,
                        range = 0..10,
                        dividersColor = Color.Cyan,
                        onValueChange = {
                            pickerValue = it
                        }
                    )

                    Button(onClick = { /*TODO*/ }, modifier = Modifier.constrainAs(btn) {
                        centerHorizontallyTo(parent)
                        bottom.linkTo(parent.bottom)
                    }) {
                        Text(text = "Click")
                    }
                }

"Repeat" property

"Repeat" Boolean property that if true, will loop back to the bottom of the picker at the top of the picker and vice versa if the picker is at the bottom, similar to a never-ending carousel. (Once the beginning/end is reached, the end/beginning of the list will be the next value in display, instead of having to scroll all the way back to the desired point of the list.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.