Example fix, test script, and some refactoring

- The test script just does an eslint check. (Closes #121)
- Refactored JS code to pass the check.
- Fixed VideoPlayer example. (Closes #117)
  - Updated package.json to use local react-native-video in a simple manner.
  - Added shared scheme for target.
  - Updated poject settings.
  - Now using react-native 0.18.1.
This commit is contained in:
Baris Sencan
2016-01-31 19:35:18 -08:00
parent c449faa3ff
commit 3b6671c4c7
9 changed files with 156 additions and 41 deletions

View File

@@ -1,4 +1,6 @@
const React = require('react-native');
import React from 'react-native';
import VideoResizeMode from './VideoResizeMode.js';
const {
Component,
StyleSheet,
@@ -8,19 +10,18 @@ const {
View,
} = React;
const VideoResizeMode = require('./VideoResizeMode');
const styles = StyleSheet.create({
base: {
overflow: 'hidden',
},
});
class Video extends Component {
export default class Video extends Component {
constructor(props, context) {
super(props, context);
this.seek = this.seek.bind(this);
this._assignRoot = this._assignRoot.bind(this);
this._onLoadStart = this._onLoadStart.bind(this);
this._onLoad = this._onLoad.bind(this);
this._onError = this._onError.bind(this);
@@ -34,44 +35,58 @@ class Video extends Component {
}
seek(time) {
this.setNativeProps({ seek: parseFloat(time) });
this.setNativeProps({ seek: time });
}
_assignRoot(component) {
this._root = component;
}
_onLoadStart(event) {
this.props.onLoadStart && this.props.onLoadStart(event.nativeEvent);
if (this.props.onLoadStart) {
this.props.onLoadStart(event.nativeEvent);
}
}
_onLoad(event) {
this.props.onLoad && this.props.onLoad(event.nativeEvent);
if (this.props.onLoad) {
this.props.onLoad(event.nativeEvent);
}
}
_onError(event) {
this.props.onError && this.props.onError(event.nativeEvent);
if (this.props.onError) {
this.props.onError(event.nativeEvent);
}
}
_onProgress(event) {
this.props.onProgress && this.props.onProgress(event.nativeEvent);
if (this.props.onProgress) {
this.props.onProgress(event.nativeEvent);
}
}
_onSeek(event) {
this.props.onSeek && this.props.onSeek(event.nativeEvent);
if (this.props.onSeek) {
this.props.onSeek(event.nativeEvent);
}
}
_onEnd(event) {
this.props.onEnd && this.props.onEnd(event.nativeEvent);
if (this.props.onEnd) {
this.props.onEnd(event.nativeEvent);
}
}
render() {
const {
style,
source,
ref,
resizeMode,
} = this.props;
let uri = source.uri;
if (uri && uri.match(/^\//)) {
uri = 'file://' + uri;
uri = `file://${uri}`;
}
const isNetwork = !!(uri && uri.match(/^https?:/));
@@ -90,10 +105,10 @@ class Video extends Component {
const nativeProps = Object.assign({}, this.props);
Object.assign(nativeProps, {
style: [styles.base, style],
style: [styles.base, nativeProps.style],
resizeMode: nativeResizeMode,
src: {
uri: uri,
uri,
isNetwork,
isAsset,
type: source.type || 'mp4',
@@ -108,8 +123,9 @@ class Video extends Component {
return (
<RCTVideo
ref={ component => this._root = component }
{...nativeProps} />
ref={this._assignRoot}
{...nativeProps}
/>
);
}
}
@@ -135,7 +151,7 @@ Video.propTypes = {
onProgress: PropTypes.func,
onSeek: PropTypes.func,
onEnd: PropTypes.func,
/* Required by react-native */
scaleX: React.PropTypes.number,
scaleY: React.PropTypes.number,
@@ -148,8 +164,6 @@ Video.propTypes = {
const RCTVideo = requireNativeComponent('RCTVideo', Video, {
nativeOnly: {
src: true,
seek: true
seek: true,
},
});
module.exports = Video;