3
0

App.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import React , { useState } from 'react';
  2. import { StyleSheet, Text, View as Div, TextInput, Button } from 'react-native';
  3. import RoutingSystem from './lib/systems/RoutingSystem.js';
  4. import ViewSystem, { View, Node, ViewNode, RowNode, ColNode } from './lib/systems/ViewSystem.js';
  5. import CoreSystem from './lib/systems/CoreSystem.js';
  6. /*********** Custom View Tree ****/
  7. import { Tree } from './lib/helpers/tree';
  8. import FormComp from './modules/Form';
  9. import TextComp from './modules/Text';
  10. import RootComp from './modules/RootComp';
  11. import ImageComp from './modules/Image';
  12. import ButtonComp from './modules/Button';
  13. const CustomStyle = StyleSheet.create({
  14. container:{
  15. flex:1,
  16. backgroundColor:'red'
  17. },
  18. text:{
  19. color:'blue'
  20. }
  21. })
  22. const RootStyle = StyleSheet.create({
  23. container:{
  24. flex:1,
  25. backgroundColor:'blue'
  26. },
  27. text:{
  28. color:'black'
  29. }
  30. })
  31. let RootNode = new ViewNode("A","RootComp",{text:"This is the asd asd asd asd asd asd sda asdaasdasd asd asdasd asd asd dasasdasd asd adsasd asd asd asdasd asd asd asd asd asd asd asd asd sda asdaasdasd asd asdasd asd asd dasasdasd asd adsasd asd asd asdasd asd asd asd asd asd asd asd asd sda asdaasdasd asd asdasd asd asd dasasdasd asd adsasd asd asd asdasd asd asd asd asd asd asd asd asd sda asdStarting point!!!Try add on me ",style:RootStyle});
  32. let TestNode = new ViewNode("H","Text",{style:CustomStyle,text:"Edited Text Node Will be here"})
  33. let ImageNode = new ViewNode("asdasd","Image");
  34. // let Row1 = new RowNode("RootRow");
  35. // let Col11 = new ColNode("Col11");
  36. // let Col12 = new ColNode("Col12");
  37. // let Row2 = new RowNode("RootRow2");
  38. // let Col21 = new ColNode("Col21");
  39. // let Col22 = new ColNode("Col22");
  40. // Col21.content = RootNode;
  41. // Col12.content = TestNode;
  42. let nodeA = new Node("A", {justifyContent: 'flex-end', stretchContainer: true, selected: true});
  43. let nodeB = new Node("B", {justifyContent: 'flex-end' , selected: true}, ImageNode);
  44. let nodeC = new Node("C", {alignSelf: 'flex-end' , selected: true}, ImageNode);
  45. let nodeD = new Node("D");
  46. let nodeE = new Node("E", {alignSelf: 'flex-end' , selected: true}, ImageNode);
  47. let VS = new View();
  48. let root = VS.defaultContainer;
  49. VS
  50. .addViewNode(nodeA, root)
  51. .addViewNode(nodeB, nodeA)
  52. .addViewNode(nodeC, nodeA)
  53. .addViewNode(nodeD, nodeA);
  54. let datata = VS.export();
  55. let VS2 = new View();
  56. VS2
  57. .addViewNode(nodeE, VS2.defaultContainer)
  58. .import(datata, nodeE.id);
  59. // let rowss = VS.setRows(root, 1)[0];
  60. // VS.setColumns(rowss, 2);
  61. // root.props.selected = true;
  62. // let cols = VS.getChildren(rowss);
  63. // VS.setRows(cols[0], 3);
  64. // VS.setRows(cols[1], 2);
  65. // VS.setRows(cols[2], 2);
  66. // cols.forEach((col) => col.props.selected = true);
  67. // cols.forEach((col) => VS.getRows(col).forEach((r) => {VS.setColumns(r,1);r.props.selected = true}));
  68. // cols.forEach((col) => VS.getRows(col).forEach((r) => VS.getColumns(r).forEach((c) => c.props.selected = true)));
  69. // let ee = VS.getRows(cols[1]);
  70. // VS.setColumns(ee[0], 1);
  71. // let cc = VS.getColumns(ee[0]);
  72. // cc[0].content = ImageNode;
  73. // cols[0].content = RootNode;
  74. // cols[1].content = RootNode;
  75. // cols[2].content = ImageNode;
  76. // console.log("ASDASDASDA -> ", cols);
  77. // VS.addViewNode(Row1);
  78. // VS.addViewNode(Col11,Row1);
  79. // VS.addViewNode(Col12,Row1);
  80. // VS.addViewNode(Row2,Col11);
  81. // VS.addViewNode(Col21,Row2);
  82. // VS.addViewNode(Col22,Row2);
  83. // VS.addViewNode(RootNode);
  84. /*VS.addViewNode(NodeB,RootNode)
  85. VS.addViewNode(NodeE,RootNode)
  86. VS.addViewNode(NodeD,NodeB)
  87. VS.addViewNode(NodeK,NodeB)
  88. console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@")
  89. console.log(VS)
  90. //VS.replace(NodeB,TestNode)
  91. VS.replace(NodeK,EditNode)
  92. */
  93. //***************//
  94. /*********************** Custom View tree Ends ************/
  95. //************************************** Routing Ends
  96. let CS = new CoreSystem()
  97. .addPage('test', VS2, 'VS1')
  98. .setHome('test');
  99. let data = CS.export();
  100. console.log("Original");
  101. console.log(data);
  102. let js = JSON.stringify(data);
  103. console.log("String");
  104. console.log(js);
  105. let NCS = new CoreSystem()
  106. let againdata = JSON.parse(js);
  107. console.log("Again");
  108. console.log(againdata)
  109. NCS.import(againdata);
  110. window.onclick = (event) => {
  111. console.log("Mouse event --- ", event);
  112. let res = NCS.ray({event}); // returns ViewNode
  113. console.log(res);
  114. }
  115. const useForceUpdate = (text) => useState(text)[1];
  116. export default function App() {
  117. let [text, setText] = useState('');
  118. let forceUpdate = useForceUpdate(text);
  119. let currentView = NCS.render();
  120. let currentView2 = CS.render();
  121. // console.log(currentView)
  122. return (
  123. <Div style={styles.container}>
  124. <TextInput
  125. style={{height: 40, borderColor: 'gray', borderWidth: 1}}
  126. onChangeText={(txt) => setText(txt)}
  127. value={text}
  128. />
  129. <Button title={'Change Route'} onPress={() => {
  130. //VS.setColumns(root, text);
  131. // CS.goto(text);
  132. // NCS.goto(text);
  133. //forceUpdate(text)
  134. }}></Button>
  135. <Text>Open up App.js to start working on your app!</Text>
  136. <Text>Open up App.js to start working on your app!</Text>
  137. {React.createElement(ButtonComp)}
  138. <Text>Open up App.js to start working on your app!</Text>
  139. <Text>here i s</Text>
  140. {React.createElement(TextComp)}
  141. <Text>sdadada</Text>
  142. {React.createElement(RootComp)}
  143. <Div style={{width: 200, height:400}}>
  144. {React.createElement(ImageComp)}
  145. </Div>
  146. <Div style={{width: 200, height:400}}>
  147. {React.createElement(FormComp)}
  148. </Div>
  149. <Text>Open up App.js to start working on your app!</Text>
  150. <Div style={{width:500, height:600}}>
  151. {currentView}
  152. </Div>
  153. <Div>
  154. <Text>------------------</Text>
  155. <Text>------------------</Text>
  156. </Div>
  157. <Div style={{width:500, height:600}}>
  158. {currentView2}
  159. </Div>
  160. </Div>
  161. );
  162. }
  163. const ImageStyle = StyleSheet.create({
  164. ImageCont:{
  165. width:250,
  166. height:250
  167. }
  168. })
  169. const styles = StyleSheet.create({
  170. container: {
  171. flex: 1,
  172. backgroundColor: '#fff',
  173. alignItems: 'center',
  174. justifyContent: 'center',
  175. },
  176. });