Giter Site home page Giter Site logo

Comments (12)

noties avatar noties commented on May 29, 2024

Hi!
If I got you right you mean something like that:
out

If it looks like your issue, than you somehow misused CanScrollVerticallyDelegate.
In this gif It always returns false, which is equal to setting ScrollableLayout.setCanScrollVerticallyDeletegate to NULL or never setting it at all

from scrollable.

ayz4sci avatar ayz4sci commented on May 29, 2024

Thanks so much.

Please how do I reduce the slidedown speed of the header? I want it to slide down with the same speed as the list fling speed.

from scrollable.

noties avatar noties commented on May 29, 2024

Set scroll friction via code scrollableLayout.setFriction(float friction) or via xml attribute app:scrollable_friction="0.075".
Try playing with values in the sample application, it has seek bar with current scroll friction indication. For my own taste something between 0.05 & 0.075 feels smooth

from scrollable.

ayz4sci avatar ayz4sci commented on May 29, 2024

Thanks.

from scrollable.

squeeish avatar squeeish commented on May 29, 2024

@noties somehow recyclerView is always null in canScrollVertically method in my Fragment. Do you have any idea why this might be the case?

from scrollable.

noties avatar noties commented on May 29, 2024

@squeeish Well, it might be two things: first check if you have RecyclerView in your layout file, second check the id of the RecyclerView (most likely you miss typed it)

from scrollable.

squeeish avatar squeeish commented on May 29, 2024

@noties it's definitely in my layout file and the id is correct as I'm setting layout managers and adapters to it. I've 4 tabs in a ViewPager with Android Design Support Library's TabLayout as the tab headers. The header is a RelativeLayout.

When I debug, I can see that the CanScrollVertically chain is there (delegate, adapter, fragment) but in all 4 fragments' CanScrollVertically method, the recyclerview variable is always null.

from scrollable.

squeeish avatar squeeish commented on May 29, 2024

Ok I've solved it. Turns out it was my FragmentPagerAdapter returning new instances of the fragments in getItem. 😄

from scrollable.

squeeish avatar squeeish commented on May 29, 2024

@noties Could you help me out?

  1. Go to developer options and check "Do not keep activities".
  2. Start the sample app and click "Inside Fragment".
  3. Scroll up and down. The header only shows when the top of the list is reached.
  4. Press the home button, then open the sample app again.
  5. Scroll up and down. CanScrollVerticallyDelegate seems to always return false this time.

Do you have any idea why this might be the case? This behaviour is not seen in MainActivity. If you are in debug mode, canScrollVertically method in RecyclerViewFragment thinks that mRecyclerView is null, which isn't supposed to be the case.

EDIT: Fixed. mRecyclerView has to be static. Same for mListView in ListViewFragment.

from scrollable.

noties avatar noties commented on May 29, 2024

Hi! Nice catch!

It happens because we pass to the ViewPagerAdapter newly created fragments, but the previous ones are still attached to the FragmentManager. Thus, our newly created fragments won't be added, won't o through onCreateView() and that's why they will always return false from canScrollVertically method. So, to work around this issue, we must do something like this:

private List<BaseFragment> fragments() {

    final FragmentManager manager = getChildFragmentManager();

    final BaseFragment list;
    {
        final Fragment fragment = manager.findFragmentByTag(ListViewFragment.TAG);
        if (fragment == null) {
            list = ListViewFragment.newInstance(0x80FF0000);
        } else {
            list = (ListViewFragment) fragment;
        }
    }

    final BaseFragment recycler;
    {
        final Fragment fragment = manager.findFragmentByTag(RecyclerViewFragment.TAG);
        if (fragment == null) {
            recycler = RecyclerViewFragment.newInstance(0x8000FF00);
        } else {
            recycler = (RecyclerViewFragment) fragment;
        }
    }

    return Arrays.asList(list, recycler);
}

And then:

final ViewPagerAdapter adapter = new ViewPagerAdapter(
        getChildFragmentManager(),
        getResources(),
        fragments()
);

This solution might work if you have not much fragments. Otherwise it's better to create some kind of helper.

from scrollable.

noties avatar noties commented on May 29, 2024

I will update sample with the next library release

from scrollable.

squeeish avatar squeeish commented on May 29, 2024

@noties Thanks! I knew it was something to do with ViewPagerAdapter but for the life of me I couldn't figure out why. Your explanation is great, thanks! Looking forward to the next library release.

from scrollable.

Related Issues (20)

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.