|
| 1 | +/** |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @flow strict-local |
| 8 | + * @format |
| 9 | + */ |
| 10 | + |
| 11 | +import type {GestureResponderEvent} from '../../Types/CoreEventTypes'; |
| 12 | + |
| 13 | +// import Animated from '../../Animated/Animated'; [Win32] |
| 14 | +// import Easing from '../../Animated/Easing'; [Win32] |
| 15 | +import StyleSheet from '../../StyleSheet/StyleSheet'; |
| 16 | +import Text from '../../Text/Text'; |
| 17 | +import LogBoxButton from './LogBoxButton'; |
| 18 | +import * as LogBoxStyle from './LogBoxStyle'; |
| 19 | +import * as React from 'react'; |
| 20 | + |
| 21 | +type Props = $ReadOnly<{ |
| 22 | + onPress?: ?(event: GestureResponderEvent) => void, |
| 23 | + status: 'COMPLETE' | 'FAILED' | 'NONE' | 'PENDING', |
| 24 | +}>; |
| 25 | + |
| 26 | +function LogBoxInspectorSourceMapStatus(props: Props): React.Node { |
| 27 | + // [Win32] Dont use Animated |
| 28 | + /* |
| 29 | + const [state, setState] = React.useState({ |
| 30 | + animation: null, |
| 31 | + rotate: null, |
| 32 | + }); |
| 33 | +
|
| 34 | + React.useEffect(() => { |
| 35 | + if (props.status === 'PENDING') { |
| 36 | + if (state.animation == null) { |
| 37 | + const animated = new Animated.Value(0); |
| 38 | + const animation = Animated.loop( |
| 39 | + Animated.timing(animated, { |
| 40 | + duration: 2000, |
| 41 | + easing: Easing.linear, |
| 42 | + toValue: 1, |
| 43 | + useNativeDriver: true, |
| 44 | + }), |
| 45 | + ); |
| 46 | + // $FlowFixMe[incompatible-call] |
| 47 | + setState({ |
| 48 | + animation, |
| 49 | + rotate: animated.interpolate({ |
| 50 | + inputRange: [0, 1], |
| 51 | + outputRange: ['0deg', '360deg'], |
| 52 | + }), |
| 53 | + }); |
| 54 | + animation.start(); |
| 55 | + } |
| 56 | + } else { |
| 57 | + if (state.animation != null) { |
| 58 | + state.animation.stop(); |
| 59 | + setState({ |
| 60 | + animation: null, |
| 61 | + rotate: null, |
| 62 | + }); |
| 63 | + } |
| 64 | + } |
| 65 | +
|
| 66 | + return () => { |
| 67 | + if (state.animation != null) { |
| 68 | + state.animation.stop(); |
| 69 | + } |
| 70 | + }; |
| 71 | + }, [props.status, state.animation]); |
| 72 | +
|
| 73 | + let image; |
| 74 | + */ |
| 75 | + let color; |
| 76 | + switch (props.status) { |
| 77 | + case 'FAILED': |
| 78 | + // image = require('./LogBoxImages/alert-triangle.png'); // [win32] Dont use LogBox images |
| 79 | + color = LogBoxStyle.getErrorColor(1); |
| 80 | + break; |
| 81 | + case 'PENDING': |
| 82 | + // image = require('./LogBoxImages/loader.png'); // [win32] Dont use LogBox images |
| 83 | + color = LogBoxStyle.getWarningColor(1); |
| 84 | + break; |
| 85 | + default: // [Win32] |
| 86 | + return null; // [Win32] |
| 87 | + } |
| 88 | + |
| 89 | + if (props.status === 'COMPLETE' /* [Win32] || image == null */) { |
| 90 | + return null; |
| 91 | + } |
| 92 | + |
| 93 | + return ( |
| 94 | + <LogBoxButton |
| 95 | + backgroundColor={{ |
| 96 | + default: 'transparent', |
| 97 | + pressed: LogBoxStyle.getBackgroundColor(1), |
| 98 | + }} |
| 99 | + hitSlop={{bottom: 8, left: 8, right: 8, top: 8}} |
| 100 | + onPress={props.onPress} |
| 101 | + style={styles.root}> |
| 102 | + {/* [Win32] Avoid Animated usage |
| 103 | + <Animated.Image |
| 104 | + source={image} |
| 105 | + style={[ |
| 106 | + styles.image, |
| 107 | + {tintColor: color}, |
| 108 | + state.rotate == null || props.status !== 'PENDING' |
| 109 | + ? null |
| 110 | + : {transform: [{rotate: state.rotate}]}, |
| 111 | + ]} |
| 112 | + /> |
| 113 | + */} |
| 114 | + <Text style={[styles.text, {color}]}>Source Map</Text> |
| 115 | + </LogBoxButton> |
| 116 | + ); |
| 117 | +} |
| 118 | + |
| 119 | +const styles = StyleSheet.create({ |
| 120 | + root: { |
| 121 | + alignItems: 'center', |
| 122 | + borderRadius: 12, |
| 123 | + flexDirection: 'row', |
| 124 | + height: 24, |
| 125 | + paddingHorizontal: 8, |
| 126 | + }, |
| 127 | + image: { |
| 128 | + height: 14, |
| 129 | + width: 16, |
| 130 | + marginEnd: 4, |
| 131 | + tintColor: LogBoxStyle.getTextColor(0.4), |
| 132 | + }, |
| 133 | + text: { |
| 134 | + fontSize: 12, |
| 135 | + includeFontPadding: false, |
| 136 | + lineHeight: 16, |
| 137 | + }, |
| 138 | +}); |
| 139 | + |
| 140 | +export default LogBoxInspectorSourceMapStatus; |
0 commit comments