feat: add loop property for iOS (#3)

This commit is contained in:
Brian Sztamfater 2023-08-15 13:25:28 -03:00 committed by GitHub
parent e213055c51
commit 1327fc622f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 3 deletions

View File

@ -3,5 +3,6 @@
@interface RCT_EXTERN_MODULE(TransparentVideoViewManager, RCTViewManager)
RCT_EXPORT_VIEW_PROPERTY(src, NSDictionary);
RCT_EXPORT_VIEW_PROPERTY(loop, BOOL);
@end

View File

@ -26,6 +26,17 @@ class TransparentVideoView : UIView {
}
}
@objc var loop: Bool = Bool() {
didSet {
// Setup looping on our video
self.playerView?.isLoopingEnabled = loop
let player = self.playerView?.player
if (loop && (player?.rate == 0 || player?.error != nil)) {
player?.play()
}
}
}
func loadVideoPlayer(itemUrl: URL) {
if (self.playerView == nil) {
let playerView = AVPlayerView(frame: CGRect(origin: .zero, size: .zero))
@ -45,9 +56,6 @@ class TransparentVideoView : UIView {
playerLayer.pixelBufferAttributes = [
(kCVPixelBufferPixelFormatTypeKey as String): kCVPixelFormatType_32BGRA]
// Setup looping on our video
playerView.isLoopingEnabled = true
NotificationCenter.default.addObserver(self, selector: #selector(appEnteredBackgound), name: UIApplication.didEnterBackgroundNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(appEnteredForeground), name: UIApplication.willEnterForegroundNotification, object: nil)

View File

@ -6,6 +6,7 @@ import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource'
type TransparentVideoProps = {
style: ViewStyle;
source?: any;
loop?: boolean;
};
const ComponentName = 'TransparentVideoView';
@ -27,6 +28,7 @@ class TransparentVideo extends React.PureComponent<TransparentVideoProps> {
uri,
type: source.type || '',
},
loop: nativeProps.loop ?? true,
});
return <TransparentVideoView {...nativeProps} />;