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 { @@ -139,25 +134,6 @@ +progress: Node, +isOpeningSidebar: boolean, }; -type TooltipProps = { - ...Base, - // Redux state - +dimensions: DimensionsInfo, - +overlayContext: ?OverlayContextType, - +chatContext: ?ChatContextType, - +styles: $ReadOnly, - +tooltipContext: TooltipContextType, - +closeTooltip: () => mixed, - +getTooltipLocation: () => 'above' | 'below' | 'fixed', - +opacityStyle: AnimatedViewStyle, - +contentContainerStyle: ViewStyle, - +buttonStyle: ViewStyle, - +tooltipContainerStyle: AnimatedViewStyle, - +getTooltipItem: () => React.ComponentType, - +onPressMore: () => void, - +renderMoreIcon: () => React.Node, - +onTooltipContainerLayout: (event: LayoutEvent) => void, -}; export type TooltipMenuProps = { ...BaseTooltipProps, @@ -171,136 +147,6 @@ ButtonComponent: React.ComponentType>, MenuComponent: React.ComponentType>, ): React.ComponentType { - class Tooltip extends React.PureComponent< - TooltipProps, - > { - render(): React.Node { - const { - dimensions, - overlayContext, - chatContext, - styles, - tooltipContext, - closeTooltip, - getTooltipLocation, - opacityStyle, - contentContainerStyle, - buttonStyle, - tooltipContainerStyle: _tooltipContainerStyle, - getTooltipItem, - onPressMore, - renderMoreIcon, - onTooltipContainerLayout, - ...navAndRouteForFlow - } = this.props; - - const tooltipContainerStyle: Array = [styles.itemContainer]; - const tooltipLocation = getTooltipLocation(); - - if (tooltipLocation === '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 (tooltipLocation === 'above') { - triangleDown = ; - } else if (tooltipLocation === '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 (tooltipLocation !== 'fixed') { - tooltip = ( - - {triangleUp} - {items} - {triangleDown} - - ); - } else if ( - tooltipLocation === 'fixed' && - !this.props.route.params.hideTooltip - ) { - tooltip = ( - - {items} - - ); - } - - return ( - - - - - - - - - {tooltip} - - - ); - } - } function ConnectedTooltip( props: $ReadOnly<{ ...BaseTooltipPropsType, @@ -315,7 +161,7 @@ const { tooltipLocation } = params; const isFixed = tooltipLocation === 'fixed'; - const { hideTooltip, ...rest } = props; + const { hideTooltip, ...navAndRouteForFlow } = props; React.useEffect(() => { Haptics.impactAsync(); @@ -599,25 +445,101 @@ [dimensions.width, params.initialCoordinates], ); + const tooltipItemContainerStyle: Array = [styles.itemContainer]; + + if (tooltipLocation === '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 (tooltipLocation === 'above') { + triangleDown = ; + } else if (tooltipLocation === 'below') { + triangleUp = ; + } + + const isOpeningSidebar = !!chatContext?.currentTransitionSidebarSourceID; + + const buttonProps: ButtonProps = { + ...navAndRouteForFlow, + progress: position, + isOpeningSidebar, + }; + + const itemsStyles = [styles.items, styles.itemsFixed]; + + let tooltip = null; + + if (tooltipLocation !== 'fixed') { + tooltip = ( + + {triangleUp} + {items} + {triangleDown} + + ); + } else if (tooltipLocation === 'fixed' && !params.hideTooltip) { + tooltip = ( + + {items} + + ); + } + return ( - + + + + + + + + + {tooltip} + + ); } function MemoizedTooltip(props: BaseTooltipPropsType) {