forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogBoxInspectorStackFrame.js
More file actions
116 lines (108 loc) · 2.86 KB
/
LogBoxInspectorStackFrame.js
File metadata and controls
116 lines (108 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
'use strict';
import * as React from 'react';
import StyleSheet from '../../StyleSheet/StyleSheet';
import Text from '../../Text/Text';
import View from '../../Components/View/View';
import Platform from '../../Utilities/Platform';
import LogBoxButton from './LogBoxButton';
import * as LogBoxStyle from './LogBoxStyle';
import type {PressEvent} from '../../Types/CoreEventTypes';
import type {StackFrame} from '../../Core/NativeExceptionsManager';
type Props = $ReadOnly<{|
frame: StackFrame,
onPress?: ?(event: PressEvent) => void,
|}>;
function LogBoxInspectorStackFrame(props: Props): React.Node {
const {frame, onPress} = props;
const column = frame.column != null && parseInt(frame.column, 10);
const location =
getFileName(frame.file) +
(frame.lineNumber != null
? ':' +
frame.lineNumber +
(column && !isNaN(column) ? ':' + (column + 1) : '')
: '');
return (
<View style={styles.frameContainer}>
<LogBoxButton
backgroundColor={{
default: 'transparent',
pressed: onPress ? LogBoxStyle.getBackgroundColor(1) : 'transparent',
}}
onPress={onPress}
style={styles.frame}>
<Text style={[styles.name, frame.collapse === true && styles.dim]}>
{frame.methodName}
</Text>
<Text
ellipsizeMode="middle"
numberOfLines={1}
style={[styles.location, frame.collapse === true && styles.dim]}>
{location}
</Text>
</LogBoxButton>
</View>
);
}
function getFileName(file) {
if (file == null) {
return '<unknown>';
}
const queryIndex = file.indexOf('?');
return file.substring(
file.lastIndexOf('/') + 1,
queryIndex === -1 ? file.length : queryIndex,
);
}
const styles = StyleSheet.create({
frameContainer: {
flexDirection: 'row',
paddingHorizontal: 15,
},
frame: {
flex: 1,
paddingVertical: 4,
paddingHorizontal: 10,
borderRadius: 5,
},
lineLocation: {
flexDirection: 'row',
},
name: {
color: LogBoxStyle.getTextColor(1),
fontSize: 14,
includeFontPadding: false,
lineHeight: 18,
fontWeight: '400',
fontFamily: Platform.select({android: 'monospace', ios: 'Menlo'}),
},
location: {
color: LogBoxStyle.getTextColor(0.8),
fontSize: 12,
fontWeight: '300',
includeFontPadding: false,
lineHeight: 16,
paddingLeft: 10,
},
dim: {
color: LogBoxStyle.getTextColor(0.4),
fontWeight: '300',
},
line: {
color: LogBoxStyle.getTextColor(0.8),
fontSize: 12,
fontWeight: '300',
includeFontPadding: false,
lineHeight: 16,
},
});
export default LogBoxInspectorStackFrame;