evrencoskun / TableView

TableView is a powerful Android library for displaying complex data structures and rendering tabular data composed of rows, columns and cells.
MIT License
3.14k stars 456 forks source link

Can't scrolling up when inside SwipeRefreshLayout #111

Open ioterateam opened 6 years ago

ioterateam commented 6 years ago

It's doing refresh instead of scrolling up

If TableView inside of SwipeRefreshLayout in the xml, it's work fine if i'm scrolling down, but when i'm trying to scroll up the table, it's doing refresh instead of scrolling up, can you fix that?

My current .xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout 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">

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <EditText
            android:id="@+id/test"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <com.evrencoskun.tableview.TableView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/test" />

    </RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>

Can you fix this? Or it's just my fault?

sonique6784 commented 6 years ago

Hi @ioterateam, you need to disable swipeRefreshLayout until 1first row is fully visible (so SwipeLayout do not get the events).

  1. Extend TableView (MyTableView)
  2. add a TouchHandler in MyTableView TouchHandler mTouchHandler; + add setter
  3. Override dispatchTouchEvent(MotionEvent ev)
  4. call mTouchHandler.onTouchEvent(ev)
  5. in your fragment/activity set your TouchHandler on MyTableView: setTouchHandler(this);
  6. implement the touch handler: onTouchEvent(MotionEvent ev) { mSwipeRefreshLayout.setEnabled(getRowHeaderLayoutManager().findFirstCompletelyVisibleItemPosition() == 0) }

you might want to check if the event is DOWN or MOVE, depending what you achieve.

thangnguyendt commented 5 years ago

I tried to use the @sonique6784 answer. It doesn't work that well. It's always stuck at the first touch -> the row move from 4,5 to 0. and next touch the swipe refreshlayout is enable (need at least 2 touches)

So please @evrencoskun add the pull to refresh layout feature for the table

porco1024 commented 3 years ago

you can try this

//解决滑动冲突 tableView.getCellRecyclerView().addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); refreshLayout.setEnabled(tableView.getCellLayoutManager().findFirstVisibleItemPosition() == 0); } });

HananoshikaYomaru commented 3 years ago

@83849 's answer is genius, completely works for me. A better way is to change findFirstVisibleItemPosition() to findFirstCompletelyVisibleItemPosition() to make sure the first item is completely visible, then you set the swipe refresh layout to be enabled.