Skip to content

Commit d35b5eb

Browse files
committed
Initial commit.
0 parents  commit d35b5eb

File tree

5 files changed

+241
-0
lines changed

5 files changed

+241
-0
lines changed

.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.flowconfig

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[ignore]
2+
.*/Example/*
3+
4+
# We fork some components by platform.
5+
.*/*.web.js
6+
.*/*.android.js
7+
8+
# Some modules have their own node_modules with overlap
9+
.*/node_modules/node-haste/.*
10+
11+
# Ignore react-tools where there are overlaps, but don't ignore anything that
12+
# react-native relies on
13+
.*/node_modules/react-tools/src/vendor/core/ExecutionEnvironment.js
14+
.*/node_modules/react-tools/src/browser/eventPlugins/ResponderEventPlugin.js
15+
.*/node_modules/react-tools/src/browser/ui/React.js
16+
.*/node_modules/react-tools/src/core/ReactInstanceHandles.js
17+
.*/node_modules/react-tools/src/event/EventPropagators.js
18+
19+
# Ignore commoner tests
20+
.*/node_modules/react-tools/node_modules/commoner/test/.*
21+
22+
# See https://github.com/facebook/flow/issues/442
23+
.*/react-tools/node_modules/commoner/lib/reader.js
24+
25+
# Ignore jest
26+
.*/react-native/node_modules/jest-cli/.*
27+
28+
29+
[include]
30+
31+
[libs]
32+
node_modules/react-native/Libraries/react-native/react-native-interface.js
33+
34+
[options]
35+
module.system=haste
36+
37+
[version]
38+
0.11.0

.gitignore

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
# Runtime data
6+
pids
7+
*.pid
8+
*.seed
9+
10+
# Directory for instrumented libs generated by jscoverage/JSCover
11+
lib-cov
12+
13+
# Coverage directory used by tools like istanbul
14+
coverage
15+
16+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17+
.grunt
18+
19+
# node-waf configuration
20+
.lock-wscript
21+
22+
# Compiled binary addons (http://nodejs.org/api/addons.html)
23+
build/Release
24+
25+
# Dependency directory
26+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27+
node_modules

index.js

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/**
2+
* @providesModule ImageProgress
3+
*/
4+
'use strict';
5+
6+
var _ = require('lodash');
7+
var React = require('react-native');
8+
var {
9+
Image,
10+
View,
11+
StyleSheet,
12+
} = React
13+
var flattenStyle = require('react-native/Libraries/StyleSheet/flattenStyle');
14+
15+
var BAR_WIDTH = 150;
16+
var BAR_HEIGHT = 6;
17+
var MIN_PADDING = 10;
18+
19+
var ImageProgress = React.createClass({
20+
getInitialState: function() {
21+
return {
22+
loading: false,
23+
error: false,
24+
progress: 0,
25+
};
26+
},
27+
28+
setNativeProps: function(nativeProps) {
29+
this._root.setNativeProps(nativeProps);
30+
},
31+
32+
handleLayoutChange: function(event) {
33+
this.setState({ layout: event.nativeEvent.layout });
34+
},
35+
36+
handleLoadStart: function() {
37+
this.setState({
38+
error: false,
39+
loading: true,
40+
progress: 0,
41+
});
42+
},
43+
44+
handleLoadProgress: function(event) {
45+
this.setState({
46+
progress: event.nativeEvent.written / event.nativeEvent.total,
47+
});
48+
},
49+
50+
handleLoaded: function() {
51+
this.setState({
52+
loading: false,
53+
progress: 1,
54+
});
55+
},
56+
57+
handleLoadAbort: function() {
58+
this.setState({
59+
loading: false,
60+
});
61+
},
62+
63+
handleLoadError: function() {
64+
this.setState({
65+
error: true,
66+
loading: false,
67+
});
68+
},
69+
70+
render: function() {
71+
var indicator = false;
72+
var props = _.omit(this.props, 'onLoadStart', 'onLoadProgress', 'onLoaded', 'onLoadAbort', 'onLoadError', 'handleLayoutChange');
73+
74+
if(this.state.loading) {
75+
props.style = flattenStyle([styles.container, props.style]);
76+
switch(props.indicator) {
77+
case 'circle': throw new Error('Not yet implemented'); break;
78+
79+
default: {
80+
var barWidth = BAR_WIDTH;
81+
if(this.state.layout) {
82+
barWidth = Math.min(BAR_WIDTH, this.state.layout.width - MIN_PADDING * 2);
83+
}
84+
85+
var barWidthStyle = { width: barWidth };
86+
var barProgressStyle = { width: (barWidth - 2) * this.state.progress };
87+
88+
indicator = (
89+
<View style={[styles.barContainer, barWidthStyle]}>
90+
<View style={[styles.bar, barProgressStyle]}></View>
91+
</View>)
92+
break;
93+
}
94+
}
95+
}
96+
return (
97+
<Image
98+
{...props}
99+
ref={component => this._root = component}
100+
onLoadStart={this.handleLoadStart}
101+
onLoadProgress={this.handleLoadProgress}
102+
onLoaded={this.handleLoaded}
103+
onLoadAbort={this.handleLoadAbort}
104+
onLoadError={this.handleLoadError}
105+
onLayout={this.handleLayoutChange}
106+
>
107+
{indicator}
108+
</Image>
109+
);
110+
}
111+
});
112+
113+
var styles = StyleSheet.create({
114+
container: {
115+
alignItems: 'center',
116+
justifyContent: 'center',
117+
},
118+
barContainer: {
119+
height: BAR_HEIGHT,
120+
borderRadius: BAR_HEIGHT/2,
121+
backgroundColor: 'rgba(255, 255, 255, 0.5)',
122+
},
123+
bar: {
124+
margin: 1,
125+
backgroundColor: 'black',
126+
borderRadius: BAR_HEIGHT/2 - 1,
127+
height: BAR_HEIGHT - 2,
128+
}
129+
});
130+
131+
module.exports = ImageProgress;

package.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "react-native-image-progress",
3+
"version": "0.1.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [
10+
"react-native",
11+
"react-component",
12+
"react-native-component",
13+
"react",
14+
"mobile",
15+
"ios",
16+
"ui",
17+
"image",
18+
"progress",
19+
"bar",
20+
"progressbar",
21+
"loading",
22+
"indicator"
23+
],
24+
"author": "Joel Arvidsson",
25+
"license": "MIT",
26+
"peerDependencies": {
27+
"react-native": "=> 0.8.0 || 0.8.0-rc"
28+
},
29+
"dependencies": {
30+
"lodash": "^3.10.0"
31+
}
32+
}

0 commit comments

Comments
 (0)