facebook / litho

A declarative framework for building efficient UIs on Android.
https://fblitho.com
Apache License 2.0
7.7k stars 764 forks source link

Is there anything like gridViewPager or snapHelper in origin android sdk? #141

Closed barontxu closed 7 years ago

barontxu commented 7 years ago

Link to Code

https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html https://developer.android.com/reference/android/support/wearable/view/GridViewPager.html https://developer.android.com/reference/android/support/v7/widget/SnapHelper.html

barontxu commented 7 years ago

Or is there anything that can listen to fling or scroll in recycleView?

muraziz commented 7 years ago

Hi @barontxu, currently we don't support snapping in RecyclerSpec, but you can listen scroll events by providing onScrollListener prop like this (which will cover fling as well):

Recycler.create(c)
              ....
              .onScrollListener(new RecyclerView.OnScrollListener() {
                                ....
                          })
              ....
barontxu commented 7 years ago

@muraziz thanks, im using RecyclerEventsController, but seems OnScrollListener is better. By the way, is there a better tutorial or docs for litho?Im tired struggling in ocean of http://fblitho.com/javadoc/.

muraziz commented 7 years ago

@barontxu you can use http://fblitho.com/docs/getting-started.html for high-level overview, http://fblitho.com/docs/recycler-component for Recycler component and http://fblitho.com/docs/tutorial for barebones tutorial.

barontxu commented 7 years ago

@muraziz I've read them all.But when I facing problem like how can I get a image view, or how animation runs in this framework, or where can I get full functions of recycler etc, I have no idea which doc to turn to except reading http://fblitho.com/javadoc/. line by line.Maybe I missed something like important docs or sample, but i feel really tired develop a custom app using litho.Not like develop a website using bootstrap or sth, the docs are full of details, all I need is reading, or develop android app, there are a lot demos I can learn from.Litho's doc and sample just cover a small piece of the whole functions of the project.

barontxu commented 7 years ago

@muraziz and in http://fblitho.com/docs/inc-mount there'are lot of meaningless href, like in http://fblitho.com/docs/inc-mount, incremental mount leads to the homepage which i can't understand.

muraziz commented 7 years ago

Hey @barontxu, for creating image component you don't need a View, but you can use Image component as in example in http://fblitho.com/docs/best-practices. Currently we are working on animation support but it is not ready for use yet. Sorry for your experience, we just open-sourced the framework a week ago and there are lots of things that should be done to make documentation more extensive. The sample app's code cover usage of Recycler, Image, Text components and Column/Row containers which makes most of the building block of Litho components.

barontxu commented 7 years ago

@muraziz Thanks! And I didn't realize it's only been 7days since opened. Hope more people will use it and soon there's better docs.

barontxu commented 7 years ago

By the way @muraziz , in http://fblitho.com/docs/best-practices, image setting code: Image.create(c) .src(image) doesn't work, seems src not a builder.Maybe we should use drawable instead.

IanChilds commented 7 years ago

Hey, @barontxu, good spot. This is my fault as I changed the API without updating the docs. Sorry about that!

barontxu commented 7 years ago

hello @IanChilds , nice to see you (a guy who seems like developing the widget part or sth like that) ! Could you plz give us some more valuable samples for example, your testcase for the widgets?It's a real struggle diving straightly into your source code and guessing by variable name which sometimes a hard-to-complete job.

barontxu commented 7 years ago

@muraziz @IanChilds man is there any method I can turn Fling off in RecyclerView(I mean your component Recyler)?

muraziz commented 7 years ago

@barontxu Do you mean turning off flinging completely and scroll items only by dragging by touch? That would look quite unnatural. We don't support that. I'm not sure even RecyclerView supports that easily.

barontxu commented 7 years ago

@muraziz I mean customize my own FlingListener.

barontxu commented 7 years ago

RecyclerView supports that and all you have to do is to override fling by a empty function.

muraziz commented 7 years ago

You can use onScrollListener prop of Recycler component where you pass RecyclerView.OnScrollListener. That will cover both touch dragging and fling, like this:

   Recycler.create(c)
        ...
        .onScrollListener(new RecyclerView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == SCROLL_STATE_SETTLING) {
              // was flinging
            }
            if (newState == SCROLL_STATE_DRAGGING) {
              // was touch dragging
            }
          }

          @Override
          public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
          }
        })
       ...
       .build();
barontxu commented 7 years ago

@muraziz Thanks and I know how to use onScrollListener, BUT what if I want my app can and only can swipe one page each time? That's why I ask for a flingListener.

barontxu commented 7 years ago

And I found a way to hack it. I can inherit a Recycler and override onBind() where I can get a recyclerViewWrapper.What do you think about it? Could it work? Should I do it this way? Or is there any safety issues?

barontxu commented 7 years ago

@IanChilds @muraziz I've hacked my way in to implement a page listener, so if you don't think adding flingListener or snap is a good idea, fine. But I'm facing another problem that how can I customize a expandView and grab all the touch event until unfold.It's kind of tough writing this piece of code without a tutorial or document and just depend on the api name and guessing.

barontxu commented 7 years ago

Or it's there someway to replace a component with another dynamically?

passy commented 7 years ago

We now have official support for SnapHelper: https://www.facebook.com/groups/litho.android/permalink/111049929590158/ :)

cc @pasqualeanatriello