GithubHelp home page GithubHelp logo

Possible Bug in CollectionLayout about famous-flex HOT 5 CLOSED

 avatar commented on July 18, 2024
Possible Bug in CollectionLayout

from famous-flex.

Comments (5)

 avatar commented on July 18, 2024

Here is my code:

function _createCollectionView() {
        this.scrollView = new FlexScrollView({
                layout: CollectionLayout,
                flow: true,
                flowOptions: {
                    spring: {
                        dampingRatio: 0.8,
                        period: 1000
                    }
                },
                autoPipeEvents: true,
                debug: false,
                mouseMove: true,
                useContainer: true,
                layoutOptions: {
                    itemSize: [250, 150],    // item has width and height 
                    margins: [10, 5, 10, 5], // outer margins
                    spacing: [10, 10]        // spacing between items
                },
                dataSource: _getDogSurfaces.call(this)
            });
        return this.scrollView;
    }

If I resize the the browser and reload the page only the visible surfaces seem to get the events attached.
Just for illustration a screenshot screenshot

There are 24 surfaces in the CollectionView and in the above screenshot only the 16 visible surfaces have the click events attached for edit and delete in the upper right corner of a surface.

Any ideas what I'm missing?

from famous-flex.

IjzerenHein avatar IjzerenHein commented on July 18, 2024

Alright thanks for that info.

I think the problem is related to the 'autoPipeEvents' option. You could try not using that, and instead just piping the events from the views to the Scrollview yourself. I'll hopefully have some time this weekend to have a closer look at it.

And, nice screenshot btw :)

cheers, Hein

from famous-flex.

 avatar commented on July 18, 2024

Thanks Hein, wouldn't be possible without your excellent library. It's just too sad that Famous Industries has take famo.us into something private. My hope is that SamsaraJS can be used to replace famous, I don't see any other library that could be a candidate.

Coming back to our problem: Unfortunately, piping each surface directly to the scrollView did result in the same issue. There must be something else causing this behavior.

from famous-flex.

 avatar commented on July 18, 2024

It crossed my mind that the issue could be caused by the template that populates the content for each surface, because I attach the event handlers via jQuery. So I have tried to add the click event on a mouseover event, because all surface are rendered at this time.

function _addClickEventListeners() {
        app.wait(500).then(function() {
            // add click events to edit and delete buttons to all dog panels
            _.each(this.myDogs, function(d, i) {
                $('#edit' + i).mouseenter(function() {
                    console.log('#edit' + i + ' loaded' )
                    $('#edit' + i).on('click', _.debounce(function() {
                        require(['modules/updateDogDialog'], function(modal) {
                            var dialog = new modal(d);
                            this.modalController.show(new ModalView(dialog));
                        }.bind(this));
                    }.bind(this), 300));
                }.bind(this))

                $('#delete' + i).on('click', _.debounce(function() {
                    var deleteDog = confirm('Do you really want to remove this dog?');
                    if ( deleteDog ) {
                        _removeDog.call(this, i);
                    }
                }.bind(this), 300));
                if ( i === this.myDogs.length - 1 ) {
                    this.scrollView.ensureVisible(i);
                }
            }.bind(this));
        }.bind(this));
    }

But still, only the surface visible in browsers viewport get the event handlers attached. When I scroll down further they don't get attached.

from famous-flex.

IjzerenHein avatar IjzerenHein commented on July 18, 2024

Right, I see... Your jQuery code attaches its event handlers based on what is in the DOM at that time. ScrollView however, only adds the surfaces to the DOM which are visible and needed for scrolling. When scrolling, surfaces are dynamically added/removed to and from the DOM. That's why the surfaces which are not in the DOM at the time when _addClickEventListeners is called, don't have event handlers attached.
Personally I would not use this approach to attach event handlers, but instead use the famous event mechanisms instead.

Alternatively you could use the option layoutAll which causes all surfaces to be added to the DOM always, potentially at the cost of (scrolling) performance.

from famous-flex.

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.