LogBoxInspectorContainer.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @flow
  8. * @format
  9. */
  10. 'use strict';
  11. import * as React from 'react';
  12. import {View, StyleSheet} from 'react-native';
  13. import * as LogBoxData from './Data/LogBoxData';
  14. import LogBoxInspector from './UI/LogBoxInspector';
  15. import type LogBoxLog from './Data/LogBoxLog';
  16. type Props = $ReadOnly<{|
  17. logs: $ReadOnlyArray<LogBoxLog>,
  18. selectedLogIndex: number,
  19. isDisabled?: ?boolean,
  20. |}>;
  21. export class _LogBoxInspectorContainer extends React.Component<Props> {
  22. render(): React.Node {
  23. return (
  24. <View style={StyleSheet.absoluteFill}>
  25. <LogBoxInspector
  26. onDismiss={this._handleDismiss}
  27. onMinimize={this._handleMinimize}
  28. onChangeSelectedIndex={this._handleSetSelectedLog}
  29. logs={this.props.logs}
  30. selectedIndex={this.props.selectedLogIndex}
  31. />
  32. </View>
  33. );
  34. }
  35. _handleDismiss = (): void => {
  36. // Here we handle the cases when the log is dismissed and it
  37. // was either the last log, or when the current index
  38. // is now outside the bounds of the log array.
  39. const {selectedLogIndex, logs} = this.props;
  40. const logsArray = Array.from(logs);
  41. if (selectedLogIndex != null) {
  42. if (logsArray.length - 1 <= 0) {
  43. LogBoxData.setSelectedLog(-1);
  44. } else if (selectedLogIndex >= logsArray.length - 1) {
  45. LogBoxData.setSelectedLog(selectedLogIndex - 1);
  46. }
  47. LogBoxData.dismiss(logsArray[selectedLogIndex]);
  48. }
  49. };
  50. _handleMinimize = (): void => {
  51. LogBoxData.setSelectedLog(-1);
  52. };
  53. _handleSetSelectedLog = (index: number): void => {
  54. LogBoxData.setSelectedLog(index);
  55. };
  56. }
  57. export default (LogBoxData.withSubscription(
  58. _LogBoxInspectorContainer,
  59. ): React.AbstractComponent<{||}>);