react-native-video/ios/Video/ReactNativeVideoManager.swift

52 lines
1.2 KiB
Swift
Raw Normal View History

2024-06-25 00:55:32 -06:00
//
// ReactNativeVideoManager.swift
// react-native-video
//
import Foundation
public class ReactNativeVideoManager: RNVPlugin {
private let expectedMaxVideoCount = 2
2024-06-25 00:55:32 -06:00
// create a private initializer
private init() {}
public static let shared: ReactNativeVideoManager = .init()
private var instanceCount = 0
private var pluginList: [RNVPlugin] = Array()
2024-06-25 00:55:32 -06:00
/**
* register a new view
2024-06-25 00:55:32 -06:00
*/
func registerView(newInstance _: RCTVideo) {
if instanceCount > expectedMaxVideoCount {
2024-06-25 00:55:32 -06:00
DebugLog("multiple Video displayed ?")
}
instanceCount += 1
2024-06-25 00:55:32 -06:00
}
/**
* unregister existing view
2024-06-25 00:55:32 -06:00
*/
func unregisterView(newInstance _: RCTVideo) {
instanceCount -= 1
2024-06-25 00:55:32 -06:00
}
/**
* register a new plugin in the managed list
*/
public func registerPlugin(plugin: RNVPlugin) {
pluginList.append(plugin)
return
}
public func onInstanceCreated(id: String, player: Any) {
pluginList.forEach { it in it.onInstanceCreated(id: id, player: player) }
}
public func onInstanceRemoved(id: String, player: Any) {
pluginList.forEach { it in it.onInstanceRemoved(id: id, player: player) }
}
}