about summary refs log tree commit diff
path: root/src/components/ContextMenu/types.ts
diff options
context:
space:
mode:
authorSamuel Newman <mozzius@protonmail.com>2025-03-21 18:29:14 +0200
committerGitHub <noreply@github.com>2025-03-21 09:29:14 -0700
commitc4785ef96e13d02b217dce4e777269c0e895507d (patch)
tree785b8f00ded8dbdb6cd167a280141faad8873e3b /src/components/ContextMenu/types.ts
parentf6f253b4c93f5166648615d03f38ede40135f646 (diff)
downloadvoidsky-c4785ef96e13d02b217dce4e777269c0e895507d.tar.zst
New `ContextMenu` menu type for DM messages (#8014)
* get context menu somewhat working ish

* take screenshot rather than double rendering

* get animations somewhat working

* get transform animation working

* rm log

* upwards safe area

* get working on android

* get android working once and for all

* fix positioning on both platforms

* use dark blur on ios always, fix dark mode

* allow closing with hardware back press

* try and fix type error

* add note about ts-ignore

* round post

* add image capture error handling

* extract magic numbers

* set explicit embed width, rm top margin

* Message embed width tweaks

* Format

* fix position of embeds

* same as above for web

---------

Co-authored-by: Eric Bailey <git@esb.lol>
Diffstat (limited to 'src/components/ContextMenu/types.ts')
-rw-r--r--src/components/ContextMenu/types.ts97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/components/ContextMenu/types.ts b/src/components/ContextMenu/types.ts
new file mode 100644
index 000000000..0b3fedc55
--- /dev/null
+++ b/src/components/ContextMenu/types.ts
@@ -0,0 +1,97 @@
+import React from 'react'
+import {AccessibilityRole, StyleProp, ViewStyle} from 'react-native'
+import {SharedValue} from 'react-native-reanimated'
+
+import * as Dialog from '#/components/Dialog'
+import {RadixPassThroughTriggerProps} from '#/components/Menu/types'
+
+export type {
+  GroupProps,
+  ItemIconProps,
+  ItemProps,
+  ItemTextProps,
+} from '#/components/Menu/types'
+
+export type Measurement = {
+  x: number
+  y: number
+  width: number
+  height: number
+}
+
+export type ContextType = {
+  isOpen: boolean
+  measurement: Measurement | null
+  /* Spring animation between 0 and 1 */
+  animationSV: SharedValue<number>
+  /* Translation in Y axis to ensure everything's onscreen */
+  translationSV: SharedValue<number>
+  open: (evt: Measurement) => void
+  close: () => void
+}
+
+export type ItemContextType = {
+  disabled: boolean
+}
+
+export type TriggerProps = {
+  children(props: TriggerChildProps): React.ReactNode
+  label: string
+  /**
+   * When activated, this is the accessibility label for the entire thing that has been triggered.
+   * For example, if the trigger is a message bubble, use the message content.
+   *
+   * @platform ios, android
+   */
+  contentLabel: string
+  hint?: string
+  role?: AccessibilityRole
+  style?: StyleProp<ViewStyle>
+}
+export type TriggerChildProps =
+  | {
+      isNative: true
+      control: {isOpen: boolean; open: () => void}
+      state: {
+        hovered: false
+        focused: false
+        pressed: false
+      }
+      /**
+       * We don't necessarily know what these will be spread on to, so we
+       * should add props one-by-one.
+       *
+       * On web, these properties are applied to a parent `Pressable`, so this
+       * object is empty.
+       */
+      props: {
+        ref: null
+        onPress: null
+        onFocus: null
+        onBlur: null
+        onPressIn: null
+        onPressOut: null
+        accessibilityHint: null
+        accessibilityLabel: string
+        accessibilityRole: null
+      }
+    }
+  | {
+      isNative: false
+      control: Dialog.DialogOuterProps['control']
+      state: {
+        hovered: false
+        focused: false
+        pressed: false
+      }
+      props: RadixPassThroughTriggerProps & {
+        onPress: () => void
+        onFocus: () => void
+        onBlur: () => void
+        onMouseEnter: () => void
+        onMouseLeave: () => void
+        accessibilityHint?: string
+        accessibilityLabel: string
+        accessibilityRole: AccessibilityRole
+      }
+    }