Skip to content

Commit 43cb59d

Browse files
authored
[win32] Remove usage of Animated in LogBox (#14809)
* Remove usage of Animated in LogBox * Change files * lint fix * lint fix
1 parent 248255e commit 43cb59d

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Remove usage of Animated in LogBox",
4+
"packageName": "@office-iss/react-native-win32",
5+
"email": "30809111+acoates-ms@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

packages/@office-iss/react-native-win32/overrides.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@
299299
"baseFile": "packages/react-native/Libraries/LogBox/UI/LogBoxInspectorReactFrames.js",
300300
"baseHash": "3a3d7da499937cce35c9bd17a11f10b2eeac04cc"
301301
},
302+
{
303+
"type": "derived",
304+
"file": "src-win/Libraries/LogBox/UI/LogBoxInspectorSourceMapStatus.win32.js",
305+
"baseFile": "packages/react-native/Libraries/LogBox/UI/LogBoxInspectorSourceMapStatus.js",
306+
"baseHash": "b355418205aa52cf33fb7e4d521b26083eada49d"
307+
},
302308
{
303309
"type": "derived",
304310
"file": "src-win/Libraries/LogBox/UI/LogBoxInspectorStackFrame.win32.js",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
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

Comments
 (0)