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, +computedTooltipLocation: 'above' | 'below' | 'fixed', - +tooltipHorizontalOffset: Value, +opacityStyle: AnimatedViewStyle, +contentContainerStyle: ViewStyle, +buttonStyle: ViewStyle, +tooltipContainerStyle: AnimatedViewStyle, + +boundTooltipItem: React.ComponentType, + +onPressMore: () => void, + +renderMoreIcon: () => React.Node, + +onTooltipContainerLayout: (event: LayoutEvent) => void, }; export type TooltipMenuProps = { @@ -180,13 +182,15 @@ styles, tooltipContext, closeTooltip, - boundTooltipItem, computedTooltipLocation, - tooltipHorizontalOffset, opacityStyle, contentContainerStyle, buttonStyle, tooltipContainerStyle: _tooltipContainerStyle, + boundTooltipItem, + onPressMore, + renderMoreIcon, + onTooltipContainerLayout, ...navAndRouteForFlow } = this.props; @@ -199,7 +203,7 @@ const items: Array = [ , ]; @@ -209,8 +213,8 @@ , @@ -263,7 +267,7 @@ tooltip = ( {triangleUp} {items} @@ -295,44 +299,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<{ @@ -591,6 +557,40 @@ tooltipVerticalBelow, ]); + 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 ( ); }