{"id":13989468,"url":"https://github.com/IFTTT/SparkleMotion","last_synced_at":"2025-07-22T10:32:37.240Z","repository":{"id":29514395,"uuid":"33052737","full_name":"IFTTT/SparkleMotion","owner":"IFTTT","description":"A ViewPager animator that animates Views within pages as well as views across pages.","archived":false,"fork":false,"pushed_at":"2023-10-11T20:40:11.000Z","size":2289,"stargazers_count":339,"open_issues_count":4,"forks_count":49,"subscribers_count":28,"default_branch":"main","last_synced_at":"2024-11-29T06:35:27.052Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IFTTT.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-03-28T22:30:01.000Z","updated_at":"2024-03-31T14:15:59.000Z","dependencies_parsed_at":"2024-01-15T16:51:36.852Z","dependency_job_id":null,"html_url":"https://github.com/IFTTT/SparkleMotion","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/IFTTT%2FSparkleMotion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IFTTT%2FSparkleMotion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IFTTT%2FSparkleMotion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IFTTT%2FSparkleMotion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IFTTT","download_url":"https://codeload.github.com/IFTTT/SparkleMotion/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227079411,"owners_count":17728002,"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-09T13:01:40.466Z","updated_at":"2024-11-29T08:31:29.027Z","avatar_url":"https://github.com/IFTTT.png","language":"Java","funding_links":[],"categories":["Java"],"sub_categories":[],"readme":"## Deprecated\nThis project is not being developed. Feel free to fork!\n\u003cbr/\u003e\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n[![Open Source at IFTTT](http://ifttt.github.io/images/open-source-ifttt.svg)](http://ifttt.github.io)\n\n![Sparkle Motion](./art/sparklemotion-title.png)\n\n[![Build Status](https://travis-ci.org/IFTTT/SparkleMotion.svg?branch=more_tests)](https://travis-ci.org/IFTTT/SparkleMotion)\n\nSparkle Motion is a ViewPager animator that animates Views within pages as well as views across pages.\n\n![Sparkle Motion](./art/sparklemotion.gif)\n\n## Overview\nSparkle Motion is an animation library dedicated to animate ViewPager elements. \n\nSparkle Motion supports cross page animations, meaning that you can animate Views outside of ViewPager based on the ViewPager's scrolling, thus achieve cross-page animations. This is done through `Decor` and `SparkleViewPagerLayout`. By using them, you can specify Views that you want to animate through multiple pages, and the animations on them will be controlled by the OnPageChangeListener.\n\nSparkle Motion can also animate Views within ViewPager. It uses ViewPager's [PageTransformer](http://developer.android.com/reference/android/support/v4/view/ViewPager.PageTransformer.html) to control the progress of the animations, so that the animated Views respond to the scrolling, and thus provides an interactive effect.\n\n\n## Usage\nAdd Sparkle Motion as dependency via Gradle:\n\n```groovy\ncompile 'com.ifttt:sparklemotion:1.0.1'\n```\n\n## JazzHands and RazzleDazzle\nLooking for libraries to build awesome keyframe animations like Sparkle Motion on iOS? Check out [`JazzHands`](https://github.com/IFTTT/JazzHands) and [`RazzleDazzle`](https://github.com/IFTTT/RazzleDazzle).\n\n## Cross Page Animations \nOne of the main features that Sparkle Motion offers is running cross page animations with ViewPager. Animations that require to be animated across different pages needs to be run on `Decor`, which is an element within `SparkleViewPagerLayout`. \n\n### SparkleViewPagerLayout\n`SparkleViewPagerLayout` is a custom FrameLayout that controls `Decor` objects to play ViewPager cross page animations. **To use this layout with SparkleMotion, you need to supply a ViewPager as a child View**. This can be done in layout xml or through `addView()` method. \n\nNote that you should only have one ViewPager child in this layout.\n\nExample for layout xml,\n\n```xml\n\u003ccom.ifttt.sparklemotion.SparkleViewPagerLayout\n        android:id=\"@+id/view_pager_layout\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\u003e\n\n        \u003candroid.support.v4.view.ViewPager\n            android:id=\"@+id/view_pager\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"match_parent\"/\u003e\n\n\u003c/com.ifttt.sparklemotion.SparkleViewPagerLayout\u003e\n\n```\n\n### Decor\nA `Decor` is a component that holds information about a View that should be controlled by the ViewPager and animates when there is at least one `Animation` associated.\n\n\nImportant attributes of a `Decor`:\n\n* `contentView`: required element for a Decor, a View that should be used to animate across pages.\n* `page`: starting from which page the Decor should be presented, and on which page the Decor should be hidden. Controlled by `Page` object.\n* `layoutBehindViewPage`: whether or not the Decor should be drawn behind the ViewPager within SparkleViewPagerLayout.\n* `slideOut`: if used, this Decor will be scrolled along with the ViewPager at the end of its range, instead of being hidden by the layout.\n\nTo build a Decor, simply use `Decor.Builder`.\n\nTo assign an animation to Decor, in your Activity, for example, \n\n```java\nSparkleViewPagerLayout viewPagerLayout = (SparkleViewPagerLayout) findViewById(/* view_pager_id */);\nView contentView = new View(this);\n\n// Both the animation and the Decor exists in the first page.\nPage firstPage = Page.singlePage(0);\nAlphaAnimation alphaAnimation = new AlphaAnimation(firstPage, 0f, 1f);\n\nDecor decor = new Decor.Builder(contentView)\n\t\t .setPage(firstPage)\n\t\t .build();\n\t\t \nSparkleMotion.with(viewPagerLayout)\n\t\t .animate(alphaAnimation)\n\t\t .on(decor);\n```\n\na `Decor` will then be added to your `SparkleViewPagerLayout`, which will run the `alphaAnimation` during ViewPager scrolling.\n\nA `Decor.Builder` supports following methods,\n\n```java\nDecor decor = new Decor.Builder(View) // Content View of the Decor, must not be null\n\n                .setPage(Page)        // Set the Page attribute for this Decor, default to Page.allPages()\n                                \n                .behindViewPage()     // Set to draw the content View behind the ViewPager\n                \n                .slideIn()\t\t      // Set to scroll with ViewPager before the first visible page\n                \n                .slideOut()           // Set to scroll with ViewPager after last visible page\n                \n                .withLayer()          // Set to use hardware layer when animating this Decor's content View\n                \n                .build();\n\t\t\t\n```\n\n## ViewPager Animations\nSparkle Motion can also run animations on Views within the ViewPager. To add an animation to a View using Sparkle Motion,\n\n```java\nViewPager viewPager = (ViewPager) findViewById(/* view_pager_id */);\nAlphaAnimation alphaAnimation = new AlphaAnimation(Page.allPages(), 0f, 1f);\nSparkleMotion.with(viewPager)\n\t\t .animate(mAnimation)\n\t\t .on(R.id.view_id)\n```\n\nIn the code snippet above, `AlphaAnimation` is a class that Sparkle Motion contains for running alpha animation on View (See [here](#supported_animations) for details about supported animations). `R.id.view_id` is the id of the View inside the page that is going to run the animation, you can also use `Animation.FULL_PAGE` instead of specific View id to apply this animation to the page View itself.\n\n\n\u003ca name=\"supported_animations\"\u003e\u003c/a\u003e\n## Animation\n`Animation` is an abstract class for storing animation information for Sparkle Motion. To animate a View through Sparkle Motion, you need to assign an `Animation` instance to a View, so that Sparkle Motion will know how to animation it.\n\nTo create an instance of `Animation`, you need to pass an instance of [`Page`](#page), and the animation will be run through the pages that you assign to. \n\n### Supported animations\nSparkle Motion provides several animation classes that can be used directly to animate View properties.\n\n* Basic View animations:\n    * `AlphaAnimation`: animates the alpha property of the target Views.\n    * `RotationAnimation`: animates the rotation property of the target Views.\n    * `ScaleAnimation`: animates the scale X and/or Y properties of the target Views.\n    * `TranslationAnimation`: animates the translation X and/or Y properties of the target Views.\n* `PathAnimation`: animates the target Views' translation X and Y so that it follows a [path](http://developer.android.com/reference/android/graphics/Path.html).\n* `ParallaxAnimation`: animates the target Views' translation X to the opposite direction of the ViewPager scrolling to achieve a parallax effect.\n\n### Custom animations\nSparkle Motion also supports customized animations through extending `Animation` class. There are 3 methods in `Animation` class that you might be interested:\n\n* `onAnimate(View v, float offset, float offsetInPixel)`: main method to override to provide customized animation. \n* `onAnimateOffScreenLeft(View v, float offset, float offsetInPixel)` (optional): this method will be called when `offset` \u003c -1, which means the page is currently to the left of the screen.\n* `onAnimateOffScreenRight(View v, float offset, float offsetInPixel)`(optional): this method will be called when `offset` \u003e 1, which means the page is currently to the right of the screen.\n\nThere are differences between running an Animation on a View within ViewPager an on a Decor: \n\n* For View animations, the `offset` value is ranged within [-1, 1], `offsetInPixel` is the negative value of the scrolling offset of the entire page in pixel.\n*  For Decor animations, the `offset` value is ranged within [0, 1], `offsetInPixel` will always be 0 as they are not part of the ViewPager and are not scrolled along with the ViewPager by default.\n*  `onAnimateOffScreenLeft` and `onAnimateOffScreenRight` will be called on for animations running on Views inside ViewPager.\n\n\n\u003ca name=\"page\"\u003e\u003c/a\u003e\n## Page \nBoth `Animation` and `Decor` have an attribute that ties to the index of the pages, controlling whether or not the animation should run or the Decor should be shown. In Sparkle Motion we use a class `Page` to control such attribute. \n\n`Page` provides 3 methods to return a Page object that controls the page attribute:\n\n* `allPages()`: indicates the animation should be run for all pages, or the Decor should be shown across all pages.\n* `singlePage(int)`: indicates the animation should be run on a specific page or the Decor should be shown on a specific page.\n* `pageRange(int, int)`: indicates the animation should be run on a range of pages or the Decor should be shown on a range of pages. \n\nFor Decor, a page stands for the period where the page is still visible. For example, if a Decor has `Page.singlePage(0)`, the Decor is visible from the point where the page at index 0 is the current page, till the page at index 1 is the current page. \n\nFor animations that will run on multiple pages, the progress of the animation will be evenly split across the pages. For ViewPager View animation, it might not be necessary to run such animation, as the View will be invisible once the page is scrolled off-screen.\n\n## Sparkle Motion and PageTransformer\nYou can use Sparkle Motion instead of PageTransformer to play regular ViewPager page animations. One example is the `ZoomOutAnimation`, which takes the [PageTransformer implementation](http://developer.android.com/training/animation/screen-slide.html#pagetransformer) and implement as an Animation class. Simply apply this to the entire page to achieve the same effect.\n\nIf you need to have a custom PageTransformer for your ViewPager while using Sparkle Motion, you need to call `SparkleMotionCompat.setPageTransformer(ViewPager, boolean, PageTransformer)` to set your PageTransformer.\n\n## Contributors\n* [Zhe Lu](https://github.com/lzanita09)\n* [Eric Cochran](https://github.com/NightlyNexus)\n\n## Contributing\n\n1. Fork it ( https://github.com/[my-github-username]/SparkleMotion/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## License\n\n`Sparkle Motion` is available under the MIT license. See the LICENSE file for more info.\n\nCopyright 2015 IFTTT Inc.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIFTTT%2FSparkleMotion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FIFTTT%2FSparkleMotion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIFTTT%2FSparkleMotion/lists"}