mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
63b534a745
Summary: This diff makes number of improvements to stack frames: - Adds padding around stack frame pressables - Fixed wrapping for the closing bracket on component stacks - Adds passing around "see more" buttons - Fixed the count for "Show x more frames" when it's 0 and otherwise - Add more cases for the count text - Switches button back to minimize (snuck this in here) Changelog: [Internal] Reviewed By: cpojer Differential Revision: D18495331 fbshipit-source-id: 8b9efa88c4205b23e734893d8db6deccce88344c
123 lines
3.1 KiB
JavaScript
123 lines
3.1 KiB
JavaScript
/**
|
|
* 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;
|
|
|
|
return (
|
|
<View style={styles.frameContainer}>
|
|
<LogBoxButton
|
|
backgroundColor={{
|
|
default: 'transparent',
|
|
pressed: LogBoxStyle.getBackgroundColor(1),
|
|
}}
|
|
onPress={onPress}
|
|
style={styles.frame}>
|
|
<Text style={[styles.name, frame.collapse === true && styles.dim]}>
|
|
{frame.methodName}
|
|
</Text>
|
|
|
|
<View style={styles.lineLocation}>
|
|
<Text
|
|
ellipsizeMode="middle"
|
|
numberOfLines={1}
|
|
style={[styles.location, frame.collapse === true && styles.dim]}>
|
|
{getFileName(frame)}
|
|
</Text>
|
|
{frame.lineNumber != null && (
|
|
<Text style={[styles.line, frame.collapse === true && styles.dim]}>
|
|
:{frame.lineNumber}
|
|
</Text>
|
|
)}
|
|
{frame.column != null && !isNaN(parseInt(frame.column, 10)) && (
|
|
<Text style={[styles.line, frame.collapse === true && styles.dim]}>
|
|
:{parseInt(frame.column, 10) + 1}
|
|
</Text>
|
|
)}
|
|
</View>
|
|
</LogBoxButton>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
function getFileName(frame: StackFrame): string {
|
|
const {file} = frame;
|
|
if (file == null) {
|
|
return '<unknown>';
|
|
}
|
|
const queryIndex = file.indexOf('?');
|
|
|
|
const path = queryIndex < 0 ? file : file.substr(0, queryIndex);
|
|
return path.substr(path.lastIndexOf('/') + 1);
|
|
}
|
|
|
|
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;
|