-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LogBox - Update to use it's own root for the inspector
Summary: Apologies for the large diff, it was difficult to break down. This diff is a major refactor of LogBox that: - Separates LogBoxNotification and LogBoxInspector - Moves them each to their own container - Updates AppContainer to only render the notification - Updates the native logbox root to render the inspector - Adds withSubscription HOC to manage subscribing to LogBoxData - Simplifies LogBox to export an object instead of a component Changelog: [Internal] Reviewed By: motiz88 Differential Revision: D18750011 fbshipit-source-id: 639885d29e55e125892d1c2b6bbf2826f27d78db
- Loading branch information
1 parent
e272089
commit 5879795
Showing
19 changed files
with
613 additions
and
557 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* 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 {View, StyleSheet} from 'react-native'; | ||
import * as LogBoxData from './Data/LogBoxData'; | ||
import LogBoxInspector from './UI/LogBoxInspector'; | ||
import type LogBoxLog from './Data/LogBoxLog'; | ||
import NativeLogBox from '../NativeModules/specs/NativeLogBox'; | ||
|
||
type Props = $ReadOnly<{| | ||
logs: $ReadOnlyArray<LogBoxLog>, | ||
selectedLogIndex: number, | ||
isDisabled?: ?boolean, | ||
|}>; | ||
|
||
function NativeLogBoxVisibility(props) { | ||
React.useLayoutEffect(() => { | ||
if (NativeLogBox) { | ||
if (props.visible) { | ||
// Schedule this to try and prevent flashing the old state. | ||
setTimeout(() => NativeLogBox.show(), 10); | ||
} else { | ||
NativeLogBox.hide(); | ||
} | ||
} | ||
}, [props.visible]); | ||
|
||
return props.children; | ||
} | ||
|
||
export class _LogBoxInspectorContainer extends React.Component<Props> { | ||
render(): React.Node { | ||
return ( | ||
<NativeLogBoxVisibility visible={this.props.selectedLogIndex >= 0}> | ||
<View style={StyleSheet.absoluteFill}> | ||
<LogBoxInspector | ||
onDismiss={this._handleDismiss} | ||
onMinimize={this._handleMinimize} | ||
onChangeSelectedIndex={this._handleSetSelectedLog} | ||
logs={this.props.logs} | ||
selectedIndex={this.props.selectedLogIndex} | ||
/> | ||
</View> | ||
</NativeLogBoxVisibility> | ||
); | ||
} | ||
|
||
_handleDismiss = (): void => { | ||
// Here we handle the cases when the log is dismissed and it | ||
// was either the last log, or when the current index | ||
// is now outside the bounds of the log array. | ||
const {selectedLogIndex, logs} = this.props; | ||
const logsArray = Array.from(logs); | ||
if (selectedLogIndex != null) { | ||
if (logsArray.length - 1 <= 0) { | ||
LogBoxData.setSelectedLog(-1); | ||
} else if (selectedLogIndex >= logsArray.length - 1) { | ||
LogBoxData.setSelectedLog(selectedLogIndex - 1); | ||
} | ||
|
||
LogBoxData.dismiss(logsArray[selectedLogIndex]); | ||
} | ||
}; | ||
|
||
_handleMinimize = (): void => { | ||
LogBoxData.setSelectedLog(-1); | ||
}; | ||
|
||
_handleSetSelectedLog = (index: number): void => { | ||
LogBoxData.setSelectedLog(index); | ||
}; | ||
} | ||
|
||
export default (LogBoxData.withSubscription( | ||
_LogBoxInspectorContainer, | ||
): React.AbstractComponent<{||}>); |
Oops, something went wrong.