mirror of
https://github.com/zhigang1992/react-native-hold-menu.git
synced 2026-06-19 01:46:33 +08:00
Add bottom props, update Telegram example
This commit is contained in:
@@ -35,7 +35,7 @@ function NavButton({
|
||||
<HoldItem
|
||||
id={id}
|
||||
disableMove
|
||||
menuAnchorPosition="bottom-right"
|
||||
bottom
|
||||
items={menuItems}
|
||||
active={active}
|
||||
onActivate={onActivate}
|
||||
|
||||
@@ -49,6 +49,7 @@ const HoldItemChildComponent = ({
|
||||
id,
|
||||
items,
|
||||
theme,
|
||||
bottom,
|
||||
styles: customStyles,
|
||||
children,
|
||||
isActive,
|
||||
@@ -86,7 +87,8 @@ const HoldItemChildComponent = ({
|
||||
const position = getTransformOrigin(
|
||||
measured.pageX,
|
||||
itemRectWidth.value,
|
||||
deviceOrientation == 'portrait' ? WINDOW_WIDTH : WINDOW_HEIGHT
|
||||
deviceOrientation == 'portrait' ? WINDOW_WIDTH : WINDOW_HEIGHT,
|
||||
bottom
|
||||
);
|
||||
transformOrigin.value = position;
|
||||
}
|
||||
|
||||
9
src/components/holdItem/types.d.ts
vendored
9
src/components/holdItem/types.d.ts
vendored
@@ -63,6 +63,15 @@ export interface HoldItemCommonProps {
|
||||
* theme="light"
|
||||
*/
|
||||
theme?: 'light' | 'dark';
|
||||
|
||||
/**
|
||||
* Set true if you want to open menu from bottom
|
||||
* @type boolean
|
||||
* @default false
|
||||
* @examples
|
||||
* bottom={true}
|
||||
*/
|
||||
bottom?: boolean;
|
||||
}
|
||||
|
||||
export interface HoldItemProps extends HoldItemCommonProps {
|
||||
|
||||
@@ -73,15 +73,21 @@ export const menuAnimationAnchor = (
|
||||
export const getTransformOrigin = (
|
||||
posX: number,
|
||||
itemWidth: number,
|
||||
windowWidth: number
|
||||
windowWidth: number,
|
||||
bottom?: boolean
|
||||
): TransformOriginAnchorPosition => {
|
||||
'worklet';
|
||||
const distanceToLeft = posX + itemWidth / 2;
|
||||
const distanceToRight = windowWidth - distanceToLeft;
|
||||
let position: TransformOriginAnchorPosition = 'top-right';
|
||||
|
||||
if (distanceToLeft < distanceToRight) position = 'top-left';
|
||||
else if (distanceToRight === distanceToLeft) position = 'top-center';
|
||||
let position: TransformOriginAnchorPosition = bottom
|
||||
? 'bottom-right'
|
||||
: 'top-right';
|
||||
|
||||
if (distanceToLeft < distanceToRight)
|
||||
position = bottom ? 'bottom-left' : 'top-left';
|
||||
else if (distanceToRight === distanceToLeft)
|
||||
position = bottom ? 'bottom-center' : 'top-center';
|
||||
|
||||
return position;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user