UNPKG

reactotron-react-native

Version:

A development tool to explore, inspect, and diagnose your React Native apps.

152 lines (148 loc) 3.52 kB
"use strict"; import React, { Component } from "react"; import { Dimensions, View, Image, Text } from "react-native"; import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; const Styles = { container: { position: "absolute", left: 0, top: 0, right: 0, bottom: 0, zIndex: 1000, opacity: 0.25 }, debugContainer: { position: "absolute", top: 0, left: 0, right: 0, bottom: 0, justifyContent: "center", alignItems: "center", backgroundColor: "transparent", zIndex: 2000 }, debugTextContainer: { backgroundColor: "lightgray", margin: 50, padding: 20 }, debugText: { color: "red", fontSize: 16, marginBottom: 10 } }; /** An overlay for showing an image to help with layout. * * @class FullScreenOverlay * @extends {Component} */ class FullScreenOverlay extends Component { constructor(props) { super(props); this.state = { opacity: Styles.container.opacity, uri: null, justifyContent: "center", alignItems: "center" }; // when the server sends stuff props.emitter.on("overlay", payload => { this.setState({ ...this.state, ...payload }); }); } createContainerStyle() { const { opacity, justifyContent, alignItems } = this.state; const { width, height } = Dimensions.get("window"); const containerStyle = { ...Styles.container, opacity, width, height, justifyContent, alignItems }; return containerStyle; } renderDebug() { const { showDebug } = this.state; // If Reactotron is configured properly it should be disabled in production. // We'll throw a __DEV__ check in here just in case it get's feisty. if (!__DEV__ || !showDebug) return null; return /*#__PURE__*/_jsx(View, { style: Styles.debugContainer, pointerEvents: "none", children: /*#__PURE__*/_jsx(View, { style: Styles.debugTextContainer, children: Object.keys(this.state).map(key => { if (key === "showDebug") return null; const keyName = key === "uri" ? "have image" : key; const value = key === "uri" ? !!this.state[key] : this.state[key]; return /*#__PURE__*/_jsx(Text, { style: Styles.debugText, children: `${keyName}: ${value}` }, key); }) }) }); } /** * Draw. */ render() { const { uri, width, height, growToWindow, resizeMode, marginLeft = 0, marginRight = 0, marginTop = 0, marginBottom = 0 } = this.state; const imageStyle = { width, height, marginTop, marginRight, marginBottom, marginLeft }; if (growToWindow) { const windowSize = Dimensions.get("window"); imageStyle.width = windowSize.width; imageStyle.height = windowSize.height; } const image = uri ? /*#__PURE__*/_jsx(Image, { source: { uri }, style: imageStyle, resizeMode: growToWindow ? resizeMode : null }) : /*#__PURE__*/_jsx(View, {}); return /*#__PURE__*/_jsxs(_Fragment, { children: [/*#__PURE__*/_jsx(View, { style: this.createContainerStyle(), pointerEvents: "none", children: image }), this.renderDebug()] }); } } export default FullScreenOverlay; //# sourceMappingURL=overlay.js.map