From a9920d963041e53be5c454da30f8109c2a145d19 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Fri, 3 Mar 2023 15:13:31 -0600 Subject: Add translate link to post menu (#261) * Add a google translate menu item to posts * Fix: make sure the dropdown menu is always visible (when low on the screen) --- src/view/com/util/forms/DropdownButton.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/view/com/util/forms/DropdownButton.tsx') diff --git a/src/view/com/util/forms/DropdownButton.tsx b/src/view/com/util/forms/DropdownButton.tsx index 2946c5ca0..dcabe5455 100644 --- a/src/view/com/util/forms/DropdownButton.tsx +++ b/src/view/com/util/forms/DropdownButton.tsx @@ -1,5 +1,6 @@ import React, {useRef} from 'react' import { + Dimensions, Share, StyleProp, StyleSheet, @@ -21,6 +22,7 @@ import {usePalette} from 'lib/hooks/usePalette' import {useTheme} from 'lib/ThemeContext' const HITSLOP = {left: 10, top: 10, right: 10, bottom: 10} +const ESTIMATED_MENU_ITEM_HEIGHT = 52 export interface DropdownItem { icon?: IconProp @@ -67,10 +69,15 @@ export function DropdownButton({ if (!menuWidth) { menuWidth = 200 } + const winHeight = Dimensions.get('window').height + const estimatedMenuHeight = items.length * ESTIMATED_MENU_ITEM_HEIGHT const newX = openToRight ? pageX + width + rightOffset : pageX + width - menuWidth - const newY = pageY + height + bottomOffset + let newY = pageY + height + bottomOffset + if (newY + estimatedMenuHeight > winHeight) { + newY -= estimatedMenuHeight + } createDropdownMenu( newX, newY, @@ -114,6 +121,7 @@ export function PostDropdownBtn({ itemHref, isAuthor, onCopyPostText, + onOpenTranslate, onDeletePost, }: { style?: StyleProp @@ -124,6 +132,7 @@ export function PostDropdownBtn({ itemTitle: string isAuthor: boolean onCopyPostText: () => void + onOpenTranslate: () => void onDeletePost: () => void }) { const store = useStores() @@ -152,6 +161,13 @@ export function PostDropdownBtn({ Share.share({url: toShareUrl(itemHref)}) }, }, + { + icon: 'language', + label: 'Translate...', + onPress() { + onOpenTranslate() + }, + }, { icon: 'circle-exclamation', label: 'Report post', -- cgit 1.4.1