Git Product home page Git Product logo

speedometer's Introduction

Speedometer

Dynamic Speedometer widget for Compose Multiplatform. amazing, powerful, and multi shape โšก , you can change (colors, bar width, shape, text, font ...everything !!), see project on GitHub.

Currently it supports Android, IOS and Desktop platforms.

This widget is drawn using Compose API only, which makes it work on all platforms that support Compose UI. You can use the Android View-UI SpeedView library for XML View.

Maven Central API Twitter

Speedometers...

Donations

This project needs you! If you would like to support this project, the creator of this project or the continuous maintenance of this project, feel free to donate. Your donation is highly appreciated. Thank you!

PayPal

Download

This library still in alpha stage. Implementations might change in the future.

Requirements to use:

  • Kotlin version 1.8.20 or above.
  • Compose version 1.4.0.
  • Minimum API version 21 (For Android).

Add mavenCentral to your dependency management.

dependencyResolutionManagement {
    repositories {
        // ...
        mavenCentral()
    }
}

Then, add the speedometer dependencies according to your project:

Compose Multiplatform Project

Go to build.gradle.kts file in the shared module. In commonMain dependencies:

sourceSets {
    val commonMain by getting {
        dependencies {
            // Add Speedometer library
            implementation("com.github.anastr:speedometer:1.0.0-ALPHA02")
        }
    }
    // ...
}

Native Android Project

If you want to use the library only in a native Android project. Add this line to build.gradle.kts app module level:

dependencies {
    implementation("com.github.anastr:speedometer-android:1.0.0-ALPHA02")
}

Simple Usage

Currently, this library only supports SpeedView. To use it, just call SpeedView composable like so:

SpeedView(
    modifier = Modifier.size(250.dp),
    speed = 50f,
)

Current speedometers available:

SpeedView AwesomeSpeedometer PointerSpeedometer TubeSpeedometer

By default, this library doesn't implement any animation. To make the indicator move smoothly, use compose animation :

var speed by remember { mutableStateOf(0f) }
val currentSpeed by animateFloatAsState(
    targetValue = speed,
    animationSpec = tween(durationMillis = 2000, easing = FastOutSlowInEasing)
)
Column(
    modifier = Modifier
        .fillMaxWidth()
        .padding(12.dp),
    horizontalAlignment = Alignment.CenterHorizontally,
) {
    SpeedView(
        modifier = Modifier.size(250.dp),
        speed = currentSpeed,
    )
    Button(
        onClick = {
            // Change speed to start the animation
            speed = Random.nextFloat() * 100
        },
    ) {
        Text("Random speed")
    }
}

speedometer's People

Contributors

anastr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

speedometer's Issues

LayoutNode should be attached to an owner

When I navigate back from a screen that uses this Speedometer Composable it sometimes throws this exception.

Some Info:

  • KMP project
  • Navigation with Decompose + Router
  • kotlin = "1.9.10"
  • agp = "8.1.2"
  • compose = "1.5.1"
PID: 6165
java.lang.IllegalStateException: LayoutNode should be attached to an owner
    at androidx.compose.ui.node.LayoutNodeKt.requireOwner(LayoutNode.kt:1448)
    at androidx.compose.ui.node.LayoutNode.invalidateSemantics$ui_release(LayoutNode.kt:412)
    at androidx.compose.ui.node.SemanticsModifierNodeKt.invalidateSemantics(SemanticsModifierNode.kt:92)
    at androidx.compose.foundation.text.modifiers.TextAnnotatedStringNode.doInvalidations(TextAnnotatedStringNode.kt:210)
    at androidx.compose.foundation.text.modifiers.TextAnnotatedStringElement.update(TextAnnotatedStringElement.kt:67)
    at androidx.compose.foundation.text.modifiers.TextAnnotatedStringElement.update(TextAnnotatedStringElement.kt:36)
    at androidx.compose.ui.node.NodeChainKt.updateUnsafe(NodeChain.kt:808)
    at androidx.compose.ui.node.NodeChainKt.access$updateUnsafe(NodeChain.kt:1)
    at androidx.compose.ui.node.NodeChain.updateNode(NodeChain.kt:653)
    at androidx.compose.ui.node.NodeChain.updateFrom$ui_release(NodeChain.kt:138)
    at androidx.compose.ui.node.LayoutNode.setModifier(LayoutNode.kt:844)
    at androidx.compose.ui.node.ComposeUiNode$Companion$SetModifier$1.invoke(ComposeUiNode.kt:47)
    at androidx.compose.ui.node.ComposeUiNode$Companion$SetModifier$1.invoke(ComposeUiNode.kt:47)
    at androidx.compose.runtime.ComposerImpl$apply$operation$1.invoke(Composer.kt:1712)
    at androidx.compose.runtime.ComposerImpl$apply$operation$1.invoke(Composer.kt:1710)
    at androidx.compose.runtime.CompositionImpl.applyChangesInLocked(Composition.kt:818)
    at androidx.compose.runtime.CompositionImpl.applyChanges(Composition.kt:849)
    at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$1.invoke(Recomposer.kt:625)
    at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$1.invoke(Recomposer.kt:537)
    at androidx.compose.ui.platform.AndroidUiFrameClock$withFrameNanos$2$callback$1.doFrame(AndroidUiFrameClock.android.kt:41)
    at androidx.compose.ui.platform.AndroidUiDispatcher.performFrameDispatch(AndroidUiDispatcher.android.kt:109)
    at androidx.compose.ui.platform.AndroidUiDispatcher.access$performFrameDispatch(AndroidUiDispatcher.android.kt:41)
    at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.doFrame(AndroidUiDispatcher.android.kt:69)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1350)
    at android.view.Choreographer.doCallbacks(Choreographer.java:1149)
    at android.view.Choreographer.doFrame(Choreographer.java:1040)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1333)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:233)
    at android.app.ActivityThread.main(ActivityThread.java:8030)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
    Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.runtime.PausableMonotonicFrameClock@fffc223, androidx.compose.ui.platform.MotionDurationScaleImpl@71e8320, StandaloneCoroutine{Cancelling}@eb1c4d9, AndroidUiDispatcher@4811e9e]

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.