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-media-modal

v0.1.6

Published

React Native Modal with Media Content

Downloads

15

Readme

Screenshot

React Native Media Modal is a component that facilitates the creation of a pop-up with media content generally used for communications or in-app marketing.

Installation

npm i react-native-media-modal --save

or

yarn add react-native-media-modal

Usage

import MediaModal from "react-native-media-modal";
<MediaModal ref={ref => { this.MyModal = ref }} />

For the methods works, you should create the reference

Methods

| Method Name | Description | | ----------- | ------------------ | | open | Open Medial Modal | | close | Close Medial Modal |

Examples

// Open Modal
function ExampleModalOpen = () => { this.MyModal.open()}

// Close Modal
function ExampleModalClose = () => { this.MyModal.close()}

Props

| Prop | Type | Description | Default | | ---------------- | -------- | -------------------------------------------------------- | -------------------------- | | title | string | Media Modal Content Title | "" | | message | string | Media Modal message | "" | | textPositionTop | boolean | Use title and message above image | false | | showMedia | boolean | Display Media Block | true | | mediaImage | boolean | Load Image on Media Block or Webview | true | | mediaURL | string | Url from Image or Video Embebed if you use Webview | true | | showCancel | boolean | Show a Cancel button | true | | showConfirm | boolean | Show a Confirm button | true | | textCancel | string | Text display on Cancel button | "" | | textConfirm | string | Text display on Confirm button | "" | | backdropClose | boolean | Close Media Modal when press on mask | false | | useNativeDriver | boolean | Allowing native code to perform the animation | false | | customStyles | object | Custom style to AlertPro | {} | | onCancel | function | Event on Cancel button | null | | onConfirm | function | Event on Confirm button | null | | onClose | function | Callback function when modal has closed | null | | customComponent | function | Inject custom component inside of modal | null |

Available Custom Style

customStyles: {
  BackgroundMask: {...}, // Backdrop mask 
  container: {...}, // Modal container 
  title: {...}, // Content title
  message: {...}, //Message text
  media: {...}, // Media 
  closeButton: {...}, // Close button
  closeButtonIcon: {...}, // Close button Icon
  buttonCancel: {...}, // Cancel Button
  textButtonCancel: {...}, // Cancel Button Text
  buttonConfirm: {...}, // Confirm button
  textButtonConfirm: {...} // Confirm button's Text
}

Example with modal customization

import React from 'react';
import { StyleSheet, View, Button } from 'react-native';
import MediaModal from 'react-native-media-modal';

const modalCustomStyles = {
  BackgroundMask: { backgroundColor: 'rgba(255,101,80, 0.4)' },
  container: { backgroundColor: '#e3e3e3' },
  title: { color: 'orange' },
  media: { width: 300 },
  message: { color: 'green' },
  closeButton: { backgroundColor: '#439431' },
  closeButtonIcon: { color: '#000' },
  buttonCancel: { backgroundColor: '#457d34' },
  buttonConfirm: { backgroundColor: '#542862' },
  textButtonCancel: { color: 'purple' },
  textButtonConfirm: { color: 'pink' },
  customComponent: { backgroundColor: '#dadada' }
}

const CustomComponent = <Text>Hello World!</Text>

export default class App extends React.Component {
  constructor(props) {
    super(props);
  }

  // ACTION ON CLOSE MODAL, CANCEL AND CONFIRM BUTTON TOUCH
  onClose = () => {
    console.log('Modal just closed');
  }

  onCancel = () => {
    console.log('User cancel')
    this.MyModal.close()
  }

  onConfirm = () => {
    console.log('User confirm')
  }

  render() {
    return (
      <View style={{flex: 1,    backgroundColor: '#fff',    alignItems: 'center',    justifyContent: 'center'}}>
        <Button title="Open Modal" color="#841584" accessibilityLabel="Learn more about this purple button" onPress={() => this.MyModal.open()} />
        <MediaModal
          ref={ref => { this.MyModal = ref }}
          title={'Welcome to My App'}
          message={'In this App, we will demonstrate the use of React Native Media Modal'}
          mediaURL={'https://www.url.com/myimage.png'}
          showCancel={true}
          showConfirm={true}
          onClose={this.onClose}
          onCancel={this.onCancel}
          onConfirm={this.onConfirm}
          backdropClose={false}
          customComponent={CustomComponent}
          customStyles={modalCustomStyles}
        />
      </View>
    );
  }
}

Example using functional component

import React, { useRef } from 'react'
import { Text, View, Button } from 'react-native'

import MediaModal from 'react-native-media-modal';

const modalCustomStyles = {
    BackgroundMask: { backgroundColor: 'rgba(255,101,80, 0.4)' },
    container: { backgroundColor: '#e3e3e3' },
    title: { color: 'orange' },
    media: { width: 300 },
    message: { color: 'green' },
}

const MediaModalExample = () => {

    const MediaModalRef = useRef();

    return (
        <View>
            <Text>Media Modal Example - Functional Component</Text>
            <Button title="Open Modal" color="#841584" onPress={MediaModalRef.current.open()} />
            <MediaModal
                ref={MediaModalRef}
                title={'Media Modal Functional Components'}
                message={'This is a example using functional components with Media Modal'}
                mediaURL={'https://www.url.com/myimage.png'}
                showCancel={true}
                showConfirm={true}
                backdropClose={false}
                customStyles={modalCustomStyles}
            />
        </View>
    )
}

export default MediaModalExample

Dependencies

This project use the dependency React Native Webview

Credits

Inspired on React Native Alert Pro from NY Samnang

Author

By Alan Ribeiro

If you think the project is useful, please contribute with a star!