### Install react-native-popover-view with npm Source: https://github.com/steffeydev/react-native-popover-view/blob/master/README.md Use this command to install the library using npm. ```shell npm i react-native-popover-view ``` -------------------------------- ### Install react-native-popover-view with yarn Source: https://github.com/steffeydev/react-native-popover-view/blob/master/README.md Use this command to install the library using yarn. ```shell yarn add react-native-popover-view ``` -------------------------------- ### Basic Popover Usage in React Native Source: https://github.com/steffeydev/react-native-popover-view/blob/master/README.md This example demonstrates the simplest way to use the Popover component. It automatically shows when the child TouchableOpacity is pressed. Note that any existing onPress or ref props on the TouchableOpacity will be overwritten. ```jsx import React from 'react'; import Popover from 'react-native-popover-view'; function App() { return ( Press here to open popover! ))> This is the contents of the popover ); } ``` -------------------------------- ### Advanced Popover Usage in React Native Source: https://github.com/steffeydev/react-native-popover-view/blob/master/README.md This example shows advanced usage where you control the popover's anchor element and visibility. The popover anchors to the text inside the popover and is shown on a long press. The sourceRef is used to identify the anchor element, and showPopover is a callback to trigger the popover's display. ```jsx import React from 'react'; import Popover from 'react-native-popover-view'; function App() { return ( ( Press here to open popover! ))}> This is the contents of the popover ); } ``` -------------------------------- ### Use Popover with Safe Area Context Source: https://github.com/steffeydev/react-native-popover-view/blob/master/README.md Integrates the Popover component with react-native-safe-area-context to respect screen insets. Requires `react-native-safe-area-context` to be installed. ```jsx import { useSafeAreaInsets } from 'react-native-safe-area-context'; import Popover from 'react-native-popover-view'; function PopoverSafeWrapper(props) { const insets = useSafeAreaInsets(); return ( ); } ``` -------------------------------- ### Handle Popover Lifecycle Events Source: https://context7.com/steffeydev/react-native-popover-view/llms.txt Use `onOpenStart`, `onOpenComplete`, `onCloseStart`, `onCloseComplete`, and `onPositionChange` to hook into popover animation phases. Useful for synchronizing UI state or analytics. ```jsx import React, { useState } from 'react'; import { TouchableOpacity, Text, View } from 'react-native'; import Popover from 'react-native-popover-view'; export default function LifecyclePopover() { const [status, setStatus] = useState('closed'); return ( Status: {status} setStatus('opening…')} onOpenComplete={() => setStatus('open')} onCloseStart={() => setStatus('closing…')} onCloseComplete={() => setStatus('closed')} onPositionChange={() => console.log('Popover moved to new position')} from=( Tap to open ) > Watch the status label above. ); } ``` -------------------------------- ### Using Class Components with Popover Source: https://github.com/steffeydev/react-native-popover-view/blob/master/README.md Demonstrates how to use `react-native-popover-view` with class components by utilizing `createRef` to manage the popover's anchor element and state for visibility. ```jsx import React, { createRef } from 'react'; import Popover from 'react-native-popover-view'; class App extends React.Component { constructor(props) { super(props); this.touchable = createRef(); this.state = { showPopover: false } } render() { return ( <> this.setState({ showPopover: true })}> Press here to open popover! this.setState({ showPopover: false })}> This is the contents of the popover ); } } ``` -------------------------------- ### Using Rect and Size for Geometry Source: https://context7.com/steffeydev/react-native-popover-view/llms.txt Utilize `Rect` and `Size` classes for defining popover anchors and display areas. These classes include equality checking and can also accept plain JavaScript objects. ```tsx import { Rect, Size } from 'react-native-popover-view'; // Create a Rect representing a screen region const anchor = new Rect(50, 100, 200, 60); console.log(anchor.x, anchor.y, anchor.width, anchor.height); // 50 100 200 60 // Clone and compare const clone = Rect.clone(anchor); console.log(clone.equals(anchor)); // true // Size for arrowSize prop const arrowSize = new Size(20, 10); console.log(arrowSize.width, arrowSize.height); // 20 10 console.log(arrowSize.equals(new Size(20, 10))); // true // Pass plain object instead of new Rect() (also accepted by Popover) const plainRect = { x: 50, y: 100, width: 200, height: 60 }; // ``` -------------------------------- ### Enable Debugging for Popover Placement Source: https://context7.com/steffeydev/react-native-popover-view/llms.txt Set `debug={true}` to log detailed geometry calculations to the console, aiding in troubleshooting placement issues. Ensure necessary imports are included. ```jsx import React from 'react'; import { TouchableOpacity, Text, View } from 'react-native'; import Popover from 'react-native-popover-view'; export default function DebugPopover() { return ( {/* debug=true logs all internal geometry computations to the console */} Debug Mode ) > Check your console for geometry logs. ); } ``` -------------------------------- ### Show Popover as Tooltip Source: https://github.com/steffeydev/react-native-popover-view/blob/master/README.md Use `PopoverMode.TOOLTIP` to display a popover without dimming the background. Manual visibility control is required as `onRequestClose` will not be called. ```jsx import React, { useRef, useState } from 'react'; import Popover, { PopoverMode, PopoverPlacement } from 'react-native-popover-view'; function App() { const [showPopover, setShowPopover] = useState(false); return ( setShowPopover(true)}> Press here to open popover! ))> <> This is the contents of the popover setShowPopover(false)}> Dismiss ); } ``` -------------------------------- ### Show Popover from Element Reference Source: https://github.com/steffeydev/react-native-popover-view/blob/master/README.md Pass a `ref` to the `Popover`'s `from` prop to anchor it to a specific element, even if the popover and the element are in different parts of the component tree. ```jsx import React, { useRef, useState } from 'react'; import Popover from 'react-native-popover-view'; function App() { const touchable = useRef(); const [showPopover, setShowPopover] = useState(false); return ( <> setShowPopover(true)}> Press here to open popover! setShowPopover(false)}> This is the contents of the popover ); } ``` -------------------------------- ### Show Popover from Predetermined Position Source: https://github.com/steffeydev/react-native-popover-view/blob/master/README.md Anchor the popover to a specific screen location by providing a `Rect(x, y, width, height)` object to the `from` prop. A `Rect` with zero width and height anchors to a point. ```jsx import React, { useState } from 'react'; import Popover, { Rect } from 'react-native-popover-view'; function App() { const [showPopover, setShowPopover] = useState(false); return ( <> setShowPopover(true)}> Press here to open popover! setShowPopover(false)}> This is the contents of the popover ); } ``` -------------------------------- ### Popover View Props Source: https://github.com/steffeydev/react-native-popover-view/blob/master/README.md All props are optional and can be used to customize the popover's behavior and appearance. ```APIDOC ## Props All props are optional Prop | Type | Default | Description ----------------- | -------- | ----------- | ----------- from | multiple | null | Popover source. See [From](#from) section below. isVisible | bool | false | Show/Hide the popover. Required if `from` is *not* a Touchable or function that uses `showPopover` call (see examples). If supplied, takes precedence regardless of `from`. mode | string | 'rn-modal' | One of: 'rn-modal', 'js-modal', 'tooltip'. See [Mode](#mode) section below for details. placement | string OR string list | 'auto' | How to position the popover, one of 'top', 'bottom', 'left', 'right', 'floating', or 'auto'. When 'auto' is specified, it will try to determine the best placement so that the popover is fully visible within `displayArea`. If an array of options is passed in, it will pick the first option that can accommodate the content. offset | number | 0 | The amount to shift the popover away from the source. Does not apply if the popover is centered. popoverStyle | object | | The style of the popover itself. You can override the `borderRadius`, `backgroundColor`, or any other [`style` prop for a `View`](https://facebook.github.io/react-native/docs/view-style-props.html). popoverShift | object | | How much to shift the popover in each direction, as a multiplier. Object of shape `{ x: -1 to 1, y: -1 to 1 }`, where both `x` and `y` are optional. `-1` shifts the popover all the way to the left/top and `1` shifts it to the right/bottom. Currently only applies when placement is `floating`, but this will apply to all placements in a future version. backgroundStyle | object | | The style of the background view. Default is a black background with 0.5 opacity. arrowSize | object | `{ width: 16, height: 8 }` | The size of the arrow, as an object with `width` & `height` properties. The width of the arrow is the size of the arrow on the edge that touches the popover (base of isosceles triangle), while the height covers the distance from the popover to the source view, regardless of the placement of the popover. You can use `{ width: 0, height: 0 }` to hide the arrow completely. arrowShift | number | 0 | How much to shift the arrow to either side, as a multiplier. `-1` will shift it all the way to the left (or top) corner of the source view, while `1` will shift it all the way to the right (or bottom) corner. A value of `0.5` or `-0.8` will shift it partly to one side. onOpenStart | function | | Callback to be fired when the open animation starts (before animation) onOpenComplete | function | | Callback to be fired when the open animation ends (after animation) onRequestClose | function | | Callback to be fired when the user taps outside the popover (on the background) or taps the system back button on Android onCloseStart | function | | Callback to be fired when the popover starts closing (before animation) onCloseComplete | function | | Callback to be fired when the popover is finished closing (after animation) onPositionChange | function | | Callback to be fired when the popover position finishes moving position (after animation) animationConfig | object | | An object containing any configuration options that can be passed to Animated.timing (e.g. `{ duration: 600, easing: Easing.inOut(Easing.quad) }`). The configuration options you pass will override the defaults for all animations. displayArea | rect | | Area where the popover is allowed to be displayed. By default, this will be automatically calculated to be the size of the display, or the size of the parent component if mode is not 'rn-modal'. displayAreaInsets | object | | Insets to apply to the display area. The Popover will not be allowed to go beyond the display area minus the insets. statusBarTranslucent | bool | true | For 'rn-modal' mode on Android only. Determines whether the background should go under the status bar. Passed through to RN `Modal` component, see [their docs](https://reactnative.dev/docs/modal#statusbartranslucent-1) as well. debug | bool | false | Set this to `true` to turn on debug logging to the console. This is useful for figuring out why a Popover isn't showing. ``` -------------------------------- ### Show Popover and Close Programmatically Source: https://github.com/steffeydev/react-native-popover-view/blob/master/README.md Use a `ref` to access the `Popover` instance and call `requestClose()` to dismiss it programmatically. This is useful when the dismiss action is triggered from within the popover's content. ```jsx import React, { useRef } from 'react'; import Popover from 'react-native-popover-view'; function App() { const popoverRef = useRef(); return ( Press here to open popover! )> popoverRef.current.requestClose()}> Tap to close me ); } ``` -------------------------------- ### Customize Popover Appearance with Style Props Source: https://context7.com/steffeydev/react-native-popover-view/llms.txt Use `popoverStyle`, `backgroundStyle`, `arrowSize`, and `arrowShift` to customize the popover bubble, dimming background, and arrow. Includes custom animation configuration. ```jsx import React from 'react'; import { Easing, TouchableOpacity, Text, View } from 'react-native'; import Popover from 'react-native-popover-view'; export default function StyledPopover() { return ( Styled Popover ) > Custom styled content ); } ``` -------------------------------- ### Popover Component - Show from Touchable Element Source: https://context7.com/steffeydev/react-native-popover-view/llms.txt Use the `from` prop with a Touchable element for simple popover integration. The popover automatically shows when the element is pressed, eliminating the need for external visibility state management. ```jsx import React from 'react'; import { TouchableOpacity, Text, View } from 'react-native'; import Popover from 'react-native-popover-view'; export default function App() { return ( Open Popover ) > Hello from the popover! ); } ``` -------------------------------- ### Show Popover from a Rect or Point Source: https://context7.com/steffeydev/react-native-popover-view/llms.txt Anchor the popover to a specific on-screen position using a `Rect` object or a plain coordinate object. Useful for fixed UI elements or custom positioning. ```jsx import React, { useState } from 'react'; import { TouchableOpacity, Text, View } from 'react-native'; import Popover, { Rect } from 'react-native-popover-view'; export default function RectPopover() { const [visible, setVisible] = useState(false); return ( setVisible(true)} style={{ padding: 12, backgroundColor: '#267326', borderRadius: 8 }}> Show at fixed rect {/* Popover anchored to the rect (x=40, y=120, w=80, h=40) */} setVisible(false)} > Anchored to a fixed screen region. {/* Or anchor to a single point: */} {/* setVisible(false)}> */} ); } ``` -------------------------------- ### Show Popover from a Ref (Decoupled Trigger) Source: https://context7.com/steffeydev/react-native-popover-view/llms.txt Use this when the trigger element and the Popover component are in separate branches of the component tree. Pass a ref to the `from` prop. ```jsx import React, { useRef, useState } from 'react'; import { TouchableOpacity, Text, View } from 'react-native'; import Popover from 'react-native-popover-view'; export default function RefPopover() { const buttonRef = useRef(null); const [visible, setVisible] = useState(false); return ( {/* Trigger lives in a different part of the tree */} setVisible(true)} style={{ margin: 20, padding: 12, backgroundColor: '#5c2d91', borderRadius: 8 }} > Open (ref-based) setVisible(false)} > Anchored to the button above via ref. ); } ``` -------------------------------- ### Show Popover in a Specific Direction Source: https://github.com/steffeydev/react-native-popover-view/blob/master/README.md Force the popover to appear in a specific direction using the `placement` prop. This overrides the default behavior of automatically choosing the best fit. ```jsx import React from 'react'; import Popover, { PopoverPlacement } from 'react-native-popover-view'; function App() { return ( Press here to open popover! )> This is the contents of the popover ); } ``` -------------------------------- ### Control Popover Rendering Mode with PopoverMode Enum Source: https://context7.com/steffeydev/react-native-popover-view/llms.txt Use `PopoverMode` to switch between rendering modes: `RN_MODAL` (default, native modal), `JS_MODAL` (JS layer for nested popovers), and `TOOLTIP` (no dimmed background, no outside-tap dismiss). ```jsx import React, { useState } from 'react'; import { TouchableOpacity, Text, View } from 'react-native'; import Popover, { PopoverMode, PopoverPlacement } from 'react-native-popover-view'; export default function ModeExample() { const [showTooltip, setShowTooltip] = useState(false); return ( {/* TOOLTIP mode: background stays active, taps fall through */} setShowTooltip(true)} style={{ padding: 12, backgroundColor: '#006', borderRadius: 8 }}> Show Tooltip ) > Tooltip content setShowTooltip(false)} style={{ marginTop: 8, padding: 6, backgroundColor: '#900', borderRadius: 4 }}> Dismiss {/* JS_MODAL mode: use inside native modals or for nested popovers */} JS Modal Popover ) > Rendered in JS layer. ); } ``` -------------------------------- ### Popover Component - Advanced `from` Function Source: https://context7.com/steffeydev/react-native-popover-view/llms.txt Utilize the `from` prop as a function to independently control the anchor reference and the trigger callback. This is useful when the element that triggers the popover differs from the element the popover anchors to. ```jsx import React from 'react'; import { TouchableOpacity, Text, View } from 'react-native'; import Popover from 'react-native-popover-view'; export default function AdvancedFrom() { return ( ( {/* Arrow points at this Text, but pops open on long-press */} Long-press me )} > Opened via long-press! ); } ``` -------------------------------- ### Control Popover Placement with PopoverPlacement Enum Source: https://context7.com/steffeydev/react-native-popover-view/llms.txt Use `PopoverPlacement` to force a popover into a specific direction or provide an ordered array of preferred placements. The library selects the first placement that fits. ```jsx import React from 'react'; import { TouchableOpacity, Text, View } from 'react-native'; import Popover, { PopoverPlacement } from 'react-native-popover-view'; export default function PlacementExample() { return ( {/* Always show above the trigger */} Force TOP ) > I'm above you. {/* Try RIGHT first, fall back to LEFT, then AUTO */} Right → Left → Auto ) > Best available side. {/* Float centered with no arrow */} Floating (centered) ) > I float in the center. ); } ``` -------------------------------- ### Imperative Popover Close Method Source: https://context7.com/steffeydev/react-native-popover-view/llms.txt Obtain a ref to the Popover component to call `requestClose()` programmatically from within the popover's content. This avoids the need for external state management to control closing. ```jsx import React, { useRef } from 'react'; import { TouchableOpacity, Text, View } from 'react-native'; import Popover from 'react-native-popover-view'; export default function ImperativeClose() { const popoverRef = useRef(null); return ( Open ) > Tap the button below to close. popoverRef.current?.requestClose()} style={{ padding: 8, backgroundColor: '#cc0000', borderRadius: 6 }} > Close Me ); } ``` -------------------------------- ### Avoid Safe Area and Keyboard with `displayAreaInsets` Source: https://context7.com/steffeydev/react-native-popover-view/llms.txt Restrict popover appearance to a specific area using `displayAreaInsets`. Commonly used with `react-native-safe-area-context` to avoid notches and system UI. ```jsx import React from 'react'; import { TouchableOpacity, Text, View } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import Popover from 'react-native-popover-view'; // Wrap Popover to always respect device safe areas function SafePopover(props) { const insets = useSafeAreaInsets(); return ; } export default function SafeAreaExample() { return ( Safe Area Popover ) > Will never overlap notches or system bars. ); } ``` -------------------------------- ### Show Popover with Manual Dismiss Control Source: https://github.com/steffeydev/react-native-popover-view/blob/master/README.md Control popover visibility using `isVisible` and `onRequestClose` props for manual dismissal. `onRequestClose` is called when the user taps outside the popover. ```jsx import React, { useState, useEffect } from 'react'; import Popover from 'react-native-popover-view'; function App() { const [showPopover, setShowPopover] = useState(false); useEffect(() => { setTimeout(() => setShowPopover(false), 2000); }, []); return ( setShowPopover(false)} from=( setShowPopover(true)}> Press here to open popover! )> This popover will be dismissed automatically after 2 seconds ); } ``` -------------------------------- ### Show Floating Popover Without Anchor Source: https://github.com/steffeydev/react-native-popover-view/blob/master/README.md Display a popover that is not anchored to any specific element by omitting the `from` prop. The popover will be centered on the screen. ```jsx import React, { useState } from 'react'; import Popover from 'react-native-popover-view'; function App() { const [showPopover, setShowPopover] = useState(false); return ( <> setShowPopover(true)}> Press here to open popover! setShowPopover(false)}> This popover will stay centered on the screen, even when the device is rotated! ); } ``` -------------------------------- ### Popover Component - Controlled Visibility Source: https://context7.com/steffeydev/react-native-popover-view/llms.txt Manage the popover's open/close lifecycle manually using the `isVisible` and `onRequestClose` props. This allows for programmatic control and integration with timers or other logic for automatic dismissal. ```jsx import React, { useState, useEffect } from 'react'; import { TouchableOpacity, Text, View } from 'react-native'; import Popover from 'react-native-popover-view'; export default function ControlledPopover() { const [visible, setVisible] = useState(false); // Auto-dismiss after 3 seconds useEffect(() => { if (visible) { const timer = setTimeout(() => setVisible(false), 3000); return () => clearTimeout(timer); } }, [visible]); return ( setVisible(false)} from=( setVisible(true)} style={{ padding: 12, backgroundColor: '#333', borderRadius: 8 }}> Show (auto-closes in 3s) ) > This will close automatically or when you tap outside. ); } ``` -------------------------------- ### Fix Functional Component Ref Error Source: https://github.com/steffeydev/react-native-popover-view/blob/master/README.md When passing a functional component to the Popover 'from' prop, use React.forwardRef to resolve ref errors. This ensures the Popover can correctly determine the position of the 'from' component. ```javascript Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()? ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.