mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
c24c8a039c
Summary: By depending on react-native, these files can't be flow strict until index.js is flow strict. By depending on the internals directly they can be flow strict as soon as their dependents are flow strict. Changelog: [Internal] Refactoring some core file imports to depend on internals directly Reviewed By: zackargyle Differential Revision: D18828324 fbshipit-source-id: 2a347c4e234a64edbb3e6f0ef6387ef1ce78badc
142 lines
3.5 KiB
JavaScript
142 lines
3.5 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
|
|
* @format
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import * as React from 'react';
|
|
import Platform from '../../Utilities/Platform';
|
|
import ScrollView from '../../Components/ScrollView/ScrollView';
|
|
import StyleSheet from '../../StyleSheet/StyleSheet';
|
|
import Text from '../../Text/Text';
|
|
import View from '../../Components/View/View';
|
|
import * as LogBoxStyle from './LogBoxStyle';
|
|
import type {CodeFrame} from '../Data/parseLogBoxLog';
|
|
import LogBoxButton from './LogBoxButton';
|
|
import openFileInEditor from '../../Core/Devtools/openFileInEditor';
|
|
import AnsiHighlight from './AnsiHighlight';
|
|
import LogBoxInspectorSection from './LogBoxInspectorSection';
|
|
import * as LogBoxData from '../Data/LogBoxData';
|
|
type Props = $ReadOnly<{|
|
|
codeFrame: ?CodeFrame,
|
|
|}>;
|
|
|
|
function LogBoxInspectorCodeFrame(props: Props): React.Node {
|
|
const codeFrame = props.codeFrame;
|
|
if (codeFrame == null) {
|
|
return null;
|
|
}
|
|
|
|
function getFileName() {
|
|
const matches = /[^/]*$/.exec(codeFrame.fileName);
|
|
if (matches && matches.length > 0) {
|
|
return matches[0];
|
|
}
|
|
|
|
return codeFrame.fileName;
|
|
}
|
|
|
|
function getLocation() {
|
|
const location = codeFrame.location;
|
|
if (location != null) {
|
|
return ` (${location.row}:${
|
|
location.column + 1 /* Code frame columns are zero indexed */
|
|
})`;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<LogBoxInspectorSection heading="Source" action={<AppInfo />}>
|
|
<View style={styles.box}>
|
|
<View style={styles.frame}>
|
|
<ScrollView horizontal>
|
|
<AnsiHighlight style={styles.content} text={codeFrame.content} />
|
|
</ScrollView>
|
|
</View>
|
|
<LogBoxButton
|
|
backgroundColor={{
|
|
default: 'transparent',
|
|
pressed: LogBoxStyle.getBackgroundDarkColor(1),
|
|
}}
|
|
style={styles.button}
|
|
onPress={() => {
|
|
openFileInEditor(codeFrame.fileName, codeFrame.location?.row ?? 0);
|
|
}}>
|
|
<Text style={styles.fileText}>
|
|
{getFileName()}
|
|
{getLocation()}
|
|
</Text>
|
|
</LogBoxButton>
|
|
</View>
|
|
</LogBoxInspectorSection>
|
|
);
|
|
}
|
|
|
|
function AppInfo() {
|
|
const appInfo = LogBoxData.getAppInfo();
|
|
if (appInfo == null) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<Text style={appInfoStyles.text}>
|
|
{appInfo.appVersion} ({appInfo.engine})
|
|
</Text>
|
|
);
|
|
}
|
|
|
|
const appInfoStyles = StyleSheet.create({
|
|
text: {
|
|
color: LogBoxStyle.getTextColor(0.4),
|
|
fontSize: 12,
|
|
lineHeight: 12,
|
|
flex: 0,
|
|
flexGrow: 0,
|
|
},
|
|
});
|
|
|
|
const styles = StyleSheet.create({
|
|
box: {
|
|
backgroundColor: LogBoxStyle.getBackgroundColor(),
|
|
marginLeft: 10,
|
|
marginRight: 10,
|
|
marginTop: 5,
|
|
borderRadius: 3,
|
|
},
|
|
frame: {
|
|
padding: 10,
|
|
borderBottomColor: LogBoxStyle.getTextColor(0.1),
|
|
borderBottomWidth: 1,
|
|
},
|
|
button: {
|
|
paddingTop: 10,
|
|
paddingBottom: 10,
|
|
},
|
|
content: {
|
|
color: LogBoxStyle.getTextColor(1),
|
|
fontSize: 12,
|
|
includeFontPadding: false,
|
|
lineHeight: 20,
|
|
fontFamily: Platform.select({android: 'monospace', ios: 'Menlo'}),
|
|
},
|
|
fileText: {
|
|
color: LogBoxStyle.getTextColor(0.5),
|
|
textAlign: 'center',
|
|
flex: 1,
|
|
fontSize: 12,
|
|
includeFontPadding: false,
|
|
lineHeight: 16,
|
|
fontFamily: Platform.select({android: 'monospace', ios: 'Menlo'}),
|
|
},
|
|
});
|
|
|
|
export default LogBoxInspectorCodeFrame;
|