{"id":14373935,"url":"https://github.com/KlassenKonstantin/ComposePhysicsLayout","last_synced_at":"2025-08-22T19:32:02.359Z","repository":{"id":64580278,"uuid":"576626587","full_name":"KlassenKonstantin/ComposePhysicsLayout","owner":"KlassenKonstantin","description":"A custom Compose layout backed by a physics engine","archived":false,"fork":false,"pushed_at":"2023-05-14T10:43:54.000Z","size":260,"stargazers_count":449,"open_issues_count":0,"forks_count":16,"subscribers_count":9,"default_branch":"main","last_synced_at":"2023-11-07T14:55:20.565Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KlassenKonstantin.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-12-10T13:03:32.000Z","updated_at":"2023-11-06T09:39:18.000Z","dependencies_parsed_at":"2023-02-09T22:00:28.906Z","dependency_job_id":null,"html_url":"https://github.com/KlassenKonstantin/ComposePhysicsLayout","commit_stats":null,"previous_names":[],"tags_count":1,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KlassenKonstantin%2FComposePhysicsLayout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KlassenKonstantin%2FComposePhysicsLayout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KlassenKonstantin%2FComposePhysicsLayout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KlassenKonstantin%2FComposePhysicsLayout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KlassenKonstantin","download_url":"https://codeload.github.com/KlassenKonstantin/ComposePhysicsLayout/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":217270456,"owners_count":16151247,"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":[],"created_at":"2024-08-28T02:01:14.387Z","updated_at":"2024-08-28T02:02:51.705Z","avatar_url":"https://github.com/KlassenKonstantin.png","language":"Kotlin","funding_links":[],"categories":["Android"],"sub_categories":["Android samples"],"readme":"# Physics Layout\n![Maven Central](https://img.shields.io/maven-central/v/io.github.klassenkonstantin/physics-layout?style=flat-square\u0026versionPrefix=0.4)\n\nThis library offers a [dyn4j](https://www.dyn4j.org) wrapper for [Jetpack Compose](https://developer.android.com/jetpack/compose).\n\n## 🚧 Experimental 🚧\nBefore reaching version 1.0, this library is considered experimental, which means that there is no guaranteed backwards compatibility between versions. Signatures, interfaces, names, etc. may and will most likely change.\n\n## Sample App\nhttps://user-images.githubusercontent.com/1836066/206856910-d2172e7e-64da-454e-99b9-8171cf5f5eeb.mov\n\n## Download\n```\ndependencies {\n    implementation 'io.github.klassenkonstantin:physics-layout:\u003cversion\u003e'\n}\n```\n\n# How to use\nTo get started, create a `PhysicsLayout` and add arbitrary content to it. Add the `physicsBody` modifier to Composables that should be part of the physics simulation.\n\n## PhysicsLayout\n```kotlin\n@Composable\nfun PhysicsLayout(\n    modifier: Modifier = Modifier,\n    shape: Shape? = RectangleShape,\n    scale: Dp = DEFAULT_SCALE,\n    simulation: Simulation = rememberSimulation(),\n    content: @Composable BoxScope.() -\u003e Unit\n)\n```\n- `shape`: The shape of the outer border of the `PhysicsLayout`\n- `scale`: How many Dps should be considered one meter. Bodies shouldn't be smaller than one meter\n- `simulation`: Does the mapping between layout and physics engine\n- `content`: The arbitrary layout\n\n## physicsBody modifier\n```kotlin\nfun Modifier.physicsBody(\n    id: String? = null,\n    shape: Shape = RectangleShape,\n    bodyConfig: BodyConfig = BodyConfig(),\n    dragConfig: DragConfig? = null,\n)\n```\n- `id`: The id the body should have in the simulation. Useful for operations that act directly on bodies (not yet supported).\n- `shape`: Describes the outer bounds of the body. Supported shapes are:\n  - [RectangleShape](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/package-summary#RectangleShape())\n  - [CircleShape](https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/package-summary#CircleShape())\n  - [RoundedCornerShape](https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/RoundedCornerShape)\n  - [CutCornerShape](https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CutCornerShape)\n- `bodyConfig`: Configures properties of the body\n- `dragConfig`: Set a `DragConfig` to enable drag support, or `null` to disable dragging\n\n## Clock\nBy default `Simulation` uses a default `Clock` which automatically starts running. To pause and resume a `Clock`, create an instance with `rememberClock()` and pass that to the `Simulation`.\n\n### Example usage\n```kotlin\n@Composable\nfun SimpleScreen() {\n    Surface(\n        modifier = Modifier.fillMaxSize(),\n        color = MaterialTheme.colorScheme.background\n    ) {\n        PhysicsLayout {\n            Card(\n                modifier = Modifier.physicsBody(\n                    shape = CircleShape,\n                ).align(Alignment.Center),\n                shape = CircleShape,\n            ) {\n                Icon(\n                    modifier = Modifier\n                        .size(32.dp)\n                        .padding(4.dp),\n                    imageVector = Icons.Default.Star,\n                    contentDescription = \"Star\",\n                    tint = Color.White\n                )\n            }\n        }\n    }\n}\n```\nThis example adds a ball with a star in the center of the layout, which then starts falling to the ground.\n\n\u003e Note: The `shape` must be set on both the body modifier and the `Card`.\n\n### Change gravity\nIf you need to change the gravity of the simulated world, use `Simulation.setGravity`\n\n## Caveats, notes, missing features\n- I don't think Compose was made to display hundreds of Composables at the same time. So maybe it's not a good idea to build a particle system out of this.\n- In general, what is true for all of Compose is especially true for this Layout: **Release builds perform way better than debug builds**.\n- State is not restored on config changes 😱.\n- Currently there is no way to observe bodies / collosions / etc.\n- Not tested with scrolling containers\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKlassenKonstantin%2FComposePhysicsLayout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKlassenKonstantin%2FComposePhysicsLayout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKlassenKonstantin%2FComposePhysicsLayout/lists"}