diff --git a/Libraries/ReactIOS/InspectorOverlay/BorderBox.js b/Libraries/Inspector/BorderBox.js similarity index 100% rename from Libraries/ReactIOS/InspectorOverlay/BorderBox.js rename to Libraries/Inspector/BorderBox.js diff --git a/Libraries/ReactIOS/InspectorOverlay/BoxInspector.js b/Libraries/Inspector/BoxInspector.js similarity index 100% rename from Libraries/ReactIOS/InspectorOverlay/BoxInspector.js rename to Libraries/Inspector/BoxInspector.js diff --git a/Libraries/ReactIOS/InspectorOverlay/ElementBox.js b/Libraries/Inspector/ElementBox.js similarity index 100% rename from Libraries/ReactIOS/InspectorOverlay/ElementBox.js rename to Libraries/Inspector/ElementBox.js diff --git a/Libraries/ReactIOS/InspectorOverlay/ElementProperties.js b/Libraries/Inspector/ElementProperties.js similarity index 98% rename from Libraries/ReactIOS/InspectorOverlay/ElementProperties.js rename to Libraries/Inspector/ElementProperties.js index 310374fb1..855423845 100644 --- a/Libraries/ReactIOS/InspectorOverlay/ElementProperties.js +++ b/Libraries/Inspector/ElementProperties.js @@ -11,15 +11,15 @@ */ 'use strict'; +var BoxInspector = require('BoxInspector'); +var PropTypes = require('ReactPropTypes'); var React = require('React'); +var StyleInspector = require('StyleInspector'); var StyleSheet = require('StyleSheet'); var Text = require('Text'); -var View = require('View'); -var PropTypes = require('ReactPropTypes'); -var BoxInspector = require('BoxInspector'); -var StyleInspector = require('StyleInspector'); var TouchableHighlight = require('TouchableHighlight'); var TouchableWithoutFeedback = require('TouchableWithoutFeedback'); +var View = require('View'); var flattenStyle = require('flattenStyle'); var mapWithSeparator = require('mapWithSeparator'); @@ -93,7 +93,6 @@ var styles = StyleSheet.create({ justifyContent: 'space-between', }, info: { - backgroundColor: 'rgba(0, 0, 0, 0.7)', padding: 10, }, path: { diff --git a/Libraries/Inspector/Inspector.js b/Libraries/Inspector/Inspector.js new file mode 100644 index 000000000..46615d967 --- /dev/null +++ b/Libraries/Inspector/Inspector.js @@ -0,0 +1,115 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @providesModule Inspector + * @flow + */ +'use strict'; + +var Dimensions = require('Dimensions'); +var InspectorOverlay = require('InspectorOverlay'); +var InspectorPanel = require('InspectorPanel'); +var InspectorUtils = require('InspectorUtils'); +var React = require('React'); +var StyleSheet = require('StyleSheet'); +var UIManager = require('NativeModules').UIManager; +var View = require('View'); + +class Inspector extends React.Component { + constructor(props: Object) { + super(props); + this.state = { + panelPos: 'bottom', + inspecting: true, + inspected: null, + }; + } + + setSelection(i: number) { + var instance = this.state.hierarchy[i]; + var publicInstance = instance.getPublicInstance(); + UIManager.measure(React.findNodeHandle(instance), (x, y, width, height, left, top) => { + this.setState({ + inspected: { + frame: {left, top, width, height}, + style: publicInstance.props ? publicInstance.props.style : {}, + }, + selection: i, + }); + }); + } + + onTouchInstance(instance: Object, frame: Object, pointerY: number) { + var hierarchy = InspectorUtils.getOwnerHierarchy(instance); + var publicInstance = instance.getPublicInstance(); + var props = publicInstance.props || {}; + this.setState({ + panelPos: pointerY > Dimensions.get('window').height / 2 ? 'top' : 'bottom', + selection: hierarchy.length - 1, + hierarchy, + inspected: { + style: props.style || {}, + frame, + }, + }); + } + + setInspecting(val: bool) { + this.setState({ + inspecting: val, + }); + } + + render() { + var panelPosition; + if (this.state.panelPos === 'bottom') { + panelPosition = {bottom: -Dimensions.get('window').height}; + } else { + panelPosition = {top: 0}; + } + return ( + + {this.state.inspecting && + } + + + + + ); + } +} + +var styles = StyleSheet.create({ + container: { + position: 'absolute', + backgroundColor: 'transparent', + top: 0, + left: 0, + right: 0, + height: 0, + }, + panelContainer: { + position: 'absolute', + left: 0, + right: 0, + }, +}); + +module.exports = Inspector; diff --git a/Libraries/Inspector/InspectorOverlay.js b/Libraries/Inspector/InspectorOverlay.js new file mode 100644 index 000000000..cf9dd8d68 --- /dev/null +++ b/Libraries/Inspector/InspectorOverlay.js @@ -0,0 +1,81 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @providesModule InspectorOverlay + * @flow + */ +'use strict'; + +var Dimensions = require('Dimensions'); +var InspectorUtils = require('InspectorUtils'); +var React = require('React'); +var StyleSheet = require('StyleSheet'); +var UIManager = require('NativeModules').UIManager; +var View = require('View'); +var ElementBox = require('ElementBox'); + +var PropTypes = React.PropTypes; + +type EventLike = { + nativeEvent: Object; +}; + +var InspectorOverlay = React.createClass({ + propTypes: { + inspectedViewTag: PropTypes.object, + onTouchInstance: PropTypes.func.isRequired, + }, + + findViewForTouchEvent: function(e: EventLike) { + var {locationX, locationY} = e.nativeEvent.touches[0]; + UIManager.findSubviewIn( + this.props.inspectedViewTag, + [locationX, locationY], + (nativeViewTag, left, top, width, height) => { + var instance = InspectorUtils.findInstanceByNativeTag(this.props.rootTag, nativeViewTag); + if (!instance) { + return; + } + this.props.onTouchInstance(instance, {left, top, width, height}, locationY); + } + ); + }, + + shouldSetResponser: function(e: EventLike): bool { + this.findViewForTouchEvent(e); + return true; + }, + + render: function() { + var content = null; + if (this.props.inspected) { + content = ; + } + + return ( + + {content} + + ); + } +}); + +var styles = StyleSheet.create({ + inspector: { + backgroundColor: 'transparent', + position: 'absolute', + left: 0, + top: 0, + right: 0, + }, +}); + +module.exports = InspectorOverlay; diff --git a/Libraries/Inspector/InspectorPanel.js b/Libraries/Inspector/InspectorPanel.js new file mode 100644 index 000000000..7f49f19dc --- /dev/null +++ b/Libraries/Inspector/InspectorPanel.js @@ -0,0 +1,119 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @providesModule InspectorPanel + * @flow + */ +'use strict'; + +var React = require('React'); +var StyleSheet = require('StyleSheet'); +var Text = require('Text'); +var View = require('View'); +var ElementProperties = require('ElementProperties'); +var TouchableHighlight = require('TouchableHighlight'); + +var PropTypes = React.PropTypes; + +class InspectorPanel extends React.Component { + renderWaiting() { + if (this.props.inspecting) { + return ( + + Tap something to inspect it + + ); + } + return Nothing is inspected; + } + + render() { + var contents; + if (this.props.inspected) { + contents = ( + + ); + } else { + contents = ( + + {this.renderWaiting()} + + ); + } + return ( + + {contents} + +