Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions Libraries/Inspector/ElementProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ var Text = require('Text');
var TouchableHighlight = require('TouchableHighlight');
var TouchableWithoutFeedback = require('TouchableWithoutFeedback');
var View = require('View');
var {SourceCode} = require('NativeModules');
var {fetch} = require('fetch');

var flattenStyle = require('flattenStyle');
var mapWithSeparator = require('mapWithSeparator');
Expand All @@ -32,11 +34,31 @@ var ElementProperties = React.createClass({
PropTypes.array,
PropTypes.number,
]),
source: PropTypes.shape({
fileName: PropTypes.string,
lineNumber: PropTypes.number,
}),
},

render: function() {
var style = flattenStyle(this.props.style);
var selection = this.props.selection;
var openFileButton;
var source = this.props.source;
var {fileName, lineNumber} = source || {};
if (fileName && lineNumber) {
var parts = fileName.split('/');
var fileNameShort = parts[parts.length - 1];
openFileButton = (
<TouchableHighlight
style={styles.openButton}
onPress={this._openFile.bind(null, fileName, lineNumber)}>
<Text style={styles.openButtonTitle} numberOfLines={1}>
{fileNameShort}:{lineNumber}
</Text>
</TouchableHighlight>
);
}
// Without the `TouchableWithoutFeedback`, taps on this inspector pane
// would change the inspected element to whatever is under the inspector
return (
Expand All @@ -63,13 +85,26 @@ var ElementProperties = React.createClass({
)}
</View>
<View style={styles.row}>
<StyleInspector style={style} />
<View style={styles.col}>
<StyleInspector style={style} />
{openFileButton}
</View>
<BoxInspector style={style} frame={this.props.frame} />
</View>
</View>
</TouchableWithoutFeedback>
);
}
},

_openFile: function(fileName: string, lineNumber: number) {
var match = SourceCode.scriptURL && SourceCode.scriptURL.match(/^https?:\/\/.*?\//);
var baseURL = match ? match[0] : 'http://localhost:8081/';

fetch(baseURL + 'open-stack-frame', {
method: 'POST',
body: JSON.stringify({file: fileName, lineNumber}),
});
},
});

var styles = StyleSheet.create({
Expand Down Expand Up @@ -101,13 +136,27 @@ var styles = StyleSheet.create({
alignItems: 'center',
justifyContent: 'space-between',
},
col: {
flex: 1,
},
info: {
padding: 10,
},
path: {
color: 'white',
fontSize: 9,
},
openButton: {
padding: 10,
backgroundColor: '#000',
marginVertical: 5,
marginRight: 5,
borderRadius: 2,
},
openButtonTitle: {
color: 'white',
fontSize: 8,
}
});

module.exports = ElementProperties;
4 changes: 4 additions & 0 deletions Libraries/Inspector/Inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,13 @@ class Inspector extends React.Component {
// if we inspect a stateless component we can't use the getPublicInstance method
// therefore we use the internal _instance property directly.
var publicInstance = instance['_instance'] || {};
var source = instance._currentElement && instance._currentElement._source;
UIManager.measure(instance.getNativeNode(), (x, y, width, height, left, top) => {
this.setState({
inspected: {
frame: {left, top, width, height},
style: publicInstance.props ? publicInstance.props.style : {},
source,
},
selection: i,
});
Expand All @@ -149,13 +151,15 @@ class Inspector extends React.Component {
// therefore we use the internal _instance property directly.
var publicInstance = instance._instance || {};
var props = publicInstance.props || {};
var source = instance._currentElement && instance._currentElement._source;
this.setState({
panelPos: pointerY > Dimensions.get('window').height / 2 ? 'top' : 'bottom',
selection: hierarchy.length - 1,
hierarchy,
inspected: {
style: props.style || {},
frame,
source,
},
});
}
Expand Down
1 change: 1 addition & 0 deletions Libraries/Inspector/InspectorPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class InspectorPanel extends React.Component {
<ElementProperties
style={this.props.inspected.style}
frame={this.props.inspected.frame}
source={this.props.inspected.source}
hierarchy={this.props.hierarchy}
selection={this.props.selection}
setSelection={this.props.setSelection}
Expand Down