UNPKG

sonner-native

Version:

An opinionated toast component for React Native. A port of @emilkowalski's sonner.

60 lines (59 loc) 1.44 kB
"use strict"; import React from 'react'; import { Platform, View } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { useToastContext } from "./context.js"; import { jsx as _jsx } from "react/jsx-runtime"; export const Positioner = ({ children, position, style, ...props }) => { const { offset } = useToastContext(); const { top, bottom } = useSafeAreaInsets(); const containerStyle = React.useMemo(() => { if (position === 'center') { return { position: 'absolute', top: 0, bottom: 0, left: 0, right: 0, justifyContent: 'center', alignItems: 'center' }; } return { position: 'absolute', width: '100%', alignItems: 'center' }; }, [position]); const insetValues = React.useMemo(() => { if (position === 'bottom-center') { return { bottom: offset || bottom || 40 }; } if (position === 'top-center') { return { top: offset || top || 40 }; } return {}; }, [position, bottom, top, offset]); const hasChildren = React.Children.count(children) > 0; return /*#__PURE__*/_jsx(View, { style: [containerStyle, insetValues, style], pointerEvents: Platform.OS === 'android' && !hasChildren ? 'none' : 'box-none', ...props, children: children }); }; //# sourceMappingURL=positioner.js.map