Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3507320
D14108.id46326.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D14108.id46326.diff
View Options
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
@@ -152,6 +152,14 @@
+getMargin: () => number,
+getTooltipHeight: () => number,
+getTooltipLocation: () => 'above' | 'below' | 'fixed',
+ +backdropOpacity: Node,
+ +tooltipContainerOpacity: Node,
+ +tooltipVerticalAbove: Node,
+ +tooltipVerticalBelow: Node,
+ +tooltipHorizontalOffset: Value,
+ +tooltipHorizontal: Node,
+ +tooltipScale: Node,
+ +fixedTooltipVertical: Node,
};
export type TooltipMenuProps<RouteName> = {
@@ -169,70 +177,6 @@
class Tooltip extends React.PureComponent<
TooltipProps<BaseTooltipPropsType>,
> {
- backdropOpacity: Node;
- tooltipContainerOpacity: Node;
- tooltipVerticalAbove: Node;
- tooltipVerticalBelow: Node;
- tooltipHorizontalOffset: Value = new Value(0);
- tooltipHorizontal: Node;
- tooltipScale: Node;
- fixedTooltipVertical: Node;
-
- constructor(props: TooltipProps<BaseTooltipPropsType>) {
- super(props);
-
- const { overlayContext } = props;
- invariant(overlayContext, 'Tooltip should have OverlayContext');
- const { position } = overlayContext;
- invariant(position, 'position should be defined in tooltip');
-
- this.backdropOpacity = interpolateNode(position, {
- inputRange: [0, 1],
- outputRange: [0, 0.7],
- extrapolate: Extrapolate.CLAMP,
- });
- this.tooltipContainerOpacity = interpolateNode(position, {
- inputRange: [0, 0.1],
- outputRange: [0, 1],
- extrapolate: Extrapolate.CLAMP,
- });
-
- this.tooltipVerticalAbove = interpolateNode(position, {
- inputRange: [0, 1],
- outputRange: [
- this.props.getMargin() + this.props.getTooltipHeight() / 2,
- 0,
- ],
- extrapolate: Extrapolate.CLAMP,
- });
- this.tooltipVerticalBelow = interpolateNode(position, {
- inputRange: [0, 1],
- outputRange: [
- -this.props.getMargin() - this.props.getTooltipHeight() / 2,
- 0,
- ],
- extrapolate: Extrapolate.CLAMP,
- });
-
- const invertedPosition = add(1, multiply(-1, position));
-
- this.tooltipHorizontal = multiply(
- invertedPosition,
- this.tooltipHorizontalOffset,
- );
-
- this.tooltipScale = interpolateNode(position, {
- inputRange: [0, 0.2, 0.8, 1],
- outputRange: [0, 0, 1, 1],
- extrapolate: Extrapolate.CLAMP,
- });
-
- this.fixedTooltipVertical = multiply(
- invertedPosition,
- props.dimensions.height,
- );
- }
-
componentDidMount() {
Haptics.impactAsync();
}
@@ -240,7 +184,7 @@
get opacityStyle(): AnimatedViewStyle {
return {
...this.props.styles.backdrop,
- opacity: this.backdropOpacity,
+ opacity: this.props.backdropOpacity,
};
}
@@ -279,12 +223,12 @@
const style: WritableAnimatedStyleObj = {};
style.position = 'absolute';
style.alignItems = 'center';
- style.opacity = this.tooltipContainerOpacity;
+ style.opacity = this.props.tooltipContainerOpacity;
const transform: Array<ReanimatedTransform> = [];
if (tooltipLocation !== 'fixed') {
- transform.push({ translateX: this.tooltipHorizontal });
+ transform.push({ translateX: this.props.tooltipHorizontal });
}
const extraLeftSpace = x;
@@ -311,20 +255,20 @@
verticalBounds.y -
inputBarHeight +
padding;
- transform.push({ translateY: this.fixedTooltipVertical });
+ transform.push({ translateY: this.props.fixedTooltipVertical });
} else if (tooltipLocation === 'above') {
style.bottom =
dimensions.height - Math.max(y, verticalBounds.y) + getMargin();
- transform.push({ translateY: this.tooltipVerticalAbove });
+ transform.push({ translateY: this.props.tooltipVerticalAbove });
} else {
style.top =
Math.min(y + height, verticalBounds.y + verticalBounds.height) +
getMargin();
- transform.push({ translateY: this.tooltipVerticalBelow });
+ transform.push({ translateY: this.props.tooltipVerticalBelow });
}
if (tooltipLocation !== 'fixed') {
- transform.push({ scale: this.tooltipScale });
+ transform.push({ scale: this.props.tooltipScale });
}
style.transform = transform;
@@ -344,6 +288,14 @@
getMargin,
getTooltipHeight,
getTooltipLocation,
+ backdropOpacity,
+ tooltipContainerOpacity,
+ tooltipVerticalAbove,
+ tooltipVerticalBelow,
+ tooltipHorizontalOffset,
+ tooltipHorizontal,
+ tooltipScale,
+ fixedTooltipVertical,
...navAndRouteForFlow
} = this.props;
@@ -481,10 +433,14 @@
const actualWidth = event.nativeEvent.layout.width;
if (extraLeftSpace < extraRightSpace) {
const minWidth = width + 2 * extraLeftSpace;
- this.tooltipHorizontalOffset.setValue((minWidth - actualWidth) / 2);
+ this.props.tooltipHorizontalOffset.setValue(
+ (minWidth - actualWidth) / 2,
+ );
} else {
const minWidth = width + 2 * extraRightSpace;
- this.tooltipHorizontalOffset.setValue((actualWidth - minWidth) / 2);
+ this.props.tooltipHorizontalOffset.setValue(
+ (actualWidth - minWidth) / 2,
+ );
}
};
}
@@ -570,6 +526,74 @@
return 'below';
}, [getMargin, getTooltipHeight, params, tooltipLocation]);
+ invariant(overlayContext, 'Tooltip should have OverlayContext');
+ const { position } = overlayContext;
+ invariant(position, 'position should be defined in tooltip');
+
+ const backdropOpacity = React.useMemo(
+ () =>
+ interpolateNode(position, {
+ inputRange: [0, 1],
+ outputRange: [0, 0.7],
+ extrapolate: Extrapolate.CLAMP,
+ }),
+ [position],
+ );
+ const tooltipContainerOpacity = React.useMemo(
+ () =>
+ interpolateNode(position, {
+ inputRange: [0, 0.1],
+ outputRange: [0, 1],
+ extrapolate: Extrapolate.CLAMP,
+ }),
+ [position],
+ );
+
+ const tooltipVerticalAbove = React.useMemo(
+ () =>
+ interpolateNode(position, {
+ inputRange: [0, 1],
+ outputRange: [getMargin() + getTooltipHeight() / 2, 0],
+ extrapolate: Extrapolate.CLAMP,
+ }),
+ [getMargin, getTooltipHeight, position],
+ );
+ const tooltipVerticalBelow = React.useMemo(
+ () =>
+ interpolateNode(position, {
+ inputRange: [0, 1],
+ outputRange: [-getMargin() - getTooltipHeight() / 2, 0],
+ extrapolate: Extrapolate.CLAMP,
+ }),
+ [getMargin, getTooltipHeight, position],
+ );
+
+ const invertedPosition = React.useMemo(
+ () => add(1, multiply(-1, position)),
+ [position],
+ );
+ const tooltipHorizontalOffset = React.useRef(new Value(0));
+
+ const tooltipHorizontal = React.useMemo(
+ () => multiply(invertedPosition, tooltipHorizontalOffset.current),
+ [invertedPosition],
+ );
+
+ const tooltipScale = React.useMemo(
+ () =>
+ interpolateNode(position, {
+ inputRange: [0, 0.2, 0.8, 1],
+ outputRange: [0, 0, 1, 1],
+ extrapolate: Extrapolate.CLAMP,
+ }),
+ [position],
+ );
+
+ const fixedTooltipVertical = React.useMemo(
+ () => multiply(invertedPosition, dimensions.height),
+ [dimensions.height, invertedPosition],
+ );
+
return (
<Tooltip
{...rest}
@@ -583,6 +607,14 @@
getMargin={getMargin}
getTooltipHeight={getTooltipHeight}
getTooltipLocation={getTooltipLocation}
+ backdropOpacity={backdropOpacity}
+ tooltipContainerOpacity={tooltipContainerOpacity}
+ tooltipVerticalAbove={tooltipVerticalAbove}
+ tooltipVerticalBelow={tooltipVerticalBelow}
+ tooltipHorizontalOffset={tooltipHorizontalOffset.current}
+ tooltipHorizontal={tooltipHorizontal}
+ tooltipScale={tooltipScale}
+ fixedTooltipVertical={fixedTooltipVertical}
/>
);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 21, 8:12 PM (20 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2688953
Default Alt Text
D14108.id46326.diff (8 KB)
Attached To
Mode
D14108: [native] Move Reanimated nodes in Tooltip to functional component
Attached
Detach File
Event Timeline
Log In to Comment