Coder Social home page Coder Social logo

sanengineer / react-navigation-scrollable-modal Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gorhom/react-navigation-scrollable-modal

0.0 0.0 0.0 1.31 MB

This is a POC to replicate the native interaction behavior of iOS modal presentation with React Navigation.

JavaScript 1.21% TypeScript 98.79%

react-navigation-scrollable-modal's Introduction

React Navigation Scrollable Modal

This is a POC to replicate the native interaction behavior of iOS modal presentation with React Navigation.

React Navigation Scrollable Modal


Usage

In order to get this functionality working in your project, you have to:

  • Copy patches/@react-navigation+stack+6.0.7.patch into your project root folder.
  • Copy src/useCardModalGestureInteraction.ts into any place in your project.
  • add "postinstall": "npx patch-package" into your project package.json in scripts node.
  • run yarn
export const ScrollableModalScreen = () => {
  const scrollableRef = useAnimatedRef<FlatList>();

  const { scrollableGestureRef, handleScrolling } =
    useCardModalGestureInteraction(scrollableRef);
  return (
    <NativeViewGestureHandler ref={scrollableGestureRef}>
      <AnimatedFlatList
        ref={scrollableRef}
        scrollEventThrottle={16}
        onScroll={handleScrolling}
        {...}
      />
    </NativeViewGestureHandler>
  );
};

How it works

React Navigation Stack implements a PanGestureHandler in the Card component, which should allow us to manipulate the gesture behavior as we want.

To achieve the seamless scrolling / pan gesture interaction, We have to wrap the scrollable component with NativeGestureHandler from react-native-gesture-handler and pass its reference to the Card's PanGestureHandler via the prop simultaneousHandlers.

Then we need to lock the scrollable component, whenever the user is reach to the top and start dragging the Card.

I have already prepare a custom hook useCardModalGestureInteraction that will handle all the interaction with the Card, all you have to do is to pass the scrollable ref, and attached the return variables to NativeViewGestureHandler and your scrollable

This solution was inspired by the Bottom Sheet library, thanks to @haibert for highlighting this issue.


Mo Gorhom

react-navigation-scrollable-modal's People

Contributors

gorhom avatar zhigang1992 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.