{"id":13640714,"url":"https://github.com/VictorAlbertos/SwipeCoordinator","last_synced_at":"2025-04-20T06:34:27.405Z","repository":{"id":85040031,"uuid":"71636870","full_name":"VictorAlbertos/SwipeCoordinator","owner":"VictorAlbertos","description":"A coordinator layout for Android views to animate and typify touch events as swipe gestures","archived":false,"fork":false,"pushed_at":"2020-08-09T10:36:44.000Z","size":653,"stargazers_count":251,"open_issues_count":0,"forks_count":40,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-01-08T09:02:26.268Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","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/VictorAlbertos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-10-22T12:13:10.000Z","updated_at":"2024-12-10T11:20:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"3d0b6799-9182-4edb-ac96-71fc0d18c58b","html_url":"https://github.com/VictorAlbertos/SwipeCoordinator","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorAlbertos%2FSwipeCoordinator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorAlbertos%2FSwipeCoordinator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorAlbertos%2FSwipeCoordinator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorAlbertos%2FSwipeCoordinator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VictorAlbertos","download_url":"https://codeload.github.com/VictorAlbertos/SwipeCoordinator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249859688,"owners_count":21335988,"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-02T01:01:13.735Z","updated_at":"2025-04-20T06:34:27.110Z","avatar_url":"https://github.com/VictorAlbertos.png","language":"Java","funding_links":[],"categories":["进度条"],"sub_categories":[],"readme":"# SwipeCoordinator\n\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-SwipeCoordinator-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/4556)\n\nSwipeCoordinator simplifies the processs of implementing animated swipeable views. It links a view with its parent as a single behavioural unit constrained by the parent boundaries. SwipeCoordinator supports both *left-to-right* and *top-to-bottom* direction.\n\n![Screenshots](swipe_coordinator_left_right.gif)\n\n![Screenshots](swipe_coordinator_top_bottom.gif)\n\n\n## SetUp\n\nAdd to top level *gradle.build* file\n\n```gradle\nallprojects {\n    repositories {\n        maven { url \"https://jitpack.io\" }\n    }\n}\n```\n\nAdd to app module *gradle.build* file\n```gradle\ndependencies {\n    compile 'com.github.VictorAlbertos:SwipeCoordinator:0.0.2'\n}\n```\n\n## Usage\n\nIdentify the swipeable view with `@id/swipeable_view` attribute. Thew ViewGroup containing the swipeable view can not declare any padding attribute, as such as the swipeable view can not declare any margin. Otherwise the calculations will be misleading.  \n\n```xml\n\u003cRelativeLayout\n      android:id=\"@+id/parent_swipeable_view\"\n      android:layout_width=\"match_parent\"\n      android:layout_height=\"?attr/actionBarSize\"\n      android:background=\"@color/colorPrimary\"\u003e\n\n    \u003cView\n        android:id=\"@id/swipeable_view\"\n        android:layout_width=\"?attr/actionBarSize\"\n        android:layout_height=\"?attr/actionBarSize\"\n        android:background=\"@color/colorAccent\"/\u003e\n\n\u003c/RelativeLayout\u003e\n```\n\nCreate an instance of `SwipeCoordinator` suppliyng as argument constructor the parent layout of the swipeable view, and the expected direction for the swipe gesture. \n\n```java\nViewGroup parentSwipeableView = (ViewGroup) findViewById(R.id.parent_swipeable_view);\n    SwipeCoordinator swipeCoordinator =\n        new SwipeCoordinator(parentSwipeableView, SwipeDirection.LEFT_TO_RIGHT);\n```\n\n### ActionUpSwipeListener\n`ActionUpSwipeListener` signals the `MotionEvent` `ACTION_UP` of the swipeable view providing a `boolean` as a flag to indicate if the action took place surpassing the threshold value. This callback is the place to determine if the user fulfilled the motion event. \n\n```java\nswipeCoordinator.setOnActionUpSwipeListener(new SwipeCoordinator.ActionUpSwipeListener() {\n  @Override public void onActionUp(boolean thresholdReached) {\n    if (thresholdReached) Toast.makeText(this, \"Approved\", Toast.LENGTH_SHORT).show();\n    else Toast.makeText(this, \"Pending\", Toast.LENGTH_SHORT).show();\n  }\n});\n```\n\n### ProgressListener\n`ProgressListener` emits the progress of the swipeable view. From 0 to 1, this value represent in percentage the left distance to its fulfilled position. This callback is the perfect place to create animations based on the progress value.\n\n```java\nswipeCoordinator.setProgressListener(new SwipeCoordinator.ProgressListener() {\n  @Override public void onProgress(float progress) {\n    tvAccepted.setScaleX(progress);\n    tvAccepted.setScaleY(progress);\n    tvAccepted.setAlpha(progress);\n  }\n});\n```\n\n### Survive to config changes\n`SwipeCoordinator` exposes `doSwipe` method. It translates the swipeable view to the fulfilled stage and calls `ProgressListener::onProgress(progress)` with a value of 1.0 to restore all the dependent state views (scale, alpha...).\n\n\n### Customization\n\n#### Threshold\nThe value in percentage of the threshold to signal it as reached when the user drops the swipeable view. From 0 to 1, being the default value 0.7.\n\n```java\nswipeCoordinator.setThreshold(0.5f);\n```\n\n#### Variance percentage\nIncrement (if number greater than 1.0) or decrement (if number less than 1.0) the duration of the rearrange animation performed when the user drops the swipeable view. Default value is 1.0.\n\n```java\nswipeCoordinator.setVariancePercentage(0.5f);\n```\n\n### Examples\nThe module [test-sample](https://github.com/VictorAlbertos/SwipeCoordinator/tree/master/test-sample) contains both example and UI test driven by Espresso.\n\n## Author\n\n**Víctor Albertos**\n\n* \u003chttps://twitter.com/_victorAlbertos\u003e\n* \u003chttps://www.linkedin.com/in/victoralbertos\u003e\n* \u003chttps://github.com/VictorAlbertos\u003e\n\n\n## Another author's libraries:\n* [BreadcrumbsView](https://github.com/VictorAlbertos/BreadcrumbsView): A customizable Android view for paginated forms.\n* [Mockery](https://github.com/VictorAlbertos/Mockery): Android and Java library for mocking and testing networking layers with built-in support for Retrofit.\n* [ReactiveCache](https://github.com/VictorAlbertos/ReactiveCache): A reactive cache for Android and Java which honors the Observable chain.\n* [RxActivityResult](https://github.com/VictorAlbertos/RxActivityResult): A reactive-tiny-badass-vindictive library to break with the OnActivityResult implementation as it breaks the observables chain. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVictorAlbertos%2FSwipeCoordinator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FVictorAlbertos%2FSwipeCoordinator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVictorAlbertos%2FSwipeCoordinator/lists"}