- Notifications
You must be signed in to change notification settings - Fork75
Android LiquidSwipe Library
License
Chrisvin/LiquidSwipe
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Android LiquidSwipe Library
![]() | ![]() |
---|---|
Default | Touch Interactive |
LiquidSwipe is a viewpager library that can be used to make awesome onboarding designs. (Default Demo apk) (TouchInteractive Demo apk)
If you like this, you'll likeConcentricOnboarding as well.
To run the demo project, clone the repository and run it via Android Studio.
(OR)
Download the latest demo apk fromreleases.
- Add the JitPack repository to your root build.gradle at the end of repositories:
allprojects {repositories {...maven { url 'https://jitpack.io' }}}
- Add the LiquidSwipe dependency in the build.gradle:
implementation 'com.github.Chrisvin:LiquidSwipe:1.3'
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <com.jem.liquidswipe.LiquidSwipeViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="match_parent"/></androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?><com.jem.liquidswipe.layout.LiquidSwipeConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".DummyFragment"> <!-- Fill with your views, just like you would in a normal ConstraintLayout --></com.jem.liquidswipe.layout.LiquidSwipeConstraintLayout><!-- Also supports LiquidSwipeFrameLayout & LiquidSwipeLinearLayout -->
Note :Dokka generated documentation on LiquidSwipeLayouts
Rather than having the wave center Y value always be layout.height/2 , it would be more aesthetically pleasing for it to be the same as the touch Y value.The following code can be used to dynamically change thewaveCenterY
based on the touch position on theLiquidSwipeViewPager
.(The reason this isn't done internally in the library is because the viewpager layouts don't get the touch events when said touch events are consumed directly by the viewpager)
- In the
Activity
/Fragment
class containing theLiquidSwipeViewPager
// Create an array of LiquidSwipeCPP, one for each layout in the PagerAdapterval liquidSwipeClipPathProviders=Array(titleArray.count()) {LiquidSwipeClipPathProvider()}// Pass the LiquidSwipeCPP array to the adapterviewpager.adapter=CustomPagerAdapter(this, liquidSwipeClipPathProviders)// Similar logic can also be applied for your custom FragmentPagerAdapter/FragmentStatePagerAdapter// Listen to onTouch events on the viewpager and update the waveCenterY value of the LiquidSwipeCPPsviewpager.setOnTouchListener { _, event->val waveCenterY= event.y liquidSwipeClipPathProviders.map { it.waveCenterY= waveCenterY }false}
- In the
PagerAdapter
// Set the layout's clipPathProvider to the corresponding `LiquidSwipeClipPathProvider`(layoutas?LiquidSwipeLayout)?.clipPathProvider= liquidSwipeClipPathProviders[position]
The above code has been showcased in the demo app, feel free to look at it for reference.
Note:This is not a perfect solution, in fact some artifacts might occur due to the quick waveCenterY value jumps.But for now, this is the cleanest solution I can think of.Anyone else with a better solution is welcome to fork and submit a pull request. :)
The concept for theClipPathProvider
in LiquidSwipe is the same as that in theEasyReveal library (If you haven't already, then you should really check it out, infact the first version of LiquidSwipe usedEasyReveal as a dependency).
You can create your own swipe animation by extending theClipPathProvider and implementing thegetPath()
method.getPath()
provides thePath for a givenpercent value on the providedview. The path gotten fromgetPath()
is then used to clip the view usingcanvas.clipPath(path, op)
(Theop
value is provided by theClipPathProvider
as well). You can then set your customClipPathProvider to your layouts.
Documentation generated using Dokka :chrisvin.github.io/LiquidSwipe
For bugs, questions and discussions please use theGithub Issues.
- Cuberto's liquid-swipe for iOS - Source of inspiration
- Alvaro Fabre - Designer of the lottie animations in the demo app
MIT LicenseCopyright (c) 2019 JemPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.
About
Android LiquidSwipe Library