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 @@ -149,6 +149,7 @@ +tooltipContext: TooltipContextType, +closeTooltip: () => mixed, +boundTooltipItem: React.ComponentType, + +margin: number, }; export type TooltipMenuProps = { @@ -194,15 +195,14 @@ extrapolate: Extrapolate.CLAMP, }); - const { margin } = this; this.tooltipVerticalAbove = interpolateNode(position, { inputRange: [0, 1], - outputRange: [margin + this.tooltipHeight / 2, 0], + outputRange: [this.props.margin + this.tooltipHeight / 2, 0], extrapolate: Extrapolate.CLAMP, }); this.tooltipVerticalBelow = interpolateNode(position, { inputRange: [0, 1], - outputRange: [-margin - this.tooltipHeight / 2, 0], + outputRange: [-this.props.margin - this.tooltipHeight / 2, 0], extrapolate: Extrapolate.CLAMP, }); @@ -251,8 +251,8 @@ const boundsTop = verticalBounds.y; const boundsBottom = verticalBounds.y + verticalBounds.height; - const { margin, tooltipHeight: curTooltipHeight } = this; - const fullHeight = curTooltipHeight + margin; + const { tooltipHeight: curTooltipHeight } = this; + const fullHeight = curTooltipHeight + this.props.margin; if ( contentBottom + fullHeight > boundsBottom && contentTop - fullHeight > boundsTop @@ -295,19 +295,12 @@ }; } - get margin(): number { - const customMargin = this.props.route.params.margin; - return customMargin !== null && customMargin !== undefined - ? customMargin - : 20; - } - get tooltipContainerStyle(): AnimatedViewStyle { - const { dimensions, route } = this.props; + const { dimensions, route, margin } = this.props; const { initialCoordinates, verticalBounds, chatInputBarHeight } = route.params; const { x, y, width, height } = initialCoordinates; - const { margin, tooltipLocation } = this; + const { tooltipLocation } = this; const style: WritableAnimatedStyleObj = {}; style.position = 'absolute'; @@ -374,6 +367,7 @@ tooltipContext, closeTooltip, boundTooltipItem, + margin, ...navAndRouteForFlow } = this.props; @@ -561,6 +555,14 @@ const tooltipContext = React.useContext(TooltipContext); invariant(tooltipContext, 'TooltipContext should be set in Tooltip'); + + const margin = React.useMemo(() => { + const customMargin = params.margin; + return customMargin !== null && customMargin !== undefined + ? customMargin + : 20; + }, [params.margin]); + return ( ); }