Git Product home page Git Product logo

horizontal_blocked_scroll_physics's Introduction

Horizontal Blocked ScrollPhysics

Build Status License: MIT Pub

A ScrollPhysics class that blocks movement in the horizontal axis.

How to use it

The API of this ScrollPhysics is fairly straighforward.

We have two different classes:

  • LeftBlockedScrollPhysics: will block left movements.
  • RightBlockedScrollPhysics: will block right movements.

Blocking movement

LeftBlockedScrollPhysics();

This will allow the content to be scrolled to the right and will block any scroll to the left.

There's one exception, though. You can see here that the user is swiping to the left (which is blocked) but the screen will be able to move to the left if the movement is not completed. Note that the text will go back to the center.

swiping_left_recovery

Alternatively, if you want to block movement to the right and allow scrolling to the left:

RightBlockedScrollPhysics();

Why are we exposing two classes

You may have notice that we're exposing two classes instead of only one that uses properties to change the physics behavior. That's because of an optimization in the Scrollable class that doesn't allow to use the same type, even if it's a new instance, in order to change the Scrollable physics behavior.

The physics can be changed dynamically, but new physics will only take effect if the class of the provided object changes. Merely constructing a new instance with a different configuration is insufficient to cause the physics to be reapplied. (This is because the final object used is generated dynamically, which can be relatively expensive, and it would be inefficient to speculatively create this object each frame to see if the physics should be updated.)

That's why Flutter has specific ScrollPhysics like NeverScrollableScrollPhysics and AlwaysScrollableScrollPhysics.

horizontal_blocked_scroll_physics's People

Contributors

dees91 avatar robertohuertasm avatar

Watchers

 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.