diff --git a/example/src/Tests/NativeLayer.js b/example/src/Tests/NativeLayer.js index 5ff738d183354bf58560574922cd2db55ff5ca1f..1a10cd8071da7c468959972f0d3496a8e3ea5627 100644 --- a/example/src/Tests/NativeLayer.js +++ b/example/src/Tests/NativeLayer.js @@ -6,7 +6,7 @@ const { class NativeLayer extends React.Component { render () { const { width, height, children, ...rest } = this.props; - return + return {React.Children.map(children, child => {child} diff --git a/example/src/Tests/index.js b/example/src/Tests/index.js index 35321df2ec5454863de8fd7b2ea4b48cb8884540..070d93bb8525b3c4a97548634bc522b636765c8c 100644 --- a/example/src/Tests/index.js +++ b/example/src/Tests/index.js @@ -31,14 +31,14 @@ class Tests extends React.Component { console.log("PROGRESS", progress, loaded, total); } render () { - const debugSize = viewportW / 2; + const debugSize = viewportW / 4; const helloGL = ; const txt = - {[0,1,2,3].map(i => - - - - - - - - - - http://i.imgur.com/mp79p5T.png - - - - - - - - - - http://i.imgur.com/mp79p5T.png - - - - - - - - - - - - http://i.imgur.com/mp79p5T.png - - - - - - @@ -142,52 +104,9 @@ class Tests extends React.Component { - - - - - - - http://i.imgur.com/mp79p5T.png - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -231,6 +150,10 @@ class Tests extends React.Component { + + + + ; diff --git a/example/src/index.js b/example/src/index.js index 6b73b9308945dc995c96891c818274c776f2b039..b80079d68cc49e4cb51c2f5fd272d6062b0486b6 100644 --- a/example/src/index.js +++ b/example/src/index.js @@ -6,6 +6,7 @@ import React, { Text, TouchableOpacity, Navigator, + AsyncStorage, } from "react-native"; const screens = { @@ -77,6 +78,26 @@ class Home extends Component { export default class App extends Component { static propTypes = {}; + constructor (props) { + super(props); + this.state = { + initialRoute: homeRoute + }; + /* + new Promise((success, failure) => + AsyncStorage.getItem("route", (error, result) => { + if (error) failure(error); + else success(result); + })) + .then(result => { + const route = JSON.parse(result); + if (!route) throw new Error("invalid route"); + return route; + }) + .catch(() => homeRoute) + .then(initialRoute => this.setState({ initialRoute })); + */ + } renderScene = (route, navigator) => { if (route.id === homeRoute.id) { return navigator.push(route)} />; @@ -85,12 +106,14 @@ export default class App extends Component { return ; }; render () { + const { initialRoute } = this.state; + if (!initialRoute) return ; return ( { + // If Surface size matches the root node size, pass-in the styles + if ( + !data || + width * pixelRatio === data.width * data.pixelRatio && + height * pixelRatio === data.height * data.pixelRatio + ) { + return { pixelRatio, style: { width, height } }; + } + // otherwise, stretch the canvas to the surface size + const w = data.width * data.pixelRatio; + const h = data.height * data.pixelRatio; + return { + pixelRatio: 1, // pixelRatio is hardcoded to 1 to normalize the transform + style: { + width: w, + height: h, + transform: [ + { translateX: -w / 2 }, + { translateY: -h / 2 }, + { scaleX: width / w }, + { scaleY: height / h }, + { translateX: w / 2 }, + { translateY: h / 2 }, + ] + } + }; +}; + class GLCanvas extends Component { componentWillMount () { @@ -103,15 +132,19 @@ class GLCanvas extends Component { }; render () { - const { width, height, onLoad, onProgress, eventsThrough, ...restProps } = this.props; + const { + width, height, pixelRatio, data, + onLoad, onProgress, eventsThrough, + ...restProps } = this.props; return ; } }