Skip to content

Commit

Permalink
Merge 4111410 into 0ca2b0e
Browse files Browse the repository at this point in the history
  • Loading branch information
dmikey committed Jan 10, 2018
2 parents 0ca2b0e + 4111410 commit cf0680a
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protected void onCreate(Bundle savedInstanceState) {
modules.add(new SyrText());
modules.add(new SyrButton());
modules.add(new SyrImage());
modules.add(new SyrTouchableOpacity());

// get the javascript bundle
SyrBundle bundle = new SyrBundleManager().setBundleAssetName("").build();
Expand All @@ -45,10 +46,12 @@ protected void onCreate(Bundle savedInstanceState) {
// create a new Rootview
SyrRootView rootview = new SyrRootView(this);

// start the Syr Application
rootview.startSyrApplication(instance, bundle);

// set the content of the to the Rootview
setContentView(rootview);

// start the Syr Application
rootview.startSyrApplication(instance, bundle);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class SyrBridge {
private Context mContext;
private SyrRaster mRaster;
private WebView mBridgedBrowser;
public HashMap<String, String> bootParams = new HashMap<String,String>();

/** Instantiate the interface and set the context */
SyrBridge(Context c) {
Expand Down Expand Up @@ -70,7 +71,9 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
WebSettings webSettings = mBridgedBrowser.getSettings();
webSettings.setJavaScriptEnabled(true);

mBridgedBrowser.loadUrl("http://10.0.2.2:8080");
String loadURL = String.format("http://10.0.2.2:8080?window_height=%s&window_width=%s", bootParams.get("height"), bootParams.get("width"));

mBridgedBrowser.loadUrl(loadURL);
}

public void sendEvent(HashMap<String, String> event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

/**
* Created by dereanderson on 1/9/18.
*/
Expand All @@ -22,16 +25,24 @@ public View render(JSONObject component, Context context) {

try {
JSONObject instance = component.getJSONObject("instance");
final String guid = component.getString("guid");
if(component.has("attributes") && component.getJSONObject("attributes").has("style")){

style = component.getJSONObject("attributes").getJSONObject("style");

button.setLayoutParams(SyrStyler.styleLayout(style));
SyrStyler.styleView(button, style);

}

button.setText(instance.getString("value"));
button.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
HashMap<String, String> eventMap = new HashMap<String, String>();
eventMap.put("type", "onPress");
eventMap.put("guid", guid);
SyrEventHandler.getInstance().sendEvent(eventMap);
}
});
} catch (JSONException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
package com.example.dereanderson.syrnativeandroid;

import java.util.HashMap;

/**
* Syr Project
* https://syr.js.org
* Created by Derek Anderson on 1/8/18.
*/
public class SyrEventHandler {
}

public SyrBridge mBridge;

private static SyrEventHandler sSyrEventHandler;

private SyrEventHandler(){} //private constructor.

public static SyrEventHandler getInstance(){
if (sSyrEventHandler == null){ //if there is no instance available... create new one
sSyrEventHandler = new SyrEventHandler();
}
return sSyrEventHandler;
}

public void sendEvent(HashMap<String, String> event) {
mBridge.sendEvent(event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public SyrInstance(SyrInstanceManager manager) {
}

public SyrInstance setBridge(SyrBridge bridge) {
// set the bridge for the event handler
SyrEventHandler.getInstance().mBridge = bridge;
mBridge = bridge;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class SyrRootView extends FrameLayout {
private Context mContext;
private SyrBridge mBridge;
private SyrRaster mRaster;
private SyrInstance mInstance;
private Boolean mLoaded = false;
private int mHeight;
private int mWidth;

public SyrRootView(Context context) {
super(context);
Expand All @@ -27,7 +31,7 @@ public SyrRootView startSyrApplication(SyrInstance instance, SyrBundle bundle) {
mBridge = new SyrBridge(mContext);
mRaster = new SyrRaster(mContext);
mRaster.setRootview(this);
instance.setBridge(mBridge).setRaster(mRaster).loadBundle();
mInstance = instance;
return this;
}

Expand All @@ -37,4 +41,17 @@ public void destroy() {
mRaster = null;
}

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
mHeight = this.getWidth();
mWidth = this.getHeight();

if(mHeight > 0 && mWidth > 0 && !mLoaded) {
mLoaded = true;
mBridge.bootParams.put("height", Integer.toString(mHeight));
mBridge.bootParams.put("width", Integer.toString(mWidth));
mInstance.setBridge(mBridge).setRaster(mRaster).loadBundle();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,49 @@
package com.example.dereanderson.syrnativeandroid;

import android.content.Context;
import android.view.View;
import android.widget.RelativeLayout;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

/**
* Created by dereanderson on 1/10/18.
*/

public class SyrTouchableOpacity {
public class SyrTouchableOpacity implements SyrBaseModule {

@Override
public View render(JSONObject component, Context context) {
RelativeLayout layout = new RelativeLayout(context);
JSONObject style = null;

try {
final String guid = component.getString("guid");
style = component.getJSONObject("attributes").getJSONObject("style");

layout.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
HashMap<String, String> eventMap = new HashMap<String, String>();
eventMap.put("type", "onPress");
eventMap.put("guid", guid);
SyrEventHandler.getInstance().sendEvent(eventMap);
}
});
} catch (JSONException e) {
e.printStackTrace();
}

layout.setLayoutParams(SyrStyler.styleLayout(style));
SyrStyler.styleView(layout, style);

return layout;
}

@Override
public String getName() {
return "TouchableOpacity";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

/**
* Syr Project
* https://syr.js.org
Expand All @@ -24,13 +26,16 @@ public View render(JSONObject component, Context context) {

try {
style = component.getJSONObject("attributes").getJSONObject("style");

} catch (JSONException e) {
e.printStackTrace();
}

layout.setLayoutParams(SyrStyler.styleLayout(style));
SyrStyler.styleView(layout, style);



return layout;
}

Expand Down
17 changes: 11 additions & 6 deletions samples/example.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Component, Render, View, Dimensions, Animated, Text, Button, Image } from '../index';
import { Component, Render, View, Dimensions, Animated, Text, Button, Image, TouchableOpacity } from '../index';

console.log(Dimensions.get('window'));
const styles = {
square: {
width: 300,
width: Dimensions.get('window').width,
height: 300,
backgroundColor: '#f000f0',
top: 200,
left: 300,
left: 0,
borderRadius: 30,
},
};
Expand All @@ -17,12 +18,16 @@ class MyComponent extends Component {
render() {
return <View style={styles.square}>
<Text style={{left: 0, top:245}}>Two of These!</Text>
<Button style={{left:50,backgroundColor: '#ffffff', width:200, height:200}}>Foo Bar Moar</Button>
<Image style={{top:150,left:(300/2)-(75/2), height:75, width:75}}/>
<Button onPress={()=>this.onPress()} style={{left:50,backgroundColor: '#ffffff', width:200, height:200}}>Foo Bar Moar</Button>
<TouchableOpacity onPress={()=>this.onPress()} style={{top:150,left:(300/2)-(75/2), height:75, width:75}}><Image style={{height:75, width:75}}/></TouchableOpacity>
</View>;
}
onPress() {
console.log('I was pressed!');
}
componentDidMount() {
console.log('Yup I Did');

console.log('Yup I Did 2');
}
}

Expand Down

0 comments on commit cf0680a

Please sign in to comment.