npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-swipeable-modal

v2.0.1

Published

Display modals which can be swiped in any direction

Downloads

42

Readme

React Native Swipeable Modal

react-native-swipeable-modal is a JavaScript library for react-native allowing you to display modals which can be swiped away in any direction

It uses the great react-native-gesture-handler to handle the pan events. This module needs to be installed within your application for react-native-swipeable-modal to work. For details please check React Native Gesture Handler.

Installation

React Native Swipeable Modal is available as react-native-swipeable-modal package on npm

With npm

$ npm install react-native-swipeable-modal --save

If using yarn

$ yarn add react-native-swipeable-modal

Examples

react-native-swipeable-modal exports a SwipeableModal component which displays its children in a fullscreen mode and can then be swiped away. You can use SwipeableModal in any direction:

Use as a simple modal

import React, {Component} from 'react';
import {Text, View, Button} from 'react-native';
import { SwipeableModal } from 'react-native-swipeable-modal';

class Container extends Component {
  state = {
    showModal: false,
  };

  closeModal = () => this.setState({ showModal: false });

  render() {
    return (
      <View style={{ flex: 1 }}>
        <View style={{
          flex: 1,
          alignItems: 'center',
          justifyContent: 'center',
          backgroundColor: '#FFFFFF'
        }}>
          <Button title="Show Modal" onPress={() => this.setState({ showModal: true })} />
        </View>
        {this.state.showModal && <SwipeableModal
          closeModal={this.closeModal}
          style={{
            backgroundColor: '#888888',
            justifyContent: 'center',
            alignItems: 'center',
          }}
        >
          <Button title="Close" raised onPress={this.closeModal} />
        </SwipeableModal>}
      </View>
    );
  }
}

Or with React Native Navigation v2 showModal

registerScreen.js

import { Navigation } from 'react-native-navigation';
import { gestureHandlerRootHOC } from 'react-native-gesture-handler';
import { ContainerScreen } from './ContainerScreen';
import { ModalScreen } from './ModalScreen';

Navigation.registerComponent(`navigation.Container`, () => ContainerScreen);
Navigation.registerComponent(`navigation.Modal`, () => gestureHandlerRootHOC(ModalScreen));

ContainerScreen.js

import React, {Component} from 'react';
import {Text, View, Button} from 'react-native';
import { Navigation } from 'react-native-navigation';

class ContainerScreen extends Component {
  showModal = () => {
    Navigation.showModal({
    component: {
        name: 'navigation.Modal',
        options: {
          modalPresentationStyle: Platform.OS === 'ios' ? 'overFullScreen' : 'overCurrentContext' // 'overfullScreen' on IOS allows us to see the back content while swiping the modal
        }
      }
    });
  };

  render() {
    return (
        <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
          <Button title="Show Modal" onPress={this.showModal} />
        </View>
    );
  }
}

ModalScreen.js

import React, {Component} from 'react';
import { Text, Button } from 'react-native';
import { Navigation } from 'react-native-navigation';
import { SwipeableModal } from 'react-native-swipeable-modal';

export class ModalScreen extends Component {
  closeModal = () => {
    Navigation.dismissModal(this.props.componentId)
      .catch(() => 1));
  };

  render() {
    return (
      <SwipeableModal
        closeModal={this.closeModal}
        style={{
          backgroundColor: '#999999',
          justifyContent: 'center',
          alignItems: 'center'
        }}
      >
        <Button title="Close" onPress={this.closeModal} />
      </SwipeableModal>
    );
  }
}

API

| Parameter | Type | Required | Default | Description | |----------------|----------|----------|----------|------------------------------------------------------------------------------------------------------------| | direction | string | ✘ | "bottom" | One of "bottom", "top", "left", "right"| | closeModal | Function | ✓ | - | The function to call when the modal has been swiped away beyond it's limit| | style | Object | ✘ | - | A style to overload the default style of the modal container. Note that you cannot overload the translate properties| | panClose | number | ✘ | 0.6 | A number between 0 and 1 used to select the breakpoint at which closeModal will be called| | minOffset | number | ✘ | 20 | See react-native-gesture-handler minOffset| | maxOffset | number | ✘ | 80 | See react-native-gesture-handler maxOffset|