diff --git a/FilterType.js b/FilterType.js new file mode 100644 index 00000000..bd477d73 --- /dev/null +++ b/FilterType.js @@ -0,0 +1,18 @@ +export default { + NONE: '', + INVERT: 'CIColorInvert', + MONOCHROME: 'CIColorMonochrome', + POSTERIZE: 'CIColorPosterize', + FALSE: 'CIFalseColor', + MAXIMUMCOMPONENT: 'CIMaximumComponent', + MINIMUMCOMPONENT: 'CIMinimumComponent', + CHROME: 'CIPhotoEffectChrome', + FADE: 'CIPhotoEffectFade', + INSTANT: 'CIPhotoEffectInstant', + MONO: 'CIPhotoEffectMono', + NOIR: 'CIPhotoEffectNoir', + PROCESS: 'CIPhotoEffectProcess', + TONAL: 'CIPhotoEffectTonal', + TRANSFER: 'CIPhotoEffectTransfer', + SEPIA: 'CISepiaTone' +}; diff --git a/Video.js b/Video.js index daccb171..143272a3 100644 --- a/Video.js +++ b/Video.js @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'; import {StyleSheet, requireNativeComponent, NativeModules, View, ViewPropTypes, Image, Platform, findNodeHandle} from 'react-native'; import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource'; import TextTrackType from './TextTrackType'; +import FilterType from './FilterType'; import VideoResizeMode from './VideoResizeMode.js'; const styles = StyleSheet.create({ @@ -11,7 +12,7 @@ const styles = StyleSheet.create({ }, }); -export { TextTrackType }; +export { TextTrackType, FilterType }; export default class Video extends Component { @@ -71,7 +72,7 @@ export default class Video extends Component { this.setNativeProps({ fullscreen: false }); }; - saveAsync = async (options?) => { + save = async (options?) => { return await NativeModules.VideoManager.save(options, findNodeHandle(this._root)); } @@ -278,10 +279,25 @@ export default class Video extends Component { } } -Video.filterTypes = ['Normal', 'Country', 'Winter', 'Black N White', 'Sunrise', 'Artistic']; - Video.propTypes = { - filter: PropTypes.oneOf(Video.filterTypes), + filter: PropTypes.oneOf([ + FilterType.NONE, + FilterType.INVERT, + FilterType.MONOCHROME, + FilterType.POSTERIZE, + FilterType.FALSE, + FilterType.MAXIMUMCOMPONENT, + FilterType.MINIMUMCOMPONENT, + FilterType.CHROME, + FilterType.FADE, + FilterType.INSTANT, + FilterType.MONO, + FilterType.NOIR, + FilterType.PROCESS, + FilterType.TONAL, + FilterType.TRANSFER, + FilterType.SEPIA + ]), /* Native only */ src: PropTypes.object, seek: PropTypes.oneOfType([ diff --git a/ios/Video/RCTVideo.m b/ios/Video/RCTVideo.m index 4ea431d3..b5a26c3b 100644 --- a/ios/Video/RCTVideo.m +++ b/ios/Video/RCTVideo.m @@ -66,7 +66,7 @@ static int const RCTVideoUnset = -1; BOOL _fullscreen; NSString * _fullscreenOrientation; BOOL _fullscreenPlayerPresented; - NSString *_filter; + NSString *_filterName; UIViewController * _presentingViewController; #if __has_include() RCTVideoCache * _videoCache; @@ -862,7 +862,7 @@ static int const RCTVideoUnset = -1; [self setResizeMode:_resizeMode]; [self setRepeat:_repeat]; [self setPaused:_paused]; - [self setFilter:_filter]; + [self setFilter:_filterName]; [self setControls:_controls]; [self setAllowsExternalPlayback:_allowsExternalPlayback]; } @@ -1254,24 +1254,14 @@ static int const RCTVideoUnset = -1; } } -- (void)setFilter:(NSString *)filter { +- (void)setFilter:(NSString *)filterName { - _filter = filter; + _filterName = filterName; AVAsset *asset = _playerItem.asset; if (asset != nil) { - NSDictionary *filters = @{ - @"Normal": @"", - @"Country": @"CISepiaTone", - @"Winter": @"CIPhotoEffectProcess", - @"Black N White": @"CIPhotoEffectNoir", - @"Sunrise": @"CIPhotoEffectTransfer", - @"Artistic": @"CIColorPosterize", - }; - - NSString *filterName = filters[filter]; CIFilter *filter = [CIFilter filterWithName:filterName]; _playerItem.videoComposition = [AVVideoComposition