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-safe-popover

v1.1.0

Published

A faithful JS-only imitation of UIKit's UIPopoverPresentationController, which respects the safe area, to React Native.

Downloads

4

Readme

react-native-safe-popover

A faithful JS-only imitation of UIKit's UIPopoverPresentationController, which respects the safe area, to React Native.

Installation

npm install react-native-safe-popover
# or
yarn add react-native-safe-popover

Appearance

Usage

  • As this is an imitation of UIPopoverPresentationController, the APIs are generally modelled on those of it.
  • SafePopover is nested within a full-screen modal, and so will have access to the entire screen area regardless of where you place it into the view hierarchy.
  • When SafePopover appears, it appears over a backdrop, which by default is rgba(0,0,0,0.25) (as configured by the backdropColor prop), but you could make it totally transparent if preferred.
  • It supports the props exposed in src/Popover.tsx by the interface PopoverProps; read those for full details on how you can configure SafePopover.
  • You can specify the preferred size for the popover content via the preferredWidth and preferredHeight props. You can think of these as equivalent to maxWidth and maxHeight in CSS.
  • Given a source rectangle to "pop" out of, it calculates the optimal position to place the popover content, and thus also the orientation for the arrow.
  • Through the permittedArrowDirections prop, you can specify your order of preference for the orientation of the arrow, and thus the placement of the popover content. You can force the content to always be placed above the rectangle by specifying permittedArrowDirections={[PopoverArrowDirection.down]}.
  • If no position satisfies the constraints, it fills all available space and omits the arrow entirely (I think - I haven't bothered testing it). I think this could only realistically occur by setting silly arrow sizes.
  • Does it work in both portrait and landscape orientations? Yes. Note that the width and height of the popover content do always mean width and height – they don't swap between orientations. So if your popover content is tall and thin in portrait mode, it'll be tall and thin on landscape mode too – not short and wide.
  • Does it handle rotation? Sometimes, sometimes not. At least on iOS, it partially depends on whether you're using a simulator or a real device. I found that this is a limitation of react-native-safe-area-context – it doesn't provide the edge insets soon enough for us to apply them.
  • How do you show it? Toggle its modalVisible property to true.
  • How do you dismiss it? Toggle its modalVisible property to false. SafePopover exposes an onBackdropPress prop in case you want to toggle its modalVisible property to false upon the user pressing the backdrop.
import SafePopover from "react-native-safe-popover";

export function Example(targetRect: { x: number, y: number, height: number, width: number }) {
    const [popupVisible, setPopupVisible] = React.useState(false);
    const { x, y, height, width } = targetRect;

    function onBackdropPress(): void {
        setPopupVisible(false);
    }

    return (
        <SafePopover
            animationType={"fade"}
            sourceRectHeight={height}
            sourceRectWidth={width}
            sourceRectX={x}
            sourceRectY={y}
            modalVisible={popupVisible}
            onBackdropPress={onBackdropPress}
            canOverlapSourceViewRect={false}
        >
            <Text style={{ padding: 8 }}>I'm the content of this popover!</Text>
        </SafePopover>
    );
}

License

MIT