Skip to content

Commit

Permalink
start app example
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Oct 27, 2019
1 parent 0f951cc commit 9a73a34
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 10 deletions.
Binary file added packages/playground/assets/suikoden-2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 9 additions & 10 deletions packages/playground/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ import {
import data from './data';
import loadImage from './utils/loadImage';
import Loader from './Loader';
import Store from './Store';

const { width, height } = Dimensions.get('screen');

class App extends Component {
_isMounted = false;

constructor(props) {
super(props);
this.state = {
Expand All @@ -45,6 +48,10 @@ class App extends Component {
console.log('images loaded');
// this.setState({ loaded: true })
});

setTimeout(() => {
this.setState({ loaded: true })
}, 100)
}

render() {
Expand All @@ -59,19 +66,11 @@ class App extends Component {
);
}

if (!loaded) {
return (
<View style={{ backgroundColor: '#1C1E21', width, height }}>
<Loader/>
</View>
);
}

return (
<View style={{ backgroundColor: '#1C1E21', width, height }}>
<Text>Noice</Text>
{ !loaded ? <Loader/> : <Store/> }
</View>
);
)
}
}

Expand Down
60 changes: 60 additions & 0 deletions packages/playground/src/Loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React, {Component} from 'react';
import {
Text,
View,
registerComponent,
StyleSheet,
Dimensions,
} from '../../react-ape/reactApeEntry';

import Spinner from './Spinner';

const {width, height} = Dimensions.get('screen');

// Create Custom Components
const custom = {
Spinner: registerComponent('Spinner', Spinner),
};

const styles = StyleSheet.create({
container: {
position: 'absolute',
left: width / 2 - 40,
top: height / 4,
backgroundColor: '#1C1E21',
}
});

class Loader extends Component {
_interval = null;

constructor(props) {
super(props);
this.state = {
degrees: 0.0,
};
}

componentDidMount() {
this._interval = setInterval(() => {
const {degrees} = this.state;
this.setState({degrees: degrees + 0.1});
}, 10);
}

componentWillUnmount() {
clearInterval(this._interval);
}

render() {
const {degrees} = this.state;
return (
<View style={ styles.container }>
<custom.Spinner degrees={degrees} style={{ top: height / 4 + 8, left: width / 2 - 60, color: 'white' }} />
<Text style={{ color: 'white' }}>Loading Store...</Text>
</View>
);
}
}

export default Loader;
43 changes: 43 additions & 0 deletions packages/playground/src/Store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, {Component} from 'react';
import {
Text,
View,
registerComponent,
StyleSheet,
Dimensions,
} from '../../react-ape/reactApeEntry';

const { width, height } = Dimensions.get('screen');

const styles = StyleSheet.create({
container: {
position: 'absolute',
left: 200,
top: 0,
height,
width,
backgroundColor: 'white',
color: 'orange'
}
});

class Store extends Component {
constructor(props) {
super(props);
this.state = {};
}

componentDidMount() {

}

render() {
return (
<View style={ styles.container }>
<Text>Store...</Text>
</View>
);
}
}

export default Store;
48 changes: 48 additions & 0 deletions packages/playground/src/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export default [
{
name: 'Suikoden 2',
price: 18.9,
imageSrc: 'suikoden-2.jpeg'
},
{
name: 'Suikoden 2',
price: 18.9,
imageSrc: 'suikoden-2.jpeg'
},
{
name: 'Suikoden 2',
price: 18.9,
imageSrc: 'suikoden-2.jpeg'
},
{
name: 'Suikoden 2',
price: 18.9,
imageSrc: 'suikoden-2.jpeg'
},
{
name: 'Suikoden 2',
price: 18.9,
imageSrc: 'suikoden-2.jpeg'
},
{
name: 'Suikoden 2',
price: 18.9,
imageSrc: 'suikoden-2.jpeg'
},
{
name: 'Suikoden 2',
price: 18.9,
imageSrc: 'suikoden-2.jpeg'
},
{
name: 'Suikoden 2',
price: 18.9,
imageSrc: 'suikoden-2.jpeg'
},
{
name: 'Suikoden 2',
price: 18.9,
imageSrc: 'suikoden-2.jpeg'
},
];

11 changes: 11 additions & 0 deletions packages/playground/src/utils/loadImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function loadImage(url) {
return new Promise(resolve => {
const image = new Image();
image.addEventListener('load', () => {
resolve(image);
});
image.src = url;
});
}

export default loadImage;

0 comments on commit 9a73a34

Please sign in to comment.