2015-06-03 20:55:52 +00:00
|
|
|
/**
|
|
|
|
* 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 ElementProperties
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
[ReactNative] refactor the inspector
Summary:
The `InspectorOverlay` component was getting unwieldy, so I broke it into three components:
- Inspector
- InspectorOverlay
- InspectorPanel
and added @flow types.
The inspector was also living under the `ReactIOS` directory, and I moved it
up into the `Libraries` directory, as the inspector will soon be usable [on
Android](https://phabricator.fb.com/D2138319).
All features of the inspector should remain functional, with the addition of
one feature:
- you can toggle "touch to inspect" by tapping the "Inspect" button at the
bottom of the inspection panel. When inspection is disabled, the panel remains, but you can interact with
the app normally without touches being intercepted
@public
Test Plan:
Open the inspector:
- touch to inspect things, verify that margin, padding, size and position are
reported correctly, and that the component hierarchy is navigable.
- tap the "Inspect" button, and verify that you can interact with the app
normally.
{F22548949}
[Video of toggling inspection](https://www.latest.facebook.com/pxlcld/mrs9)
2015-06-11 20:50:48 +00:00
|
|
|
var BoxInspector = require('BoxInspector');
|
2015-06-03 20:55:52 +00:00
|
|
|
var React = require('React');
|
[ReactNative] refactor the inspector
Summary:
The `InspectorOverlay` component was getting unwieldy, so I broke it into three components:
- Inspector
- InspectorOverlay
- InspectorPanel
and added @flow types.
The inspector was also living under the `ReactIOS` directory, and I moved it
up into the `Libraries` directory, as the inspector will soon be usable [on
Android](https://phabricator.fb.com/D2138319).
All features of the inspector should remain functional, with the addition of
one feature:
- you can toggle "touch to inspect" by tapping the "Inspect" button at the
bottom of the inspection panel. When inspection is disabled, the panel remains, but you can interact with
the app normally without touches being intercepted
@public
Test Plan:
Open the inspector:
- touch to inspect things, verify that margin, padding, size and position are
reported correctly, and that the component hierarchy is navigable.
- tap the "Inspect" button, and verify that you can interact with the app
normally.
{F22548949}
[Video of toggling inspection](https://www.latest.facebook.com/pxlcld/mrs9)
2015-06-11 20:50:48 +00:00
|
|
|
var StyleInspector = require('StyleInspector');
|
2015-06-03 20:55:52 +00:00
|
|
|
var StyleSheet = require('StyleSheet');
|
|
|
|
var Text = require('Text');
|
2015-06-04 17:27:51 +00:00
|
|
|
var TouchableHighlight = require('TouchableHighlight');
|
|
|
|
var TouchableWithoutFeedback = require('TouchableWithoutFeedback');
|
[ReactNative] refactor the inspector
Summary:
The `InspectorOverlay` component was getting unwieldy, so I broke it into three components:
- Inspector
- InspectorOverlay
- InspectorPanel
and added @flow types.
The inspector was also living under the `ReactIOS` directory, and I moved it
up into the `Libraries` directory, as the inspector will soon be usable [on
Android](https://phabricator.fb.com/D2138319).
All features of the inspector should remain functional, with the addition of
one feature:
- you can toggle "touch to inspect" by tapping the "Inspect" button at the
bottom of the inspection panel. When inspection is disabled, the panel remains, but you can interact with
the app normally without touches being intercepted
@public
Test Plan:
Open the inspector:
- touch to inspect things, verify that margin, padding, size and position are
reported correctly, and that the component hierarchy is navigable.
- tap the "Inspect" button, and verify that you can interact with the app
normally.
{F22548949}
[Video of toggling inspection](https://www.latest.facebook.com/pxlcld/mrs9)
2015-06-11 20:50:48 +00:00
|
|
|
var View = require('View');
|
2015-06-03 20:55:52 +00:00
|
|
|
|
|
|
|
var flattenStyle = require('flattenStyle');
|
2015-06-04 17:27:51 +00:00
|
|
|
var mapWithSeparator = require('mapWithSeparator');
|
2016-07-13 11:34:52 +00:00
|
|
|
var openFileInEditor = require('openFileInEditor');
|
2015-06-03 20:55:52 +00:00
|
|
|
|
2016-10-15 01:50:17 +00:00
|
|
|
var PropTypes = React.PropTypes;
|
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
class ElementProperties extends React.Component {
|
|
|
|
props: {
|
|
|
|
hierarchy: Array<$FlowFixMe>,
|
|
|
|
style?: Object | Array<$FlowFixMe> | number,
|
|
|
|
source?: {
|
|
|
|
fileName?: string,
|
|
|
|
lineNumber?: number,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
2015-06-03 20:55:52 +00:00
|
|
|
hierarchy: PropTypes.array.isRequired,
|
2015-07-22 23:36:46 +00:00
|
|
|
style: PropTypes.oneOfType([
|
|
|
|
PropTypes.object,
|
|
|
|
PropTypes.array,
|
|
|
|
PropTypes.number,
|
|
|
|
]),
|
2016-05-18 03:55:28 +00:00
|
|
|
source: PropTypes.shape({
|
|
|
|
fileName: PropTypes.string,
|
|
|
|
lineNumber: PropTypes.number,
|
|
|
|
}),
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-06-04 17:27:51 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2015-06-03 20:55:52 +00:00
|
|
|
var style = flattenStyle(this.props.style);
|
2016-07-26 08:00:02 +00:00
|
|
|
// $FlowFixMe found when converting React.createClass to ES6
|
2015-06-04 17:27:51 +00:00
|
|
|
var selection = this.props.selection;
|
2016-05-18 03:55:28 +00:00
|
|
|
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}
|
2016-07-13 11:34:52 +00:00
|
|
|
onPress={openFileInEditor.bind(null, fileName, lineNumber)}>
|
2016-05-18 03:55:28 +00:00
|
|
|
<Text style={styles.openButtonTitle} numberOfLines={1}>
|
|
|
|
{fileNameShort}:{lineNumber}
|
|
|
|
</Text>
|
|
|
|
</TouchableHighlight>
|
|
|
|
);
|
|
|
|
}
|
2015-06-04 17:27:51 +00:00
|
|
|
// Without the `TouchableWithoutFeedback`, taps on this inspector pane
|
|
|
|
// would change the inspected element to whatever is under the inspector
|
2015-06-03 20:55:52 +00:00
|
|
|
return (
|
2015-06-04 17:27:51 +00:00
|
|
|
<TouchableWithoutFeedback>
|
|
|
|
<View style={styles.info}>
|
|
|
|
<View style={styles.breadcrumb}>
|
|
|
|
{mapWithSeparator(
|
|
|
|
this.props.hierarchy,
|
|
|
|
(item, i) => (
|
|
|
|
<TouchableHighlight
|
2016-01-26 02:36:10 +00:00
|
|
|
key={'item-' + i}
|
2015-06-04 17:27:51 +00:00
|
|
|
style={[styles.breadItem, i === selection && styles.selected]}
|
2016-07-26 08:00:02 +00:00
|
|
|
// $FlowFixMe found when converting React.createClass to ES6
|
2015-06-04 17:27:51 +00:00
|
|
|
onPress={() => this.props.setSelection(i)}>
|
|
|
|
<Text style={styles.breadItemText}>
|
2016-05-26 17:43:51 +00:00
|
|
|
{getInstanceName(item)}
|
2015-06-04 17:27:51 +00:00
|
|
|
</Text>
|
|
|
|
</TouchableHighlight>
|
|
|
|
),
|
2016-01-26 02:36:10 +00:00
|
|
|
(i) => (
|
|
|
|
<Text key={'sep-' + i} style={styles.breadSep}>
|
|
|
|
▸
|
|
|
|
</Text>
|
|
|
|
)
|
2015-06-04 17:27:51 +00:00
|
|
|
)}
|
|
|
|
</View>
|
|
|
|
<View style={styles.row}>
|
2016-05-18 03:55:28 +00:00
|
|
|
<View style={styles.col}>
|
|
|
|
<StyleInspector style={style} />
|
|
|
|
{openFileButton}
|
|
|
|
</View>
|
2016-07-26 08:00:02 +00:00
|
|
|
{
|
|
|
|
// $FlowFixMe found when converting React.createClass to ES6
|
|
|
|
<BoxInspector style={style} frame={this.props.frame} />}
|
2015-06-04 17:27:51 +00:00
|
|
|
</View>
|
2015-06-03 20:55:52 +00:00
|
|
|
</View>
|
2015-06-04 17:27:51 +00:00
|
|
|
</TouchableWithoutFeedback>
|
2015-06-03 20:55:52 +00:00
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-03 20:55:52 +00:00
|
|
|
|
2016-05-26 17:43:51 +00:00
|
|
|
function getInstanceName(instance) {
|
|
|
|
if (instance.getName) {
|
|
|
|
return instance.getName();
|
|
|
|
}
|
|
|
|
if (instance.constructor && instance.constructor.displayName) {
|
|
|
|
return instance.constructor.displayName;
|
|
|
|
}
|
|
|
|
return 'Unknown';
|
|
|
|
}
|
|
|
|
|
2015-06-03 20:55:52 +00:00
|
|
|
var styles = StyleSheet.create({
|
2015-06-04 17:27:51 +00:00
|
|
|
breadSep: {
|
|
|
|
fontSize: 8,
|
|
|
|
color: 'white',
|
|
|
|
},
|
|
|
|
breadcrumb: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
flexWrap: 'wrap',
|
2016-06-15 18:06:26 +00:00
|
|
|
alignItems: 'flex-start',
|
2015-06-04 17:27:51 +00:00
|
|
|
marginBottom: 5,
|
|
|
|
},
|
|
|
|
selected: {
|
|
|
|
borderColor: 'white',
|
|
|
|
borderRadius: 5,
|
|
|
|
},
|
|
|
|
breadItem: {
|
|
|
|
borderWidth: 1,
|
|
|
|
borderColor: 'transparent',
|
|
|
|
marginHorizontal: 2,
|
|
|
|
},
|
|
|
|
breadItemText: {
|
|
|
|
fontSize: 10,
|
|
|
|
color: 'white',
|
|
|
|
marginHorizontal: 5,
|
|
|
|
},
|
2015-06-03 20:55:52 +00:00
|
|
|
row: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
2015-06-04 17:27:51 +00:00
|
|
|
justifyContent: 'space-between',
|
2015-06-03 20:55:52 +00:00
|
|
|
},
|
2016-05-18 03:55:28 +00:00
|
|
|
col: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
2015-06-03 20:55:52 +00:00
|
|
|
info: {
|
|
|
|
padding: 10,
|
|
|
|
},
|
|
|
|
path: {
|
|
|
|
color: 'white',
|
|
|
|
fontSize: 9,
|
|
|
|
},
|
2016-05-18 03:55:28 +00:00
|
|
|
openButton: {
|
|
|
|
padding: 10,
|
|
|
|
backgroundColor: '#000',
|
|
|
|
marginVertical: 5,
|
|
|
|
marginRight: 5,
|
|
|
|
borderRadius: 2,
|
|
|
|
},
|
|
|
|
openButtonTitle: {
|
|
|
|
color: 'white',
|
|
|
|
fontSize: 8,
|
|
|
|
}
|
2015-06-03 20:55:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = ElementProperties;
|