Skip to content

Commit

Permalink
Update header paths to be compatible pre and post RN 0.40
Browse files Browse the repository at this point in the history
  • Loading branch information
pablocarrillo committed Mar 3, 2017
1 parent 01c1124 commit 900ee25
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 36 deletions.
8 changes: 7 additions & 1 deletion ios/RCTVideo.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#if __has_include(<React/RCTView.h>)
#import <React/RCTView.h>
#elif __has_include("React/RCTView.h")
#import "React/RCTView.h"
#elif __has_include("RCTView.h")
#import "RCTView.h"
#endif

#import <AVFoundation/AVFoundation.h>
#import "AVKit/AVKit.h"
#import "UIView+FindUIViewController.h"
Expand All @@ -16,7 +23,6 @@
@property (nonatomic, copy) RCTBubblingEventBlock onVideoProgress;
@property (nonatomic, copy) RCTBubblingEventBlock onVideoSeek;
@property (nonatomic, copy) RCTBubblingEventBlock onVideoEnd;
@property (nonatomic, copy) RCTBubblingEventBlock onTimedMetadata;
@property (nonatomic, copy) RCTBubblingEventBlock onVideoFullscreenPlayerWillPresent;
@property (nonatomic, copy) RCTBubblingEventBlock onVideoFullscreenPlayerDidPresent;
@property (nonatomic, copy) RCTBubblingEventBlock onVideoFullscreenPlayerWillDismiss;
Expand Down
50 changes: 17 additions & 33 deletions ios/RCTVideo.m
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
#import <React/RCTConvert.h>
#import "RCTVideo.h"

#if __has_include(<React/RCTConvert.h>)
#import <React/RCTBridgeModule.h>
#import <React/RCTEventDispatcher.h>
#import <React/UIView+React.h>
#import <React/RCTConvert.h>
#elif __has_include("React/RCTConvert.h")
#import "React/RCTBridgeModule.h"
#import "React/RCTEventDispatcher.h"
#import "React/UIView+React.h"
#import "React/RCTConvert.h"
#elif __has_include("RCTConvert.h")
#import "RCTConvert.h"
#import "RCTBridgeModule.h"
#import "RCTEventDispatcher.h"
#import "UIView+React.h"
#endif

#import "RCTVideo.h"


static NSString *const statusKeyPath = @"status";
static NSString *const playbackLikelyToKeepUpKeyPath = @"playbackLikelyToKeepUp";
static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty";
static NSString *const readyForDisplayKeyPath = @"readyForDisplay";
static NSString *const playbackRate = @"rate";
static NSString *const timedMetadata = @"timedMetadata";

@implementation RCTVideo
{
Expand Down Expand Up @@ -227,7 +241,6 @@ - (void)addPlayerItemObservers
[_playerItem addObserver:self forKeyPath:statusKeyPath options:0 context:nil];
[_playerItem addObserver:self forKeyPath:playbackBufferEmptyKeyPath options:0 context:nil];
[_playerItem addObserver:self forKeyPath:playbackLikelyToKeepUpKeyPath options:0 context:nil];
[_playerItem addObserver:self forKeyPath:timedMetadata options:NSKeyValueObservingOptionNew context:nil];
_playerItemObserversSet = YES;
}

Expand All @@ -240,7 +253,6 @@ - (void)removePlayerItemObservers
[_playerItem removeObserver:self forKeyPath:statusKeyPath];
[_playerItem removeObserver:self forKeyPath:playbackBufferEmptyKeyPath];
[_playerItem removeObserver:self forKeyPath:playbackLikelyToKeepUpKeyPath];
[_playerItem removeObserver:self forKeyPath:timedMetadata];
_playerItemObserversSet = NO;
}
}
Expand Down Expand Up @@ -321,34 +333,6 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
{
if (object == _playerItem) {

// When timeMetadata is read the event onTimedMetadata is triggered
if ([keyPath isEqualToString: timedMetadata])
{


NSArray<AVMetadataItem *> *items = [change objectForKey:@"new"];
if (items && ![items isEqual:[NSNull null]] && items.count > 0) {

NSMutableArray *array = [NSMutableArray new];
for (AVMetadataItem *item in items) {

NSString *value = item.value;
NSString *identifier = item.identifier;

if (![value isEqual: [NSNull null]]) {
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjects:@[value, identifier] forKeys:@[@"value", @"identifier"]];

[array addObject:dictionary];
}
}

self.onTimedMetadata(@{
@"target": self.reactTag,
@"metadata": array
});
}
}

if ([keyPath isEqualToString:statusKeyPath]) {
// Handle player item status change.
if (_playerItem.status == AVPlayerItemStatusReadyToPlay) {
Expand Down
2 changes: 2 additions & 0 deletions ios/RCTVideo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../../react-native/React/**",
);
LIBRARY_SEARCH_PATHS = "$(inherited)";
OTHER_LDFLAGS = "-ObjC";
Expand All @@ -234,6 +235,7 @@
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../../react-native/React/**",
);
LIBRARY_SEARCH_PATHS = "$(inherited)";
OTHER_LDFLAGS = "-ObjC";
Expand Down
7 changes: 6 additions & 1 deletion ios/RCTVideoManager.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#if __has_include(<React/RCTViewManager.h>)
#import <React/RCTViewManager.h>

#elif __has_include("React/RCTViewManager.h")
#import "React/RCTViewManager.h"
#elif __has_include("RCTViewManager.h")
#import "RCTViewManager.h"
#endif
@interface RCTVideoManager : RCTViewManager

@end
7 changes: 6 additions & 1 deletion ios/RCTVideoManager.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#import "RCTVideoManager.h"
#import "RCTVideo.h"
#if __has_include(<React/RCTBridge.h>)
#import <React/RCTBridge.h>
#elif __has_include("React/RCTBridge.h")
#import "React/RCTBridge.h"
#elif __has_include("RCTBridge.h")
#import "RCTBridge.h"
#endif
#import <AVFoundation/AVFoundation.h>

@implementation RCTVideoManager
Expand Down Expand Up @@ -41,7 +47,6 @@ - (dispatch_queue_t)methodQueue
RCT_EXPORT_VIEW_PROPERTY(onVideoProgress, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onVideoSeek, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onVideoEnd, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onTimedMetadata, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onVideoFullscreenPlayerWillPresent, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onVideoFullscreenPlayerDidPresent, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onVideoFullscreenPlayerWillDismiss, RCTBubblingEventBlock);
Expand Down

0 comments on commit 900ee25

Please sign in to comment.