react-native-xenon
Version:
A powerful in-app debugging tool for React Native.
77 lines (76 loc) • 2.99 kB
JavaScript
;
import { useContext } from 'react';
import { MainContext } from "../../../contexts/index.js";
import refs, { DebuggerVisibility, PanelState } from "../../../core/refs.js";
import { formatCount } from "../../../core/utils.js";
import icons from "../../../theme/icons.js";
import Divider from "../common/Divider.js";
import DebuggerHeaderItem from "../items/DebuggerHeaderItem.js";
import HeaderComponents from "./HeaderComponents.js";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export default function DebuggerHeader({
selectedPanel,
setSelectedPanel,
style,
ref
}) {
const {
setDebuggerState,
networkInterceptor,
consoleInterceptor
} = useContext(MainContext);
const switchTo = panelState => {
refs.panel.current?.setCurrentIndex(panelState);
setSelectedPanel(panelState);
setDebuggerState(draft => {
draft.detailsData = null;
});
};
const toggleNetworkInterception = () => {
networkInterceptor.isInterceptorEnabled ? networkInterceptor.disableInterception() : networkInterceptor.enableInterception();
};
const toggleConsoleInterception = () => {
consoleInterceptor.isInterceptorEnabled ? consoleInterceptor.disableInterception() : consoleInterceptor.enableInterception();
};
const onShowSearchInput = () => {
refs.debugger.current?.setCurrentIndex(DebuggerVisibility.Search);
refs.searchInput.current?.focus();
};
return /*#__PURE__*/_jsxs(HeaderComponents.Wrapper, {
ref: ref,
style: style,
children: [/*#__PURE__*/_jsx(DebuggerHeaderItem, {
onPress: onShowSearchInput,
content: icons.search
}), /*#__PURE__*/_jsx(HeaderComponents.MainButtons, {}), /*#__PURE__*/_jsx(Divider, {
type: "vertical"
}), /*#__PURE__*/_jsx(DebuggerHeaderItem, {
isLabel: true,
isActive: selectedPanel === PanelState.Network,
content: `Network (${formatCount(networkInterceptor.networkRequests.size)})`,
onPress: () => switchTo(PanelState.Network)
}), /*#__PURE__*/_jsx(DebuggerHeaderItem, {
onPress: toggleNetworkInterception,
isActive: networkInterceptor.isInterceptorEnabled,
content: icons.record
}), /*#__PURE__*/_jsx(DebuggerHeaderItem, {
onPress: networkInterceptor.clearAllNetworkRequests,
content: icons.delete
}), /*#__PURE__*/_jsx(Divider, {
type: "vertical"
}), /*#__PURE__*/_jsx(DebuggerHeaderItem, {
isLabel: true,
isActive: selectedPanel === PanelState.Console,
content: `Console (${formatCount(consoleInterceptor.logMessages.length)})`,
onPress: () => switchTo(PanelState.Console)
}), /*#__PURE__*/_jsx(DebuggerHeaderItem, {
onPress: toggleConsoleInterception,
isActive: consoleInterceptor.isInterceptorEnabled,
content: icons.record
}), /*#__PURE__*/_jsx(DebuggerHeaderItem, {
onPress: consoleInterceptor.clearAllLogMessages,
content: icons.delete
})]
});
}
//# sourceMappingURL=DebuggerHeader.js.map