Move resizeMode to prop from style (at request of @vjeux) and add pause

prop
This commit is contained in:
Brent Vatne 2015-04-05 10:17:03 -07:00
parent b8df485c79
commit 011ecff875
4 changed files with 22 additions and 9 deletions

View File

@ -34,6 +34,15 @@
_playerLayer.videoGravity = mode; _playerLayer.videoGravity = mode;
} }
- (void)setPause:(BOOL)wantsToPause
{
if (wantsToPause) {
[_player pause];
} else {
[_player play];
}
}
- (void)playerItemDidReachEnd:(NSNotification *)notification { - (void)playerItemDidReachEnd:(NSNotification *)notification {
AVPlayerItem *item = [notification object]; AVPlayerItem *item = [notification object];

View File

@ -15,6 +15,7 @@
RCT_EXPORT_VIEW_PROPERTY(src, NSString); RCT_EXPORT_VIEW_PROPERTY(src, NSString);
RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSString); RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSString);
RCT_EXPORT_VIEW_PROPERTY(repeat, BOOL); RCT_EXPORT_VIEW_PROPERTY(repeat, BOOL);
RCT_EXPORT_VIEW_PROPERTY(pause, BOOL);
- (NSDictionary *)constantsToExport - (NSDictionary *)constantsToExport
{ {

View File

@ -15,7 +15,9 @@ var Video = React.createClass({
propTypes: { propTypes: {
source: PropTypes.string, source: PropTypes.string,
style: StyleSheetPropType(VideoStylePropTypes), style: StyleSheetPropType(VideoStylePropTypes),
resizeMode: PropTypes.string,
repeat: PropTypes.bool, repeat: PropTypes.bool,
pause: PropTypes.bool,
}, },
mixins: [NativeMethodsMixin], mixins: [NativeMethodsMixin],
@ -30,18 +32,19 @@ var Video = React.createClass({
var source = this.props.source; var source = this.props.source;
var resizeMode; var resizeMode;
var contentModes = NativeModules.VideoManager; if (this.props.resizeMode === VideoResizeMode.stretch) {
if (style.resizeMode === VideoResizeMode.stretch) { resizeMode = NativeModules.VideoManager.ScaleToFill;
resizeMode = contentModes.ScaleToFill; } else if (this.props.resizeMode === VideoResizeMode.contain) {
} else if (style.resizeMode === VideoResizeMode.contain) { resizeMode = NativeModules.VideoManager.ScaleAspectFit;
resizeMode = contentModes.ScaleAspectFit; } else if (this.props.resizeMode == VideoResizeMode.cover) {
resizeMode = NativeModules.VideoManager.ScaleAspectFill;
} else { } else {
resizeMode = contentModes.ScaleAspectFill; resizeMode = NativeModules.VideoManager.ScaleNone;
} }
var nativeProps = merge(this.props, { var nativeProps = merge(this.props, {
style, style,
resizeMode, resizeMode: resizeMode,
src: source, src: source,
}); });
@ -50,7 +53,8 @@ var Video = React.createClass({
}); });
var RCTVideo = createReactIOSNativeComponentClass({ var RCTVideo = createReactIOSNativeComponentClass({
validAttributes: merge(ReactIOSViewAttributes.UIView, {src: true, resizeMode: true, repeat: true}), validAttributes: merge(ReactIOSViewAttributes.UIView,
{src: true, resizeMode: true, repeat: true, pause: true}),
uiViewClassName: 'RCTVideo', uiViewClassName: 'RCTVideo',
}); });

View File

@ -6,7 +6,6 @@ var ReactPropTypes = require('ReactPropTypes');
var VideoStylePropTypes = { var VideoStylePropTypes = {
...LayoutPropTypes, ...LayoutPropTypes,
resizeMode: ReactPropTypes.oneOf(Object.keys(VideoResizeMode)),
}; };
module.exports = VideoStylePropTypes; module.exports = VideoStylePropTypes;