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;
}
- (void)setPause:(BOOL)wantsToPause
{
if (wantsToPause) {
[_player pause];
} else {
[_player play];
}
}
- (void)playerItemDidReachEnd:(NSNotification *)notification {
AVPlayerItem *item = [notification object];

View File

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

View File

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

View File

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