1 // Copyright 2022-present 650 Industries. All rights reserved.
2 
3 import ExpoModulesCore
4 import AVFoundation
5 
6 public final class VideoViewModule: Module {
definitionnull7   public func definition() -> ModuleDefinition {
8     Name("ExpoVideoView")
9 
10     Constants([
11       "ScaleNone": AVLayerVideoGravity.resizeAspect,
12       "ScaleToFill": AVLayerVideoGravity.resize,
13       "ScaleAspectFit": AVLayerVideoGravity.resizeAspect,
14       "ScaleAspectFill": AVLayerVideoGravity.resizeAspectFill
15     ])
16 
17     AsyncFunction("setFullscreen") { (viewTag: Int, value: Bool, promise: Promise) in
18       self.runBlockForView(viewTag) { view in
19         view.setFullscreen(value, resolver: promise.resolver, rejecter: promise.legacyRejecter)
20       }
21     }
22 
23     View(EXVideoView.self) {
24       Events(
25         "onStatusUpdate",
26         "onLoadStart",
27         "onLoad",
28         "onError",
29         "onReadyForDisplay",
30         "onFullscreenUpdate"
31       )
32 
33       Prop("status") { (view: EXVideoView, status: [String: Any]) in
34         view.status = status
35       }
36 
37       Prop("useNativeControls") { (view: EXVideoView, useNativeControls: Bool) in
38         view.useNativeControls = useNativeControls
39       }
40 
41       Prop("source") { (view: EXVideoView, source: [String: Any]) in
42         view.source = source
43       }
44 
45       Prop("resizeMode") { (view: EXVideoView, resizeMode: String) in
46         view.nativeResizeMode = resizeMode
47       }
48     }
49   }
50 
51   private func runBlockForView(_ tag: Int, _ block: @escaping (EXVideoView) -> Void) {
52     let uiManager: EXUIManager? = appContext?.legacyModule(implementing: EXUIManager.self)
53 
54     uiManager?.executeUIBlock({ (view: Any) in
55       if let view = view as? EXVideoView {
56         block(view)
57       }
58     }, forView: tag, of: EXVideoView.self)
59   }
60 }
61