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 @@ -150,6 +150,7 @@ +closeTooltip: () => mixed, +boundTooltipItem: React.ComponentType, +margin: number, + +tooltipHeight: number, }; export type TooltipMenuProps = { @@ -197,12 +198,12 @@ this.tooltipVerticalAbove = interpolateNode(position, { inputRange: [0, 1], - outputRange: [this.props.margin + this.tooltipHeight / 2, 0], + outputRange: [this.props.margin + this.props.tooltipHeight / 2, 0], extrapolate: Extrapolate.CLAMP, }); this.tooltipVerticalBelow = interpolateNode(position, { inputRange: [0, 1], - outputRange: [-this.props.margin - this.tooltipHeight / 2, 0], + outputRange: [-this.props.margin - this.props.tooltipHeight / 2, 0], extrapolate: Extrapolate.CLAMP, }); @@ -229,14 +230,6 @@ Haptics.impactAsync(); } - get tooltipHeight(): number { - if (this.props.route.params.tooltipLocation === 'fixed') { - return fixedTooltipHeight; - } else { - return tooltipHeight(this.props.tooltipContext.getNumVisibleEntries()); - } - } - get tooltipLocation(): 'above' | 'below' | 'fixed' { const { params } = this.props.route; const { tooltipLocation } = params; @@ -251,8 +244,7 @@ const boundsTop = verticalBounds.y; const boundsBottom = verticalBounds.y + verticalBounds.height; - const { tooltipHeight: curTooltipHeight } = this; - const fullHeight = curTooltipHeight + this.props.margin; + const fullHeight = this.props.tooltipHeight + this.props.margin; if ( contentBottom + fullHeight > boundsBottom && contentTop - fullHeight > boundsTop @@ -368,6 +360,7 @@ closeTooltip, boundTooltipItem, margin, + tooltipHeight, ...navAndRouteForFlow } = this.props; @@ -563,6 +556,14 @@ : 20; }, [params.margin]); + const tooltipHeight = React.useMemo(() => { + if (tooltipLocation === 'fixed') { + return fixedTooltipHeight; + } else { + return getTooltipHeight(tooltipContext.getNumVisibleEntries()); + } + }, [tooltipLocation, tooltipContext]); + return ( ); } @@ -601,7 +603,7 @@ return React.memo(MemoizedTooltip); } -function tooltipHeight(numEntries: number): number { +function getTooltipHeight(numEntries: number): number { // 10 (triangle) + 37 * numEntries (entries) + numEntries - 1 (padding) return 9 + 38 * numEntries; }