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');
|
|
|
|
var PropTypes = require('ReactPropTypes');
|
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');
|
2015-06-03 20:55:52 +00:00
|
|
|
|
|
|
|
var ElementProperties = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
hierarchy: PropTypes.array.isRequired,
|
2015-07-22 23:36:46 +00:00
|
|
|
style: PropTypes.oneOfType([
|
|
|
|
PropTypes.object,
|
|
|
|
PropTypes.array,
|
|
|
|
PropTypes.number,
|
|
|
|
]),
|
2015-06-03 20:55:52 +00:00
|
|
|
},
|
2015-06-04 17:27:51 +00:00
|
|
|
|
2015-06-03 20:55:52 +00:00
|
|
|
render: function() {
|
|
|
|
var style = flattenStyle(this.props.style);
|
2015-06-04 17:27:51 +00:00
|
|
|
var selection = this.props.selection;
|
|
|
|
// 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
|
|
|
|
style={[styles.breadItem, i === selection && styles.selected]}
|
|
|
|
onPress={() => this.props.setSelection(i)}>
|
|
|
|
<Text style={styles.breadItemText}>
|
|
|
|
{item.getName ? item.getName() : 'Unknown'}
|
|
|
|
</Text>
|
|
|
|
</TouchableHighlight>
|
|
|
|
),
|
|
|
|
() => <Text style={styles.breadSep}>▸</Text>
|
|
|
|
)}
|
|
|
|
</View>
|
|
|
|
<View style={styles.row}>
|
|
|
|
<StyleInspector style={style} />
|
|
|
|
<BoxInspector style={style} frame={this.props.frame} />
|
|
|
|
</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
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
2015-06-04 17:27:51 +00:00
|
|
|
breadSep: {
|
|
|
|
fontSize: 8,
|
|
|
|
color: 'white',
|
|
|
|
},
|
|
|
|
breadcrumb: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
flexWrap: 'wrap',
|
|
|
|
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
|
|
|
},
|
|
|
|
info: {
|
|
|
|
padding: 10,
|
|
|
|
},
|
|
|
|
path: {
|
|
|
|
color: 'white',
|
|
|
|
fontSize: 9,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = ElementProperties;
|