Skip to content

Commit

Permalink
Added FilterType.js with all filters that do not require extra parame…
Browse files Browse the repository at this point in the history
…ters
  • Loading branch information
nickgzzjr committed Nov 6, 2018
1 parent 40fb19f commit 22d65ad
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
18 changes: 18 additions & 0 deletions FilterType.js
Original file line number Diff line number Diff line change
@@ -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'
};
26 changes: 21 additions & 5 deletions Video.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -11,7 +12,7 @@ const styles = StyleSheet.create({
},
});

export { TextTrackType };
export { TextTrackType, FilterType };

export default class Video extends Component {

Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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([
Expand Down
18 changes: 4 additions & 14 deletions ios/Video/RCTVideo.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ @implementation RCTVideo
BOOL _fullscreen;
NSString * _fullscreenOrientation;
BOOL _fullscreenPlayerPresented;
NSString *_filter;
NSString *_filterName;
UIViewController * _presentingViewController;
#if __has_include(<react-native-video/RCTVideoCache.h>)
RCTVideoCache * _videoCache;
Expand Down Expand Up @@ -862,7 +862,7 @@ - (void)applyModifiers
[self setResizeMode:_resizeMode];
[self setRepeat:_repeat];
[self setPaused:_paused];
[self setFilter:_filter];
[self setFilter:_filterName];
[self setControls:_controls];
[self setAllowsExternalPlayback:_allowsExternalPlayback];
}
Expand Down Expand Up @@ -1254,24 +1254,14 @@ - (void)videoPlayerViewControllerDidDismiss:(AVPlayerViewController *)playerView
}
}

- (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
Expand Down

0 comments on commit 22d65ad

Please sign in to comment.