3
0

App.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. import Environment from './environment';
  14. import * as Font from 'expo-font';
  15. import Module from './modules';
  16. console.log("@@@@@@@@@@@@@@")
  17. console.log(Module)
  18. const CustomStyle = StyleSheet.create({
  19. container:{
  20. flex:1,
  21. backgroundColor:'red'
  22. },
  23. text:{
  24. color:'blue'
  25. }
  26. })
  27. const RootStyle = StyleSheet.create({
  28. container:{
  29. flex:1,
  30. backgroundColor:'blue'
  31. },
  32. text:{
  33. color:'black'
  34. }
  35. })
  36. 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});
  37. let TestNode = new ViewNode("H","Text",{style:CustomStyle,text:"Edited Text Node Will be here"})
  38. let ImageNode = new ViewNode("asdasd","Image");
  39. // let Row1 = new RowNode("RootRow");
  40. // let Col11 = new ColNode("Col11");
  41. // let Col12 = new ColNode("Col12");
  42. // let Row2 = new RowNode("RootRow2");
  43. // let Col21 = new ColNode("Col21");
  44. // let Col22 = new ColNode("Col22");
  45. // Col21.content = RootNode;
  46. // Col12.content = TestNode;
  47. let nodeA = new Node("A", {justifyContent: 'flex-end', stretchContainer: true, selected: true});
  48. let nodeB = new Node("B", {justifyContent: 'flex-end' , selected: true}, ImageNode);
  49. let nodeC = new Node("C", {alignSelf: 'flex-end' , selected: true}, ImageNode);
  50. let nodeD = new Node("D");
  51. let nodeE = new Node("E", {alignSelf: 'flex-end' , selected: true}, ImageNode);
  52. let VS = new View();
  53. let root = VS.defaultContainer;
  54. VS
  55. .addViewNode(nodeA, root)
  56. .addViewNode(nodeB, nodeA)
  57. .addViewNode(nodeC, nodeA)
  58. .addViewNode(nodeD, nodeA);
  59. let datata = VS.export();
  60. let VS2 = new View();
  61. VS2
  62. .addViewNode(nodeE, VS2.defaultContainer)
  63. .import(datata, nodeE.id);
  64. // let rowss = VS.setRows(root, 1)[0];
  65. // VS.setColumns(rowss, 2);
  66. // root.props.selected = true;
  67. // let cols = VS.getChildren(rowss);
  68. // VS.setRows(cols[0], 3);
  69. // VS.setRows(cols[1], 2);
  70. // VS.setRows(cols[2], 2);
  71. // cols.forEach((col) => col.props.selected = true);
  72. // cols.forEach((col) => VS.getRows(col).forEach((r) => {VS.setColumns(r,1);r.props.selected = true}));
  73. // cols.forEach((col) => VS.getRows(col).forEach((r) => VS.getColumns(r).forEach((c) => c.props.selected = true)));
  74. // let ee = VS.getRows(cols[1]);
  75. // VS.setColumns(ee[0], 1);
  76. // let cc = VS.getColumns(ee[0]);
  77. // cc[0].content = ImageNode;
  78. // cols[0].content = RootNode;
  79. // cols[1].content = RootNode;
  80. // cols[2].content = ImageNode;
  81. // console.log("ASDASDASDA -> ", cols);
  82. // VS.addViewNode(Row1);
  83. // VS.addViewNode(Col11,Row1);
  84. // VS.addViewNode(Col12,Row1);
  85. // VS.addViewNode(Row2,Col11);
  86. // VS.addViewNode(Col21,Row2);
  87. // VS.addViewNode(Col22,Row2);
  88. // VS.addViewNode(RootNode);
  89. /*VS.addViewNode(NodeB,RootNode)
  90. VS.addViewNode(NodeE,RootNode)
  91. VS.addViewNode(NodeD,NodeB)
  92. VS.addViewNode(NodeK,NodeB)
  93. console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@")
  94. console.log(VS)
  95. //VS.replace(NodeB,TestNode)
  96. VS.replace(NodeK,EditNode)
  97. */
  98. //***************//
  99. /*********************** Custom View tree Ends ************/
  100. //************************************** Routing Ends
  101. let CS = new CoreSystem()
  102. // .addPage('test', VS2, 'VS1')
  103. // .setHome('test');
  104. CS.import(Environment);
  105. // let data = CS.export();
  106. // console.log("Original");
  107. // console.log(data);
  108. // let js = JSON.stringify(data);
  109. // console.log("String");
  110. // console.log(js);
  111. // let NCS = new CoreSystem()
  112. // let againdata = JSON.parse(js);
  113. // console.log("Again");
  114. // console.log(againdata)
  115. // NCS.import(againdata);
  116. // window.onclick = (event) => {
  117. // console.log("Mouse event --- ", event);
  118. // let res = NCS.ray({event}); // returns ViewNode
  119. // console.log(res);
  120. // }
  121. const useForceUpdate = (text) => useState(text)[1];
  122. export default class App extends React.Component {
  123. constructor(){
  124. super()
  125. }
  126. /*let [text, setText] = useState('');
  127. let forceUpdate = useForceUpdate(text);
  128. */
  129. componentDidMount() {
  130. Font.loadAsync({
  131. 'black': require('./assets/fonts/SFCompactDisplay-Black_0.otf'),
  132. 'bold': require('./assets/fonts/SFCompactDisplay-Bold_0.otf'),
  133. 'heavy': require('./assets/fonts/SFCompactDisplay-Heavy_0.otf'),
  134. 'light': require('./assets/fonts/SFCompactDisplay-Light_0.otf'),
  135. 'medium': require('./assets/fonts/SFCompactDisplay-Medium_0.otf'),
  136. 'regular': require('./assets/fonts/SFCompactDisplay-Regular_0.otf'),
  137. 'semibold': require('./assets/fonts/SFCompactDisplay-Semibold_0.otf'),
  138. 'thin': require('./assets/fonts/SFCompactDisplay-Thin_0.otf'),
  139. 'ultralight': require('./assets/fonts/SFCompactDisplay-Ultralight_0.otf')
  140. });
  141. }
  142. render(){
  143. let currentView2 = CS.render();
  144. return (
  145. <Div>
  146. <Div>{CS.ModuleSystem.createElementCtor(ButtonComp)}</Div>
  147. <Div>{currentView2}</Div>
  148. </Div>)
  149. }
  150. }
  151. const ImageStyle = StyleSheet.create({
  152. ImageCont:{
  153. width:250,
  154. height:250
  155. }
  156. })
  157. const styles = StyleSheet.create({
  158. container: {
  159. flex: 1,
  160. backgroundColor: '#fff',
  161. alignItems: 'center',
  162. justifyContent: 'center',
  163. },
  164. });