Created
March 29, 2015 13:58
-
-
Save chiquitinxx/f60c28da6b3ac22520b1 to your computer and use it in GitHub Desktop.
Create ios app with grooscript and react native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def AwesomeProject = React.createClass( | |
render: { | |
def groovyView = new GroovyView() | |
groovyView.data(style: styles.container) { | |
image style: styles.image, source: [uri: 'http://grooscript.org/img/groovy.png'] | |
text style: styles.welcome, "Hello #ios from #groovylang" | |
text style: styles.welcome, "With @grooscript" | |
text style: styles.welcome, "and @reactjs native" | |
} | |
}) | |
import org.grooscript.asts.GsNative | |
import static org.grooscript.GrooScript.toJavascript | |
class GroovyView { | |
def data(map, Closure closure) { | |
def allParams = [View, map] | |
def components = new Components() | |
closure.delegate = components | |
closure() | |
components.list.each { | |
allParams << it | |
} | |
React.createElement.apply(React, allParams) | |
} | |
} | |
class Components { | |
def list = [] | |
def methodMissing(String name, args) { | |
list << React.createElement(component(name), toJavascript(args[0]), args[1]) | |
} | |
def image(Map args) { | |
list << React.createElement(component('image'), toJavascript(args)) | |
} | |
@GsNative | |
private component(name) {/* | |
if (name == 'text') return Text; | |
if (name == 'image') return Image; | |
*/} | |
} | |
def styles = StyleSheet.create toJavascript( | |
container: [ | |
flex: 1, | |
justifyContent: 'center', | |
alignItems: 'center', | |
backgroundColor: '#ffffff', | |
], | |
welcome: [ | |
fontSize: 20, | |
textAlign: 'center', | |
margin: 10, | |
], | |
image: [ | |
width: 192, | |
height: 96, | |
] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment