sonner-native
Version:
An opinionated toast component for React Native. A port of @emilkowalski's sonner.
59 lines (58 loc) • 1.32 kB
JavaScript
;
import React from 'react';
import { 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]);
return /*#__PURE__*/_jsx(View, {
style: [containerStyle, insetValues, style],
pointerEvents: "box-none",
...props,
children: children
});
};
//# sourceMappingURL=positioner.js.map