App.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import React from 'react';
  2. import { StyleSheet, Text, TextInput, View } from 'react-native';
  3. import GUI from './Systems/Gui';
  4. import './App.css';
  5. export default class App extends React.Component {
  6. constructor(props){
  7. super(props)
  8. this.playgroundRef = React.createRef();
  9. this.toolboxRef = React.createRef();
  10. this.GUI = null;
  11. this.state = {
  12. zoom:1,
  13. scrollPos:0
  14. }
  15. this.addScrollEvent();
  16. this.GUI = new GUI();
  17. this.GUI.onUpdate( () => this.forceUpdate())
  18. }
  19. componentDidMount(){
  20. this.GUI = new GUI(this.playgroundRef.current,this.toolboxRef.current);
  21. this.GUI.onUpdate( () => this.forceUpdate())
  22. }
  23. addScrollEvent(){
  24. window.addEventListener('wheel', (e) =>{
  25. if(e.deltaY < 0){
  26. this.zoomIn();
  27. }
  28. else if(e.deltaY > 0){
  29. this.zoomOut();
  30. }
  31. });
  32. }
  33. zoomOut(){
  34. let z = this.state.zoom;
  35. z = z + 0.2;
  36. this.setState({zoom:z});
  37. }
  38. zoomIn(){
  39. let z = this.state.zoom;
  40. z = z - 0.2;
  41. this.setState({zoom:z});
  42. }
  43. dragPage(e){
  44. //!!!!!Import document.getElementById isnt working on react native
  45. //' let playground = document.getElementById("phone");
  46. /*playground.addEventListener("mousedown",() => {
  47. console.log("mouse down")
  48. playground.onmousemove = function(e){
  49. console.log("moving now while down")
  50. }
  51. })*/
  52. }
  53. render(){
  54. console.log("re render")
  55. let customStyle = {
  56. zoom: this.state.zoom
  57. };
  58. return (
  59. <div className="main" id="some">
  60. <div className="mainbar">
  61. {this.GUI.renderMainBar()}
  62. </div>
  63. <div className="horizontal_bars">
  64. <div ref={this.toolboxRef} className="toolbox">
  65. <div className="tool_icon_bar">{this.GUI.renderToolBox()}</div>
  66. <div className="moduleBar">{this.GUI.renderModuleBar()}</div>
  67. </div>
  68. <div className="sidebar">
  69. {this.GUI.renderSideBar()}
  70. </div>
  71. </div>
  72. {/*This is a comment*/}
  73. <div ref={this.playgroundRef} onClick={(e) => this.dragPage(e)} className="playground" style={{zoom:this.state.zoom}}>
  74. <div className="phone">
  75. {this.GUI.mobileRender()}
  76. </div>
  77. </div>
  78. </div>
  79. );
  80. }
  81. }
  82. /*
  83. const styles = StyleSheet.create({
  84. container: {
  85. flex: 1,
  86. backgroundColor: '#fff',
  87. alignItems: 'center',
  88. justifyContent: 'space-between',
  89. flexDirection: 'row'
  90. },
  91. toolbarView: {
  92. justifyContent: 'space-around',
  93. alignItems: 'center',
  94. width: 64,
  95. borderWidth: 1,
  96. borderColor: 'red',
  97. padding: 16
  98. },
  99. mainView: {
  100. backgroundColor: '#065b69',
  101. alignSelf:'stretch',
  102. flex: 1,
  103. justifyContent: 'center',
  104. alignItems: 'center'
  105. },
  106. mobileView: {
  107. backgroundColor: 'white',
  108. borderWidth: 4,
  109. borderColor: 'orange',
  110. // iphone X
  111. width:1125/3,
  112. height: 2436/3
  113. },
  114. });*/