BoxInspector.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. * @flow strict-local
  9. */
  10. 'use strict';
  11. const React = require('react');
  12. const StyleSheet = require('../StyleSheet/StyleSheet');
  13. const Text = require('../Text/Text');
  14. const View = require('../Components/View/View');
  15. const resolveBoxStyle = require('./resolveBoxStyle');
  16. const blank = {
  17. top: 0,
  18. left: 0,
  19. right: 0,
  20. bottom: 0,
  21. };
  22. class BoxInspector extends React.Component<$FlowFixMeProps> {
  23. render(): React.Node {
  24. const frame = this.props.frame;
  25. const style = this.props.style;
  26. const margin = (style && resolveBoxStyle('margin', style)) || blank;
  27. const padding = (style && resolveBoxStyle('padding', style)) || blank;
  28. return (
  29. <BoxContainer title="margin" titleStyle={styles.marginLabel} box={margin}>
  30. <BoxContainer title="padding" box={padding}>
  31. <View>
  32. <Text style={styles.innerText}>
  33. ({(frame.left || 0).toFixed(1)}, {(frame.top || 0).toFixed(1)})
  34. </Text>
  35. <Text style={styles.innerText}>
  36. {(frame.width || 0).toFixed(1)} &times;{' '}
  37. {(frame.height || 0).toFixed(1)}
  38. </Text>
  39. </View>
  40. </BoxContainer>
  41. </BoxContainer>
  42. );
  43. }
  44. }
  45. class BoxContainer extends React.Component<$FlowFixMeProps> {
  46. render() {
  47. const box = this.props.box;
  48. return (
  49. <View style={styles.box}>
  50. <View style={styles.row}>
  51. {}
  52. <Text style={[this.props.titleStyle, styles.label]}>
  53. {this.props.title}
  54. </Text>
  55. <Text style={styles.boxText}>{box.top}</Text>
  56. </View>
  57. <View style={styles.row}>
  58. <Text style={styles.boxText}>{box.left}</Text>
  59. {this.props.children}
  60. <Text style={styles.boxText}>{box.right}</Text>
  61. </View>
  62. <Text style={styles.boxText}>{box.bottom}</Text>
  63. </View>
  64. );
  65. }
  66. }
  67. const styles = StyleSheet.create({
  68. row: {
  69. flexDirection: 'row',
  70. alignItems: 'center',
  71. justifyContent: 'space-around',
  72. },
  73. marginLabel: {
  74. width: 60,
  75. },
  76. label: {
  77. fontSize: 10,
  78. color: 'rgb(255,100,0)',
  79. marginLeft: 5,
  80. flex: 1,
  81. textAlign: 'left',
  82. top: -3,
  83. },
  84. innerText: {
  85. color: 'yellow',
  86. fontSize: 12,
  87. textAlign: 'center',
  88. width: 70,
  89. },
  90. box: {
  91. borderWidth: 1,
  92. borderColor: 'grey',
  93. },
  94. boxText: {
  95. color: 'white',
  96. fontSize: 12,
  97. marginHorizontal: 3,
  98. marginVertical: 2,
  99. textAlign: 'center',
  100. },
  101. });
  102. module.exports = BoxInspector;