Code Monkey home page Code Monkey logo

nestedtouchscrollinglayout's Introduction

NestedTouchScrollingLayout

Platform SDK

This layout is used to support dispatch touch event. There has some example gif~

主要用来做 View 的无缝拖拽,详细效果看 gif~


Author Jarvis
E-mail [email protected]

效果

demo1 demo2
normal webview
demo3 demo4
bottomsheet normal bottomsheet appbarlayout
demo8 demo9
webview recyclerview imageview recyclerview
demo6
scene1 scene2

Usage example

normal use

<jarvis.com.library.NestedTouchScrollingLayout
    android:id="@+id/wrapper"
    android:layout_gravity="center"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/container_rv"
        android:layout_width="match_parent"
        android:layout_height="400dp"
        android:background="#fff"
        android:overScrollMode="always">
    </android.support.v7.widget.RecyclerView>

</jarvis.com.library.NestedTouchScrollingLayout>
// 设置手指下拉阻尼
mNestedTouchScrollingLayout.setDampingDown(2.0f / 5);
// 设置手指上拉阻尼
mNestedTouchScrollingLayout.setDampingUp(3.0f / 5);

mNestedTouchScrollingLayout.registerNestScrollChildCallback(new NestedTouchScrollingLayout.INestChildScrollChange() {
        
        // 当前 Layout 偏移距离
	@Override
	public void onNestChildScrollChange(float deltaY) {

	}
	
	// finger 脱离屏幕 Layout 偏移量,以及当前 Layout 的速度
	@Override
	public void onNestChildScrollRelease(final float deltaY, final int velocityY) {
		mNestedTouchScrollingLayout.recover(0, new Runnable() {
			@Override
			public void run() {
				Log.i("NestedTouchScrollingLayout ---> ", "deltaY : " + deltaY + " velocityY : " + velocityY);
			}
		});
	}
	// 手指抬起时机
	@Override
	public void onFingerUp(float velocityY) {

	}

	// 横向拖拽
	@Override
	public void onNestChildHorizationScroll(MotionEvent event, float deltaX, float deltaY) {
	
	}
});

bottomsheet use

 <jarvis.com.library.NestedTouchScrollingLayout
	android:id="@+id/wrapper"
	android:layout_marginTop="30dp"
	android:layout_width="match_parent"
	android:layout_height="match_parent">

	<android.support.v7.widget.RecyclerView
		android:background="#fff"
		android:id="@+id/container_rv"
		android:layout_width="match_parent"
		android:layout_height="match_parent" />

</jarvis.com.library.NestedTouchScrollingLayout>
// 临界速度,根据业务而定
public static int mVelocityYBound = 1300;

// 规定 sheetView 弹起方向
mNestedTouchScrollingLayout.setSheetDirection(NestedTouchScrollingLayout.SheetDirection.BOTTOM);

mNestedTouchScrollingLayout.registerNestScrollChildCallback(new NestedTouchScrollingLayout.INestChildScrollChange() {
	@Override
	public void onNestChildScrollChange(float deltaY) {

	}

	@Override
	public void onNestChildScrollRelease(final float deltaY, final int velocityY) {
		int totalYRange = mNestedTouchScrollingLayout.getMeasuredHeight();
		int helfLimit = (totalYRange - DisplayUtils.dpToPixel(BottomSheetActivity.this, 400)) / 2;
		int hideLimit = totalYRange - DisplayUtils.dpToPixel(BottomSheetActivity.this, 400) / 2;
		int helfHeight = totalYRange - DisplayUtils.dpToPixel(BottomSheetActivity.this, 400);
		if (velocityY > mVelocityYBound && velocityY > 0) {
			if (Math.abs(deltaY) > helfHeight) {
				mNestedTouchScrollingLayout.hiden();
			} else {
				mNestedTouchScrollingLayout.peek(mNestedTouchScrollingLayout.getMeasuredHeight() - DisplayUtils.dpToPixel(BottomSheetActivity.this,400));
			}
		} else if (velocityY < -mVelocityYBound && velocityY < 0) {
			if (Math.abs(deltaY) < helfHeight) {
				mNestedTouchScrollingLayout.expand();
			} else {
				mNestedTouchScrollingLayout.peek(mNestedTouchScrollingLayout.getMeasuredHeight() - DisplayUtils.dpToPixel(BottomSheetActivity.this,400));
			}
		} else {
			if (Math.abs(deltaY) > hideLimit) {
				mNestedTouchScrollingLayout.hiden();
			} else if (Math.abs(deltaY) > helfLimit) {
				mNestedTouchScrollingLayout.peek(mNestedTouchScrollingLayout.getMeasuredHeight() - DisplayUtils.dpToPixel(BottomSheetActivity.this, 400));
			} else {
				mNestedTouchScrollingLayout.expand();
			}
		}
	}

	@Override
	public void onFingerUp(float velocityY) {

	}

	@Override
	public void onNestChildHorizationScroll(MotionEvent event, float deltaX, float deltaY) {

	}
});

Next

  • hold all touch event, and dispath touch event to child view.
  • fix ACTION_UP dispatch child click event.
  • support bottomsheet.
  • support CoordinatorLayout (AppbarLayout).
  • add damping draging.
  • add blur cover.

Usage

方式 1:

repositories {
    // ...
    maven { url "https://jitpack.io" }
}

dependencies {
    implementation 'com.github.JarvisGG:NestedTouchScrollingLayout:v1.2.0'
}

方式 2:

repositories {
    // ...
    jcenter()
}
dependencies {
    implementation 'com.jarvis.library.NestedTouchScrollingLayout:library:1.2.0'
}

Tip

star star star !!!!:blush:

LICENSE

This library is under the MIT license. check the LICENSE file for more detail.

Copyright (c) 2018 Jarvis

nestedtouchscrollinglayout's People

Contributors

jarvisgg avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.