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-magic-overlay

v0.1.2

Published

test

Downloads

76

Readme

React Native Magic Overlay Cover

An overlay library that can be called imperatively from anywhere and shows on top of other modals!

React Native Magic Overlay :sparkles:

This library enables displaying customizeable overlays that always appear on top of other modals, it can be called imperatively on Android and IOS device without having to worry about the other modals that currently exist in the component tree.

This library relies on the FullWindowOverlay component of software-mansion/react-native-screens on IOS in order to render the view on top of other views, and on React Native's Modal component on Android.

📸 Examples

| IOS | Android | | ----------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | | | |

🛠 Installation

yarn add react-native-magic-overlay

⚙️ Usage

First, insert a MagicOverlayPortal at the top level of the application udner GestureHandlerRootView if it exists.

You can add a default style for the backdrop view in here if you don't want to use the default one or don't want to specify the backdrop style everytime the overlay is displayed.

import {GestureHandlerRootView} from 'react-native-gesture-handler';
import {MagicOverlayPortal} from 'react-native-magic-overlay';

export default function App() {
  return (
    <OtherProviders>
        <GestureHandlerRootView style={{flex: 1}}>
            <MagicOverlayPortal defaultBackdropStyle={}/>  // <-- On the top of the app component hierarchy
            <AppComponents /> // The rest of the app goes here
        </GestureHandlerRootView>
    </OtherProviders>
  );
}

Then, you are free to use the magicOverlay as shown from anywhere you want.

import React from 'react';
import { View, Text, TouchableOpacity } from 'react-native';
import { magicOverlay } from 'react-native-magic-overlay';

const CustomAlert = (someProps) => (
  <View style={{height:"50%", width:"80%"}}>
    <Text>Custom Alert</Text>
    <TouchableOpacity 
    onPress={() => {
        magicOverlay.hide({result: true})
    }}> // This will hide the alert, resolve the promise with the passed object
      <Text>OK</Text>
    </TouchableOpacity>
    <TouchableOpacity 
    onPress={() => {
        magicOverlay.hide({result: false})
    }}> // This will hide the alert, resolve the promise with the passed object
      <Text>Cancel</Text>
    </TouchableOpacity>
  </View>
);

const showAlert = async () => {
  // We can call it with or without props, depending on the requirements.
  const result = await magicOverlay.show(CustomAlert);

  //OR (with props)
  const result = await magicOverlay.show(<CustomAlert {...someProps}/>);

  console.log(result) 
  // will show {result: true}, or {result: false} based on the pressed button
};

export const Screen = () => {
  return (
    <View>
      <TouchableOpacity onPress={showAlert}>
        <Text>Show alert</Text>
      </TouchableOpacity>
    </View>
  );
};

Alternatively, if we don't care about waiting the resolved value of the promise we can just trigger some action instead.

import React from 'react';
import {View, Text, TouchableOpacity} from 'react-native';
import {magicOverlay} from 'react-native-magic-overlay';

const CustomAlert = (props) => (
  <View>
    <TouchableOpacity 
      onPress={() => {
        magicOverlay.hide();
        props.onConfirm(true)
      }}> 
      <Text>Confirm</Text>
    </TouchableOpacity>
  </View>
);

export const Screen = () => {
  const [confirmed, setConfirmed] = useState(false);

  const showAlert = useCallback(
    () => {
      magicOverlay.show(
        () => <CustomAlert onConfirm={(value)=>{setConfirmed(value)}}/>
      )
    }
  ,[])

  return (
    <View>
      <TouchableOpacity 
        onPress={showAlert}>
        <Text>Show alert</Text>
      </TouchableOpacity>
    </View>
  );
};

magicOverlay.show( ) can take a second optional argument to pass extra props to the overlay such as backdropStyle

Example:

magicOverlay.show(
    () => <SomeComponent {...someProps}>,
    {backdropStyle: styles.overlayBackdrop}
)

😬 Notes

State management

The overlay view is not reactive, as in the props that are passed to the component are a snapshot of when the overlay is displayed, so it's advised to use the overlay in the same way we use Alert.alert() and not rely on reactive values to control the texts or views inside it.

👨‍🏫 Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

⚖️ License

MIT