Skip to content

Commit 802a2da

Browse files
committed
Spinner implementation (start async render algorithm, ref #123)
1 parent e327de6 commit 802a2da

File tree

6 files changed

+32
-37
lines changed

6 files changed

+32
-37
lines changed

packages/app/src/App.js

-12
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,13 @@ import {
99
withNavigation,
1010
} from '../../react-ape/reactApeEntry';
1111

12-
// import Spinner from './Spinner';
1312
import Sidebar from './Sidebar';
1413
import Grid from './Grid';
1514
import Clock from './Clock';
1615
import Slideshow from './Slideshow';
1716

1817
const {width, height} = Dimensions.get('window');
1918

20-
// Register Custom Components
21-
/*
22-
<custom.Spinner
23-
degrees={degrees}
24-
style={{ top: height / 4 + 8, left: width / 2 - 60, color: 'white' }}
25-
/>
26-
*/
27-
// const custom = {
28-
// Spinner: registerComponent('Spinner', Spinner),
29-
// };
30-
3119
const styles = StyleSheet.create({
3220
surface: {
3321
backgroundColor: '#202020',

packages/app/src/Grid.js

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
StyleSheet,
88
} from '../../react-ape/reactApeEntry';
99

10+
import Loader from './Loader';
11+
1012
const {height} = Dimensions.get('screen');
1113

1214
const styles = StyleSheet.create({
@@ -42,9 +44,17 @@ const list = [
4244
class Grid extends Component {
4345
constructor(props) {
4446
super(props);
47+
this.state = {
48+
loading: true,
49+
};
4550
}
4651

4752
render() {
53+
const {loading} = this.state;
54+
if (loading) {
55+
return <Loader />;
56+
}
57+
4858
return (
4959
<View style={styles.grid}>
5060
<Text style={styles.title}>Rio de Janeiro</Text>

packages/app/src/Loader.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const styles = StyleSheet.create({
2121
position: 'absolute',
2222
left: width / 2 - 40,
2323
top: height / 4,
24-
backgroundColor: 'blue',
24+
backgroundColor: '#202020',
2525
},
2626
});
2727

@@ -52,9 +52,8 @@ class Loader extends Component {
5252
<View style={styles.container}>
5353
<custom.Spinner
5454
degrees={degrees}
55-
style={{top: height / 4 + 8, left: width / 2 - 60, color: 'white'}}
55+
style={{top: 550, left: 740, color: 'orange'}}
5656
/>
57-
<Text style={{color: 'white'}}>Loading...</Text>
5857
</View>
5958
);
6059
}

packages/app/src/Spinner.js

+8-19
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ class Spinner {
33
console.log(error, errorInfo);
44
}
55

6-
reset(prevProps, parentStyle, ape) {
7-
const {ctx} = ape;
8-
// parentStyle.backgroundColor // white
9-
if (ctx) {
10-
ctx.clearRect(0, 0, 18, 18);
11-
}
12-
}
6+
// You can also use your own clear function although isn't recommended
7+
// unsafeClear(prevProps, parentStyle, ape) {
8+
// const {ctx} = ape;
9+
// const parentBackgroundColor = parentStyle.style.backgroundColor;
10+
// const newProps = {...prevProps, style: { color: parentBackgroundColor } };
11+
// this.render(newProps, ape);
12+
// }
1313

1414
render(props, ape) {
1515
const {ctx} = ape;
@@ -18,24 +18,13 @@ class Spinner {
1818

1919
const offset = 8;
2020
ctx.save();
21-
// ctx.translate(offset, offset);
2221
ctx.translate(style.left, style.top);
2322
ctx.rotate(degrees);
24-
25-
// Draw half open circle
2623
ctx.beginPath();
27-
ctx.lineWidth = 3;
24+
ctx.lineWidth = 50;
2825
ctx.arc(8 - offset, 8 - offset, 6, 0, 1.75 * Math.PI);
2926
ctx.strokeStyle = color;
3027
ctx.stroke();
31-
32-
// Draw arrowhead
33-
ctx.lineWidth = 3;
34-
ctx.moveTo(13 - offset, 1 - offset);
35-
ctx.lineTo(9 - offset, 5 - offset);
36-
ctx.lineTo(13 - offset, 5 - offset);
37-
ctx.lineTo(13 - offset, 1 - offset);
38-
ctx.stroke();
3928
ctx.restore();
4029
}
4130
}

packages/react-ape/modules/Register/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ function registerComponent(componentName, Component) {
2020
isResetPhase: true,
2121
};
2222

23+
console.log('clearRender');
2324
Component.render(clearProps, apeContext, parentLayout);
2425
};
2526

2627
return {
2728
type: componentName,
2829
render: Component.render.bind(this, props),
29-
clear: Component.reset || clearRender,
30+
clear: Component.unsafeClear || clearRender,
3031
};
3132
};
3233

packages/react-ape/renderer/core/render.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,19 @@ function renderApeQueue(
2222
onFinish: () => mixed
2323
) {
2424
if (apeContextGlobal && apeContextGlobal.renderQueue.length) {
25-
// TODO: Move to request animation frame
25+
// const renderFrame = () => {
26+
// requestAnimationFrame(renderFrame);
27+
// apeContextGlobal.renderQueue.forEach(element => {
28+
// // element.render(apeContextGlobal, element.parentLayout)
29+
// renderApeElement(apeContextGlobal, element);
30+
// });
31+
// cancelAnimationFrame(renderFrame);
32+
// }
33+
// renderFrame();
34+
2635
apeContextGlobal.renderQueue.forEach(element => {
2736
renderApeElement(apeContextGlobal, element);
2837
});
29-
3038
onFinish();
3139
}
3240
}

0 commit comments

Comments
 (0)