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 @@ -148,13 +148,15 @@ +styles: $ReadOnly, +tooltipContext: TooltipContextType, +closeTooltip: () => mixed, - +boundTooltipItem: React.ComponentType, +getTooltipLocation: () => 'above' | 'below' | 'fixed', - +tooltipHorizontalOffset: Value, +opacityStyle: AnimatedViewStyle, +contentContainerStyle: ViewStyle, +buttonStyle: ViewStyle, +tooltipContainerStyle: AnimatedViewStyle, + +getTooltipItem: () => React.ComponentType, + +onPressMore: () => void, + +renderMoreIcon: () => React.Node, + +onTooltipContainerLayout: (event: LayoutEvent) => void, }; export type TooltipMenuProps = { @@ -180,13 +182,15 @@ styles, tooltipContext, closeTooltip, - boundTooltipItem, getTooltipLocation, - tooltipHorizontalOffset, opacityStyle, contentContainerStyle, buttonStyle, tooltipContainerStyle: _tooltipContainerStyle, + getTooltipItem, + onPressMore, + renderMoreIcon, + onTooltipContainerLayout, ...navAndRouteForFlow } = this.props; @@ -200,7 +204,7 @@ const items: Array = [ , ]; @@ -210,8 +214,8 @@ , @@ -264,7 +268,7 @@ tooltip = ( {triangleUp} {items} @@ -296,44 +300,6 @@ ); } - - getTooltipItem(): React.ComponentType { - const BoundTooltipItem = this.props.boundTooltipItem; - return BoundTooltipItem; - } - - onPressMore = () => { - Keyboard.dismiss(); - this.props.tooltipContext.showActionSheet(); - }; - - renderMoreIcon = (): React.Node => { - const { styles } = this.props; - return ( - - ); - }; - - onTooltipContainerLayout = (event: LayoutEvent) => { - const { route, dimensions } = this.props; - const { x, width } = route.params.initialCoordinates; - - const extraLeftSpace = x; - const extraRightSpace = dimensions.width - width - x; - - const actualWidth = event.nativeEvent.layout.width; - if (extraLeftSpace < extraRightSpace) { - const minWidth = width + 2 * extraLeftSpace; - this.props.tooltipHorizontalOffset.setValue( - (minWidth - actualWidth) / 2, - ); - } else { - const minWidth = width + 2 * extraRightSpace; - this.props.tooltipHorizontalOffset.setValue( - (actualWidth - minWidth) / 2, - ); - } - }; } function ConnectedTooltip( props: $ReadOnly<{ @@ -593,6 +559,46 @@ tooltipVerticalBelow, ]); + const getTooltipItem = + React.useCallback((): React.ComponentType => { + const BoundTooltipItem = boundTooltipItem; + return BoundTooltipItem; + }, [boundTooltipItem]); + + const onPressMore = React.useCallback(() => { + Keyboard.dismiss(); + tooltipContext.showActionSheet(); + }, [tooltipContext]); + + const renderMoreIcon = React.useCallback((): React.Node => { + return ( + + ); + }, [styles.icon]); + + const onTooltipContainerLayout = React.useCallback( + (event: LayoutEvent) => { + const { x, width } = params.initialCoordinates; + + const extraLeftSpace = x; + const extraRightSpace = dimensions.width - width - x; + + const actualWidth = event.nativeEvent.layout.width; + if (extraLeftSpace < extraRightSpace) { + const minWidth = width + 2 * extraLeftSpace; + tooltipHorizontalOffset.current.setValue( + (minWidth - actualWidth) / 2, + ); + } else { + const minWidth = width + 2 * extraRightSpace; + tooltipHorizontalOffset.current.setValue( + (actualWidth - minWidth) / 2, + ); + } + }, + [dimensions.width, params.initialCoordinates], + ); + return ( ); }