Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3502732
D13066.id43457.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D13066.id43457.diff
View Options
diff --git a/native/tooltip/nux-tips-overlay.react.js b/native/tooltip/nux-tips-overlay.react.js
--- a/native/tooltip/nux-tips-overlay.react.js
+++ b/native/tooltip/nux-tips-overlay.react.js
@@ -3,7 +3,7 @@
import invariant from 'invariant';
import * as React from 'react';
import { View, TouchableWithoutFeedback, Platform, Text } from 'react-native';
-import Animated from 'react-native-reanimated';
+import Animated, { withTiming } from 'react-native-reanimated';
import type { AppNavigationProp } from '../navigation/app-navigator.react.js';
import { OverlayContext } from '../navigation/overlay-context.js';
@@ -23,6 +23,8 @@
const { Value, Extrapolate, add, multiply, interpolateNode } = Animated;
+const animationDuration = 150;
+
const unboundStyles = {
backdrop: {
backgroundColor: 'black',
@@ -78,6 +80,19 @@
const tipHeight: number = 30;
const margin: number = 20;
+function opacityEnteringAnimation() {
+ 'worklet';
+
+ return {
+ animations: {
+ opacity: withTiming(0.7, { duration: animationDuration }),
+ },
+ initialValues: {
+ opacity: 0,
+ },
+ };
+}
+
function createNUXTipsOverlay(
ButtonComponent: React.ComponentType<NUXTipsOverlayProps>,
tipText: string,
@@ -86,6 +101,7 @@
const dimensions = useSelector(state => state.dimensions);
const overlayContext = React.useContext(OverlayContext);
invariant(overlayContext, 'NUXTipsOverlay should have OverlayContext');
+ const { onExitFinish } = overlayContext;
const position = React.useMemo(() => new Animated.Value(1), []);
@@ -108,18 +124,6 @@
};
}, [dimensions.height, route.params, styles.contentContainer]);
- const opacityStyle = React.useMemo(() => {
- const backdropOpacity = interpolateNode(position, {
- inputRange: [0, 1],
- outputRange: [0, 0.7],
- extrapolate: Extrapolate.CLAMP,
- });
- return {
- ...styles.backdrop,
- opacity: backdropOpacity,
- };
- }, [position, styles.backdrop]);
-
const { initialCoordinates, verticalBounds } = props.route.params;
const buttonStyle = React.useMemo(() => {
@@ -246,10 +250,29 @@
}
}, [dimensions.width, initialCoordinates]);
+ const opacityExitingAnimation = React.useCallback(() => {
+ 'worklet';
+
+ return {
+ animations: {
+ opacity: withTiming(0, { duration: animationDuration }),
+ },
+ initialValues: {
+ opacity: 0.7,
+ },
+ callback: onExitFinish,
+ };
+ }, [onExitFinish]);
+
return (
<TouchableWithoutFeedback onPress={goBackOnce}>
<View style={styles.container}>
- <AnimatedView style={opacityStyle} />
+ <AnimatedView
+ style={styles.backdrop}
+ // $FlowFixMe
+ entering={opacityEnteringAnimation}
+ exiting={opacityExitingAnimation}
+ />
<View style={contentContainerStyle}>
<View style={buttonStyle}>
<ButtonComponent navigation={props.navigation} route={route} />
@@ -268,7 +291,17 @@
</TouchableWithoutFeedback>
);
}
- return React.memo<NUXTipsOverlayProps>(NUXTipsOverlay);
+
+ function NUXTipsOverlayWrapper(props: NUXTipsOverlayProps) {
+ const overlayContext = React.useContext(OverlayContext);
+ invariant(overlayContext, 'NUXTipsOverlay should have OverlayContext');
+
+ const { shouldRenderScreenContent } = overlayContext;
+
+ return shouldRenderScreenContent ? <NUXTipsOverlay {...props} /> : null;
+ }
+
+ return React.memo<NUXTipsOverlayProps>(NUXTipsOverlayWrapper);
}
export { createNUXTipsOverlay };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 21, 5:01 AM (18 h, 52 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2683622
Default Alt Text
D13066.id43457.diff (3 KB)
Attached To
Mode
D13066: [native] Refactor background opacity to reanimated 2
Attached
Detach File
Event Timeline
Log In to Comment