diff --git a/Libraries/LogBox/Data/LogBoxData.js b/Libraries/LogBox/Data/LogBoxData.js index 8ca3a15ac42..76b26839ec8 100644 --- a/Libraries/LogBox/Data/LogBoxData.js +++ b/Libraries/LogBox/Data/LogBoxData.js @@ -56,8 +56,14 @@ export type WarningInfo = {| export type WarningFilter = (format: string) => WarningInfo; +type AppInfo = $ReadOnly<{| + appVersion: string, + engine: string, +|}>; + const observers: Set<{observer: Observer}> = new Set(); const ignorePatterns: Set = new Set(); +let appInfo: ?() => AppInfo = null; let logs: LogBoxLogs = new Set(); let updateTimeout = null; let _isDisabled = false; @@ -295,6 +301,14 @@ export function setWarningFilter(filter: WarningFilter): void { warningFilter = filter; } +export function setAppInfo(info: () => AppInfo): void { + appInfo = info; +} + +export function getAppInfo(): ?AppInfo { + return appInfo != null ? appInfo() : null; +} + export function checkWarningFilter(format: string): WarningInfo { return warningFilter(format); } diff --git a/Libraries/LogBox/Data/__tests__/LogBoxData-test.js b/Libraries/LogBox/Data/__tests__/LogBoxData-test.js index 0315be0ff22..7982c4d0a3f 100644 --- a/Libraries/LogBox/Data/__tests__/LogBoxData-test.js +++ b/Libraries/LogBox/Data/__tests__/LogBoxData-test.js @@ -709,4 +709,18 @@ describe('LogBoxData', () => { expect(LogBoxData.isLogBoxErrorMessage(receivedErrorMessage)).toBe(true); expect(LogBoxData.isLogBoxErrorMessage('Some other error')).toBe(false); }); + + it('getAppInfo returns null without any function registered', () => { + expect(LogBoxData.getAppInfo()).toBe(null); + }); + + it('getAppInfo returns the registered app info', () => { + const info = { + appVersion: 'App Version', + engine: 'Hermes', + }; + + LogBoxData.setAppInfo(() => info); + expect(LogBoxData.getAppInfo()).toBe(info); + }); }); diff --git a/Libraries/LogBox/UI/LogBoxInspector.js b/Libraries/LogBox/UI/LogBoxInspector.js index 817b3031fb4..d9c3154f530 100644 --- a/Libraries/LogBox/UI/LogBoxInspector.js +++ b/Libraries/LogBox/UI/LogBoxInspector.js @@ -22,7 +22,6 @@ import LogBoxInspectorFooter from './LogBoxInspectorFooter'; import LogBoxInspectorMessageHeader from './LogBoxInspectorMessageHeader'; import LogBoxInspectorReactFrames from './LogBoxInspectorReactFrames'; import LogBoxInspectorStackFrames from './LogBoxInspectorStackFrames'; -import LogBoxInspectorMeta from './LogBoxInspectorMeta'; import LogBoxInspectorHeader from './LogBoxInspectorHeader'; import * as LogBoxStyle from './LogBoxStyle'; @@ -122,7 +121,6 @@ function LogBoxInspectorBody(props) { - ); @@ -139,7 +137,6 @@ function LogBoxInspectorBody(props) { - ); } diff --git a/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.js b/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.js index f97efedf07b..4fea3005cd6 100644 --- a/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.js +++ b/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.js @@ -21,6 +21,7 @@ import LogBoxButton from './LogBoxButton'; import openFileInEditor from '../../Core/Devtools/openFileInEditor'; import stripAnsi from 'strip-ansi'; import LogBoxInspectorSection from './LogBoxInspectorSection'; +import * as LogBoxData from '../Data/LogBoxData'; type Props = $ReadOnly<{| codeFrame: ?CodeFrame, |}>; @@ -41,7 +42,7 @@ function LogBoxInspectorCodeFrame(props: Props): React.Node { } return ( - + }> @@ -69,6 +70,29 @@ function LogBoxInspectorCodeFrame(props: Props): React.Node { ); } +function AppInfo() { + const appInfo = LogBoxData.getAppInfo(); + if (appInfo == null) { + return null; + } + + return ( + + {appInfo.appVersion} ({appInfo.engine}) + + ); +} + +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(), diff --git a/Libraries/LogBox/UI/LogBoxInspectorMeta.js b/Libraries/LogBox/UI/LogBoxInspectorMeta.js deleted file mode 100644 index 6c813639554..00000000000 --- a/Libraries/LogBox/UI/LogBoxInspectorMeta.js +++ /dev/null @@ -1,70 +0,0 @@ -/** - * 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 * as LogBoxStyle from './LogBoxStyle'; -import LogBoxInspectorSection from './LogBoxInspectorSection'; -type Props = $ReadOnly<{||}>; - -function LogBoxInspectorMeta(props: Props): React.Node { - return ( - - - - Platform - Engine - - - {/* TODO: Determine engine correctly */} - - {Platform.OS === 'android' ? 'Android' : 'iOS'} - - - {global.HermesInternal ? 'Hermes' : 'Unknown'} - - - - - ); -} - -const metaStyles = StyleSheet.create({ - body: { - paddingLeft: 25, - paddingRight: 25, - paddingBottom: 20, - flexDirection: 'row', - justifyContent: 'space-between', - }, - bodyItem: { - flex: 0, - }, - bodyText: { - color: LogBoxStyle.getTextColor(0.5), - fontSize: 14, - paddingTop: 3, - paddingBottom: 3, - includeFontPadding: false, - lineHeight: 20, - flex: 0, - flexGrow: 0, - }, - bodyTextRight: { - textAlign: 'right', - }, -}); - -export default LogBoxInspectorMeta; diff --git a/Libraries/LogBox/UI/__tests__/LogBoxInspectorMeta-test.js b/Libraries/LogBox/UI/__tests__/LogBoxInspectorMeta-test.js deleted file mode 100644 index 53b171731f3..00000000000 --- a/Libraries/LogBox/UI/__tests__/LogBoxInspectorMeta-test.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * 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. - * - * @format - * @emails oncall+react_native - * @flow - */ - -'use strict'; - -const React = require('react'); -const LogBoxInspectorMeta = require('../LogBoxInspectorMeta').default; -const render = require('../../../../jest/renderer'); - -describe('LogBoxInspectorMeta', () => { - it('should render meta information', () => { - const output = render.shallowRender(); - - expect(output).toMatchSnapshot(); - }); -}); diff --git a/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorCodeFrame-test.js.snap b/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorCodeFrame-test.js.snap index 0723af2d12e..2ea8a941100 100644 --- a/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorCodeFrame-test.js.snap +++ b/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorCodeFrame-test.js.snap @@ -2,6 +2,7 @@ exports[`LogBoxInspectorCodeFrame should render a code frame 1`] = ` } heading="Source" > - - - - Platform - - - Engine - - - - - iOS - - - Unknown - - - - -`;