From 6f180f7dbec6d069957c35c204c2cb5e615eb9ed Mon Sep 17 00:00:00 2001 From: msiddharthreddy Date: Thu, 26 Jul 2018 14:46:25 -0700 Subject: [PATCH 01/10] Cleaning up Android sample --- android/.idea/misc.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/.idea/misc.xml b/android/.idea/misc.xml index 8bbe1216..ba7052b8 100644 --- a/android/.idea/misc.xml +++ b/android/.idea/misc.xml @@ -24,10 +24,10 @@ - + - + \ No newline at end of file From 068cdcebaaf7f64169edda05c1beb6510c4a1167 Mon Sep 17 00:00:00 2001 From: msiddharthreddy Date: Fri, 27 Jul 2018 12:58:31 -0700 Subject: [PATCH 02/10] Adding a conditional rendering example --- samples/conditionalRender.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 samples/conditionalRender.js diff --git a/samples/conditionalRender.js b/samples/conditionalRender.js new file mode 100644 index 00000000..dca6f8e0 --- /dev/null +++ b/samples/conditionalRender.js @@ -0,0 +1,35 @@ +import { Component, Render, Text, Dimensions, PixelRatio } from '../index'; + +class DisText extends Component { + constructor(props) { + super(props); + this.state.showing = false; + } + + componentDidMount() { + setTimeout(() => { + this.setState({ + showing: true + }); + }, 1000); + } + + render() { + const style = { + left: Dimensions.get('window').width / 2, + top: PixelRatio.getPixelSizeForLayoutSize(20), + width: PixelRatio.getPixelSizeForLayoutSize(300), + height: PixelRatio.getPixelSizeForLayoutSize(40), + fontSize: PixelRatio.getPixelSizeForLayoutSize(20), + color: '#000000' + }; + if (!this.state.showing) { + return showing; + } else { + return not showing; + } + + } +} + +Render(DisText) From a456cf2d4ff3db7474b01287a92ff349480cac25 Mon Sep 17 00:00:00 2001 From: msiddharthreddy Date: Fri, 21 Sep 2018 14:16:36 -0700 Subject: [PATCH 03/10] Allowing JavaScript running in the context of a file scheme URL to access content from other file scheme URLs --- .../syrnative/src/main/java/syr/js/org/syrnative/SyrBridge.java | 1 + 1 file changed, 1 insertion(+) diff --git a/android/syrnative/src/main/java/syr/js/org/syrnative/SyrBridge.java b/android/syrnative/src/main/java/syr/js/org/syrnative/SyrBridge.java index fecddc42..c9ca2a10 100644 --- a/android/syrnative/src/main/java/syr/js/org/syrnative/SyrBridge.java +++ b/android/syrnative/src/main/java/syr/js/org/syrnative/SyrBridge.java @@ -105,6 +105,7 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) { WebSettings webSettings = mBridgedBrowser.getSettings(); webSettings.setJavaScriptEnabled(true); + webSettings.setAllowFileAccessFromFileURLs(true); JSONArray jsArray = new JSONArray(mRaster.exportedMethods); String exportedMethods = jsArray.toString(); From 7adf26c4977a38cf99bc970a96ff9671abd5d2b5 Mon Sep 17 00:00:00 2001 From: msiddharthreddy Date: Sat, 6 Oct 2018 12:47:05 -0700 Subject: [PATCH 04/10] Adding a test HTML file for web testing --- syr_test.html | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 syr_test.html diff --git a/syr_test.html b/syr_test.html new file mode 100644 index 00000000..ac4e1472 --- /dev/null +++ b/syr_test.html @@ -0,0 +1,33 @@ + + + + + + + + From d59bff34e2893c89d7ea3e9ddd33d622ad02ecbb Mon Sep 17 00:00:00 2001 From: msiddharthreddy Date: Sat, 6 Oct 2018 12:49:03 -0700 Subject: [PATCH 05/10] Changes to get webraster workign again for XO --- android/syrnative/build.gradle | 2 +- lib/rastermanager.js | 3 ++- lib/rasters/dom/index.js | 5 +++++ lib/rasters/dom/raster.js | 16 ++++++++-------- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/android/syrnative/build.gradle b/android/syrnative/build.gradle index e3f7ea3f..9368053a 100644 --- a/android/syrnative/build.gradle +++ b/android/syrnative/build.gradle @@ -17,7 +17,7 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } - buildToolsVersion '26.0.2' + buildToolsVersion '27.0.3' compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 diff --git a/lib/rastermanager.js b/lib/rastermanager.js index d658ef79..5e92f8dd 100644 --- a/lib/rastermanager.js +++ b/lib/rastermanager.js @@ -171,6 +171,7 @@ const flattenChildren = children => { const initializeComponent = component => { // initial props const initial_props = _raster.props(); + console.log('initial props', initial_props) // hasn't been inflated yet let c = new component(initial_props); @@ -346,7 +347,7 @@ const updateComponent = (component, rendered) => { reflow(component); component.update = true; - + // console.timeEnd("ui reconciled"); return component; }; diff --git a/lib/rasters/dom/index.js b/lib/rasters/dom/index.js index dcd8cf67..a2cd6c57 100644 --- a/lib/rasters/dom/index.js +++ b/lib/rasters/dom/index.js @@ -1,4 +1,6 @@ import { Raster } from './raster'; +import { RasterUtils } from '../rasterutils'; + const document = global.document || { body: { @@ -37,6 +39,9 @@ class domraster { } props() { + if (RasterUtils.props && RasterUtils.props.initial_props) { + return JSON.parse(RasterUtils.props.initial_props); + } return {}; } } diff --git a/lib/rasters/dom/raster.js b/lib/rasters/dom/raster.js index 22b1d465..412ed387 100644 --- a/lib/rasters/dom/raster.js +++ b/lib/rasters/dom/raster.js @@ -6,13 +6,7 @@ let _instances = {}; class raster { parseAST(ast, target) { if (!ast.update) { - this.build(ast, target, () => { - console.log('uuid', ast.uuid); - SyrEvents.emit({ - type: 'componentDidMount', - guid: ast.uuid, - }); - }); + this.build(ast, target); } else { this.update(ast, target); } @@ -27,10 +21,13 @@ class raster { renderTarget instanceof HTMLElement ? renderTarget : document.getElementById(renderTarget); + SyrEvents.emit({ + type: 'componentDidMount', + guid: ast.uuid, + }); if (instance) { renderTarget.appendChild(instance); _instances[ast.instance.uuid] = instance; - cb(); if (ast.children) { this.buildChidren(ast, instance, ast.update); } @@ -51,6 +48,8 @@ class raster { if (instance) { parent.appendChild(instance); _instances[component.instance.uuid] = instance; + + // console.log('Component did mount', component) SyrEvents.emit({ type: 'componentDidMount', guid: component.instance.uuid, @@ -143,6 +142,7 @@ class raster { if (newInstance) { viewParent.appendChild(newInstance); _instances[component.instance.uuid] = newInstance; + console.log('Conponent Did mount') SyrEvents.emit({ type: 'componentDidMount', guid: component.instance.uuid, From 94f26a2f7174471a63f4af438a6440322b75337c Mon Sep 17 00:00:00 2001 From: msiddharthreddy Date: Sat, 6 Oct 2018 12:49:26 -0700 Subject: [PATCH 06/10] Pretty --- lib/component.js | 8 +++++--- lib/rastermanager.js | 27 +++++++++++++------------- lib/rasters/dom/index.js | 1 - lib/rasters/dom/raster.js | 4 ++-- samples/addRemoveItem.js | 2 +- samples/conditionalRender.js | 7 +++---- samples/example.js | 32 +++++++++++-------------------- samples/multiConditionalRender.js | 10 +++++----- samples/styles.js | 6 +----- 9 files changed, 42 insertions(+), 55 deletions(-) diff --git a/lib/component.js b/lib/component.js index 97fb4658..a1e7782e 100644 --- a/lib/component.js +++ b/lib/component.js @@ -34,15 +34,17 @@ class Component { // send updated AST to raster // check to see that this instance is available before we attempt to update it - if(Render.getInstance(this.uuid)) { + if (Render.getInstance(this.uuid)) { this.render ? Render(this) : ''; if (cb) { cb(); } } else { - console.warn('Set state called, while component exited the component tree! >>>', this); + console.warn( + 'Set state called, while component exited the component tree! >>>', + this + ); } - }; } } diff --git a/lib/rastermanager.js b/lib/rastermanager.js index 5e92f8dd..0581a4f3 100644 --- a/lib/rastermanager.js +++ b/lib/rastermanager.js @@ -171,7 +171,7 @@ const flattenChildren = children => { const initializeComponent = component => { // initial props const initial_props = _raster.props(); - console.log('initial props', initial_props) + console.log('initial props', initial_props); // hasn't been inflated yet let c = new component(initial_props); @@ -208,7 +208,6 @@ const initializeComponent = component => { const updateComponent = (component, rendered) => { function reflow(component, passedUpdates) { - let updates = []; let shouldComponentUpdate = true; let previousProps = (component.instance && component.instance.props) || {}; @@ -228,14 +227,17 @@ const updateComponent = (component, rendered) => { // console.log('setting props >>> ' + component.elementName + ' ' + JSON.stringify(component.instance.props) + ' --> ' + JSON.stringify(passedUpdates.attributes)) component.instance.setProps(passedUpdates.attributes); - if (component.instance.shouldComponentUpdate) { - shouldComponentUpdate = component.instance.shouldComponentUpdate.call(this, passedUpdates.attributes, component.instance.state); + shouldComponentUpdate = component.instance.shouldComponentUpdate.call( + this, + passedUpdates.attributes, + component.instance.state + ); } // --- component update start --- - if(shouldComponentUpdate) { + if (shouldComponentUpdate) { if (passedUpdates.attributes.style) { component.instance.style = passedUpdates.attributes.style; // console.log('updating styles >>> ' + component.elementName + '' + JSON.stringify(passedUpdates.attributes.style)) @@ -269,7 +271,6 @@ const updateComponent = (component, rendered) => { } if (updates.length > 0) { - updates = flattenChildren(updates); // get a fence id from the components children @@ -292,7 +293,6 @@ const updateComponent = (component, rendered) => { // check the cache if (typeof _cache[uuid] == 'undefined') { - // key is added during create component // not clean :shrug: - derek update.uuid = fenceid + '-' + update.guid; @@ -305,7 +305,7 @@ const updateComponent = (component, rendered) => { component.children.splice(index, 0, newComponent); } else { // update the component - reflow(_cache[uuid], update) + reflow(_cache[uuid], update); } // cache the update id's to verify if we need to unmount @@ -320,22 +320,23 @@ const updateComponent = (component, rendered) => { // if the component is not int he update tree // mark for removal - if(!updateIDs[child.instance.uuid]) { + if (!updateIDs[child.instance.uuid]) { child.unmount = true; // and remove from cache delete _cache[child.instance.uuid]; - } - else if(child.unmount) { + } else if (child.unmount) { // if we're reconciling a tree previously built, // remove any unmounts from the tree we marked last time component.children.splice(index, 1); } } - } if (component.instance && component.instance.componentDidUpdate) { - shouldComponentUpdate = component.instance.componentDidUpdate.call(this, previousProps); + shouldComponentUpdate = component.instance.componentDidUpdate.call( + this, + previousProps + ); } } diff --git a/lib/rasters/dom/index.js b/lib/rasters/dom/index.js index a2cd6c57..321c8cdf 100644 --- a/lib/rasters/dom/index.js +++ b/lib/rasters/dom/index.js @@ -1,7 +1,6 @@ import { Raster } from './raster'; import { RasterUtils } from '../rasterutils'; - const document = global.document || { body: { addEventListener: () => {}, diff --git a/lib/rasters/dom/raster.js b/lib/rasters/dom/raster.js index 412ed387..9083b1a2 100644 --- a/lib/rasters/dom/raster.js +++ b/lib/rasters/dom/raster.js @@ -49,7 +49,7 @@ class raster { parent.appendChild(instance); _instances[component.instance.uuid] = instance; - // console.log('Component did mount', component) + // console.log('Component did mount', component) SyrEvents.emit({ type: 'componentDidMount', guid: component.instance.uuid, @@ -142,7 +142,7 @@ class raster { if (newInstance) { viewParent.appendChild(newInstance); _instances[component.instance.uuid] = newInstance; - console.log('Conponent Did mount') + console.log('Conponent Did mount'); SyrEvents.emit({ type: 'componentDidMount', guid: component.instance.uuid, diff --git a/samples/addRemoveItem.js b/samples/addRemoveItem.js index a5012278..03f13fa5 100644 --- a/samples/addRemoveItem.js +++ b/samples/addRemoveItem.js @@ -58,7 +58,7 @@ class example extends Component { backgroundColor: '#09aea4', }} > - {this.state.components} + {this.state.components}