diff --git a/native/chat/multimedia-message-tooltip-modal.react.js b/native/chat/multimedia-message-tooltip-modal.react.js --- a/native/chat/multimedia-message-tooltip-modal.react.js +++ b/native/chat/multimedia-message-tooltip-modal.react.js @@ -11,7 +11,7 @@ import { createTooltip, type TooltipParams, - type BaseTooltipProps, + type TooltipProps, type TooltipMenuProps, } from '../tooltip/tooltip.react.js'; import type { ChatMultimediaMessageInfoItem } from '../types/chat-types.js'; @@ -97,7 +97,7 @@ } const MultimediaMessageTooltipModal: React.ComponentType< - BaseTooltipProps<'MultimediaMessageTooltipModal'>, + TooltipProps<'MultimediaMessageTooltipModal'>, > = createTooltip<'MultimediaMessageTooltipModal'>( MultimediaMessageTooltipButton, TooltipMenu, diff --git a/native/chat/robotext-message-tooltip-modal.react.js b/native/chat/robotext-message-tooltip-modal.react.js --- a/native/chat/robotext-message-tooltip-modal.react.js +++ b/native/chat/robotext-message-tooltip-modal.react.js @@ -8,7 +8,7 @@ import { createTooltip, type TooltipParams, - type BaseTooltipProps, + type TooltipProps, type TooltipMenuProps, } from '../tooltip/tooltip.react.js'; import type { ChatRobotextMessageInfoItemWithHeight } from '../types/chat-types.js'; @@ -45,7 +45,7 @@ } const RobotextMessageTooltipModal: React.ComponentType< - BaseTooltipProps<'RobotextMessageTooltipModal'>, + TooltipProps<'RobotextMessageTooltipModal'>, > = createTooltip<'RobotextMessageTooltipModal'>( RobotextMessageTooltipButton, TooltipMenu, diff --git a/native/chat/settings/thread-settings-member-tooltip-modal.react.js b/native/chat/settings/thread-settings-member-tooltip-modal.react.js --- a/native/chat/settings/thread-settings-member-tooltip-modal.react.js +++ b/native/chat/settings/thread-settings-member-tooltip-modal.react.js @@ -15,7 +15,7 @@ import type { AppNavigationProp } from '../../navigation/app-navigator.react'; import { ChangeRolesScreenRouteName } from '../../navigation/route-names.js'; import { - type BaseTooltipProps, + type TooltipProps, createTooltip, type TooltipMenuProps, type TooltipParams, @@ -105,7 +105,7 @@ } const ThreadSettingsMemberTooltipModal: React.ComponentType< - BaseTooltipProps<'ThreadSettingsMemberTooltipModal'>, + TooltipProps<'ThreadSettingsMemberTooltipModal'>, > = createTooltip<'ThreadSettingsMemberTooltipModal'>( ThreadSettingsMemberTooltipButton, TooltipMenu, diff --git a/native/chat/text-message-tooltip-modal.react.js b/native/chat/text-message-tooltip-modal.react.js --- a/native/chat/text-message-tooltip-modal.react.js +++ b/native/chat/text-message-tooltip-modal.react.js @@ -19,7 +19,7 @@ import { createTooltip, type TooltipParams, - type BaseTooltipProps, + type TooltipProps, type TooltipMenuProps, } from '../tooltip/tooltip.react.js'; import type { ChatTextMessageInfoItemWithHeight } from '../types/chat-types.js'; @@ -191,7 +191,7 @@ } const TextMessageTooltipModal: React.ComponentType< - BaseTooltipProps<'TextMessageTooltipModal'>, + TooltipProps<'TextMessageTooltipModal'>, > = createTooltip<'TextMessageTooltipModal'>( TextMessageTooltipButton, TooltipMenu, diff --git a/native/profile/user-relationship-tooltip-modal.react.js b/native/profile/user-relationship-tooltip-modal.react.js --- a/native/profile/user-relationship-tooltip-modal.react.js +++ b/native/profile/user-relationship-tooltip-modal.react.js @@ -15,7 +15,7 @@ import { createTooltip, type TooltipParams, - type BaseTooltipProps, + type TooltipProps, type TooltipMenuProps, type TooltipRoute, } from '../tooltip/tooltip.react.js'; @@ -158,7 +158,7 @@ } const UserRelationshipTooltipModal: React.ComponentType< - BaseTooltipProps<'UserRelationshipTooltipModal'>, + TooltipProps<'UserRelationshipTooltipModal'>, > = createTooltip<'UserRelationshipTooltipModal'>( UserRelationshipTooltipButton, TooltipMenu, diff --git a/native/tooltip/tooltip.react.js b/native/tooltip/tooltip.react.js --- a/native/tooltip/tooltip.react.js +++ b/native/tooltip/tooltip.react.js @@ -15,20 +15,15 @@ import { TooltipContextProvider, TooltipContext, - type TooltipContextType, } from './tooltip-context.react.js'; import BaseTooltipItem, { type TooltipItemBaseProps, } from './tooltip-item.react.js'; -import { ChatContext, type ChatContextType } from '../chat/chat-context.js'; +import { ChatContext } from '../chat/chat-context.js'; import SWMansionIcon from '../components/swmansion-icon.react.js'; import type { AppNavigationProp } from '../navigation/app-navigator.react.js'; -import { - OverlayContext, - type OverlayContextType, -} from '../navigation/overlay-context.js'; +import { OverlayContext } from '../navigation/overlay-context.js'; import type { TooltipModalParamList } from '../navigation/route-names.js'; -import { type DimensionsInfo } from '../redux/dimensions-updater.react.js'; import { useSelector } from '../redux/redux-utils.js'; import { useStyles } from '../themes/colors.js'; import { @@ -130,7 +125,7 @@ RouteName, >; -export type BaseTooltipProps = { +export type TooltipProps = { +navigation: AppNavigationProp, +route: TooltipRoute, }; @@ -139,170 +134,22 @@ +progress: Node, +isOpeningSidebar: boolean, }; -type TooltipProps = { - ...Base, - // Redux state - +dimensions: DimensionsInfo, - +overlayContext: ?OverlayContextType, - +chatContext: ?ChatContextType, - +styles: $ReadOnly, - +tooltipContext: TooltipContextType, - +closeTooltip: () => mixed, - +computedTooltipLocation: 'above' | 'below' | 'fixed', - +opacityStyle: AnimatedViewStyle, - +contentContainerStyle: ViewStyle, - +buttonStyle: ViewStyle, - +tooltipContainerStyle: AnimatedViewStyle, - +boundTooltipItem: React.ComponentType, - +onPressMore: () => void, - +renderMoreIcon: () => React.Node, - +onTooltipContainerLayout: (event: LayoutEvent) => void, -}; export type TooltipMenuProps = { - ...BaseTooltipProps, + ...TooltipProps, +tooltipItem: React.ComponentType, }; function createTooltip< RouteName: $Keys, - BaseTooltipPropsType: BaseTooltipProps = BaseTooltipProps, + TooltipPropsType: TooltipProps = TooltipProps, >( - ButtonComponent: React.ComponentType>, + ButtonComponent: React.ComponentType>, MenuComponent: React.ComponentType>, -): React.ComponentType { - class Tooltip extends React.PureComponent< - TooltipProps, - > { - render(): React.Node { - const { - dimensions, - overlayContext, - chatContext, - styles, - tooltipContext, - closeTooltip, - computedTooltipLocation, - opacityStyle, - contentContainerStyle, - buttonStyle, - tooltipContainerStyle: _tooltipContainerStyle, - boundTooltipItem, - onPressMore, - renderMoreIcon, - onTooltipContainerLayout, - ...navAndRouteForFlow - } = this.props; - - const tooltipContainerStyle: Array = [styles.itemContainer]; - - if (computedTooltipLocation === 'fixed') { - tooltipContainerStyle.push(styles.itemContainerFixed); - } - - const items: Array = [ - , - ]; - - if (this.props.tooltipContext.shouldShowMore()) { - items.push( - , - ); - } - - let triangleStyle; - const { route } = this.props; - const { initialCoordinates } = route.params; - const { x, width } = initialCoordinates; - const extraLeftSpace = x; - const extraRightSpace = dimensions.width - width - x; - if (extraLeftSpace < extraRightSpace) { - triangleStyle = { - alignSelf: 'flex-start', - left: extraLeftSpace + (width - 20) / 2, - }; - } else { - triangleStyle = { - alignSelf: 'flex-end', - right: extraRightSpace + (width - 20) / 2, - }; - } - - let triangleDown = null; - let triangleUp = null; - if (computedTooltipLocation === 'above') { - triangleDown = ; - } else if (computedTooltipLocation === 'below') { - triangleUp = ; - } - - invariant(overlayContext, 'Tooltip should have OverlayContext'); - const { position } = overlayContext; - invariant(position, 'position should be defined in tooltip'); - - const isOpeningSidebar = !!chatContext?.currentTransitionSidebarSourceID; - - const buttonProps: ButtonProps = { - ...navAndRouteForFlow, - progress: position, - isOpeningSidebar, - }; - - const itemsStyles = [styles.items, styles.itemsFixed]; - - let tooltip = null; - - if (computedTooltipLocation !== 'fixed') { - tooltip = ( - - {triangleUp} - {items} - {triangleDown} - - ); - } else if ( - computedTooltipLocation === 'fixed' && - !this.props.route.params.hideTooltip - ) { - tooltip = ( - - {items} - - ); - } - - return ( - - - - - - - - - {tooltip} - - - ); - } - } - function ConnectedTooltip( +): React.ComponentType { + function Tooltip( props: $ReadOnly<{ - ...BaseTooltipPropsType, + ...TooltipPropsType, +hideTooltip: () => mixed, }>, ) { @@ -314,7 +161,7 @@ const { tooltipLocation } = params; const isFixed = tooltipLocation === 'fixed'; - const { hideTooltip, ...rest } = props; + const { hideTooltip, ...navAndRouteForFlow } = props; React.useEffect(() => { Haptics.impactAsync(); @@ -591,28 +438,104 @@ [dimensions.width, params.initialCoordinates], ); + const tooltipItemContainerStyle: Array = [styles.itemContainer]; + + if (computedTooltipLocation === 'fixed') { + tooltipItemContainerStyle.push(styles.itemContainerFixed); + } + + const items: Array = [ + , + ]; + + if (tooltipContext.shouldShowMore()) { + items.push( + , + ); + } + + let triangleStyle; + const { initialCoordinates } = params; + const { x, width } = initialCoordinates; + const extraLeftSpace = x; + const extraRightSpace = dimensions.width - width - x; + if (extraLeftSpace < extraRightSpace) { + triangleStyle = { + alignSelf: 'flex-start', + left: extraLeftSpace + (width - 20) / 2, + }; + } else { + triangleStyle = { + alignSelf: 'flex-end', + right: extraRightSpace + (width - 20) / 2, + }; + } + + let triangleDown = null; + let triangleUp = null; + if (computedTooltipLocation === 'above') { + triangleDown = ; + } else if (computedTooltipLocation === 'below') { + triangleUp = ; + } + + const isOpeningSidebar = !!chatContext?.currentTransitionSidebarSourceID; + + const buttonProps: ButtonProps = { + ...navAndRouteForFlow, + progress: position, + isOpeningSidebar, + }; + + const itemsStyles = [styles.items, styles.itemsFixed]; + + let tooltip = null; + + if (computedTooltipLocation !== 'fixed') { + tooltip = ( + + {triangleUp} + {items} + {triangleDown} + + ); + } else if (computedTooltipLocation === 'fixed' && !params.hideTooltip) { + tooltip = ( + + {items} + + ); + } + return ( - + + + + + + + + + {tooltip} + + ); } - function MemoizedTooltip(props: BaseTooltipPropsType) { + function MemoizedTooltip(props: TooltipPropsType) { const { visibleEntryIDs } = props.route.params; const { goBackOnce } = props.navigation; @@ -629,11 +552,11 @@ cancel={goBackOnce} hideTooltip={hideTooltip} > - + ); } - return React.memo(MemoizedTooltip); + return React.memo(MemoizedTooltip); } function getTooltipHeight(numEntries: number): number {