react-native-transparent-video/ios/TransparentVideoViewManager.swift

37 lines
911 B
Swift
Raw Normal View History

@objc(TransparentVideoViewManager)
class TransparentVideoViewManager: RCTViewManager {
override func view() -> (TransparentVideoView) {
return TransparentVideoView()
}
@objc override static func requiresMainQueueSetup() -> Bool {
return false
}
}
class TransparentVideoView : UIView {
@objc var color: String = "" {
didSet {
self.backgroundColor = hexStringToUIColor(hexColor: color)
}
}
func hexStringToUIColor(hexColor: String) -> UIColor {
let stringScanner = Scanner(string: hexColor)
if(hexColor.hasPrefix("#")) {
stringScanner.scanLocation = 1
}
var color: UInt32 = 0
stringScanner.scanHexInt32(&color)
let r = CGFloat(Int(color >> 16) & 0x000000FF)
let g = CGFloat(Int(color >> 8) & 0x000000FF)
let b = CGFloat(Int(color) & 0x000000FF)
return UIColor(red: r / 255.0, green: g / 255.0, blue: b / 255.0, alpha: 1)
}
}