diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-03-03 15:13:31 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-03 15:13:31 -0600 |
commit | a9920d963041e53be5c454da30f8109c2a145d19 (patch) | |
tree | b02b37ffb7ac972f8e34944749fd6cdc6b67b05d /src/view/com/util/forms/DropdownButton.tsx | |
parent | c2bfa111ac1f2c5fed2dd1caa92106849b14eaec (diff) | |
download | voidsky-a9920d963041e53be5c454da30f8109c2a145d19.tar.zst |
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)
Diffstat (limited to 'src/view/com/util/forms/DropdownButton.tsx')
-rw-r--r-- | src/view/com/util/forms/DropdownButton.tsx | 18 |
1 files changed, 17 insertions, 1 deletions
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<ViewStyle> @@ -124,6 +132,7 @@ export function PostDropdownBtn({ itemTitle: string isAuthor: boolean onCopyPostText: () => void + onOpenTranslate: () => void onDeletePost: () => void }) { const store = useStores() @@ -153,6 +162,13 @@ export function PostDropdownBtn({ }, }, { + icon: 'language', + label: 'Translate...', + onPress() { + onOpenTranslate() + }, + }, + { icon: 'circle-exclamation', label: 'Report post', onPress() { |