{"id":17118132,"url":"https://github.com/zach-klippenstein/compose-autotransition","last_synced_at":"2025-04-13T02:32:28.420Z","repository":{"id":44367493,"uuid":"512283139","full_name":"zach-klippenstein/compose-autotransition","owner":"zach-klippenstein","description":"A simple library for automatically animating between Compose states.","archived":false,"fork":false,"pushed_at":"2022-07-10T19:18:04.000Z","size":119,"stargazers_count":80,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-26T20:49:29.042Z","etag":null,"topics":["android","animation","jetpack-compose"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zach-klippenstein.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-09T20:50:38.000Z","updated_at":"2025-03-10T21:57:13.000Z","dependencies_parsed_at":"2022-09-07T02:11:26.417Z","dependency_job_id":null,"html_url":"https://github.com/zach-klippenstein/compose-autotransition","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zach-klippenstein%2Fcompose-autotransition","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zach-klippenstein%2Fcompose-autotransition/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zach-klippenstein%2Fcompose-autotransition/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zach-klippenstein%2Fcompose-autotransition/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zach-klippenstein","download_url":"https://codeload.github.com/zach-klippenstein/compose-autotransition/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248657819,"owners_count":21140842,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","animation","jetpack-compose"],"created_at":"2024-10-14T17:53:31.562Z","updated_at":"2025-04-13T02:32:28.173Z","avatar_url":"https://github.com/zach-klippenstein.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# compose-autotransition\n\n_Status: Experimental_\n\nA simple library for automatically animating between Compose states.\n\n```kotlin\nvar scale by remember { mutableStateOf(1f) }\nvar elevation by remember { mutableStateOf(0.dp) }\n\nwith(rememberAutoTransition()) {\n    Button(onClick = {\n        withAnimation {\n            scale = 0.5f\n            elevation = 8.dp\n        }\n    }) { /* … */ }\n}\n```\n\nThe main component of this library is the `AutoTransition.withAnimation` function, which takes a\nblock and animates changes to any snapshot state objects (such as those created by `mutableStateOf`)\nwritten to inside the block. Use the `rememberAutoTransition()` Composable function to get an\ninstance of `AutoTransition`.\n\n`withAnimation` uses Compose's snapshot system to determine what state you changed in the block and\nthen launches a coroutine to animate it. It does this by running the block in a snapshot, then\ndisposing the snapshot without applying it. Since the snapshot is never applied, it's important to\nnot perform side effects in the `withAnimation` block, or to write to any states not backed by\nsnapshot state.\n\n## Demo\n\nhttps://user-images.githubusercontent.com/101754/178158724-e67477be-4569-48c9-9955-cf5d01f1ccd9.mp4\n\n## Customization\n\nBy default, `withTransition` can animate changes to any `MutableState` objects holding values of\ntypes that Compose ships with `TwoWayConverter` vector converters for. This set is defined in\n`DefaultAdapters.kt`. To specify how to handle additional types (either additional state object\ntypes or value types inside `MutableState`s), provide a custom `AutoTransitionFactory` using\n`AutoTransitionFactory.Builder` and `LocalAutoTransitionFactory`.\n\nHere's an example of providing an adapter for a custom value type:\n\n```kotlin\nclass Temp(val degrees: Float)\n\n@Composable\nfun App() {\n    val factory = remember {\n        AutoTransitionFactory.Builder()\n            .addAdapterRegistry(MutableStateAdapter(\n                Temp::class,\n                TwoWayConverter(\n                    convertToVector = { /* … */ },\n                    convertFromVector = { /* … */ }\n                )\n            ))\n            .build()\n    }\n\n    CompositionLocalProvider(LocalAutoTransitionFactory provides factory) {\n        // Rest of app.\n        HomeScreen()\n    }\n}\n\n@Composable\nfun HomeScreen() {\n    with(rememberAutoTransition()) {\n        // …\n    }\n}\n```\n\nThe `AutoTransitionFactory.Builder` can also override the default animation spec.\n\n## TODO\n\n- [x] Write docs.\n- [ ] Release on Maven.\n- [ ] Support multiplatform.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzach-klippenstein%2Fcompose-autotransition","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzach-klippenstein%2Fcompose-autotransition","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzach-klippenstein%2Fcompose-autotransition/lists"}