From 3467ef101c633e6de0f6d2e1967bca977b9560fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Tue, 16 Feb 2016 13:11:17 +0100 Subject: [PATCH] Support for https://github.com/ProjectSeptemberInc/gl-react/issues/33 --- example/src/Tests/NativeLayer.js | 2 +- example/src/Tests/index.js | 93 +++----------------------------- example/src/index.js | 25 ++++++++- src/GLCanvas.js | 39 ++++++++++++-- 4 files changed, 69 insertions(+), 90 deletions(-) diff --git a/example/src/Tests/NativeLayer.js b/example/src/Tests/NativeLayer.js index 5ff738d..1a10cd8 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 35321df..070d93b 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 6b73b93..b80079d 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 ; } } -- 2.26.2