react-native-theoplayer
Version:
A THEOplayer video component for react-native.
159 lines (158 loc) • 4 kB
JavaScript
"use strict";
import { NativeModules } from 'react-native';
import NamedColors from './NamedColors.json';
const namedColorsMap = NamedColors;
const NativePlayerModule = NativeModules.THEORCTPlayerModule;
export class TextTrackStyleAdapter {
_backgroundColor = undefined;
_edgeStyle = undefined;
_edgeColor = undefined;
_fontColor = undefined;
_fontFamily = undefined;
_fontSize = undefined;
_fontPath = undefined;
_windowColor = undefined;
_marginBottom = undefined;
_marginTop = undefined;
_marginLeft = undefined;
_marginRight = undefined;
constructor(_view) {
this._view = _view;
}
get backgroundColor() {
return this._backgroundColor;
}
set backgroundColor(color) {
this._backgroundColor = color;
NativePlayerModule.setTextTrackStyle(this._view.nativeHandle, {
backgroundColor: convertColorToRGBA(color)
});
}
get edgeStyle() {
return this._edgeStyle;
}
set edgeStyle(style) {
this._edgeStyle = style;
NativePlayerModule.setTextTrackStyle(this._view.nativeHandle, {
edgeStyle: style
});
}
get edgeColor() {
return this._edgeColor;
}
set edgeColor(color) {
this._edgeColor = color;
NativePlayerModule.setTextTrackStyle(this._view.nativeHandle, {
edgeColor: convertColorToRGBA(color)
});
}
get fontColor() {
return this._fontColor;
}
set fontColor(color) {
this._fontColor = color;
NativePlayerModule.setTextTrackStyle(this._view.nativeHandle, {
fontColor: convertColorToRGBA(color)
});
}
get fontFamily() {
return this._fontFamily;
}
set fontFamily(family) {
this._fontFamily = family;
NativePlayerModule.setTextTrackStyle(this._view.nativeHandle, {
fontFamily: family
});
}
get fontPath() {
return this._fontPath;
}
set fontPath(path) {
this._fontPath = path;
NativePlayerModule.setTextTrackStyle(this._view.nativeHandle, {
fontPath: path
});
}
get fontSize() {
return this._fontSize;
}
set fontSize(size) {
this._fontSize = size;
NativePlayerModule.setTextTrackStyle(this._view.nativeHandle, {
fontSize: fromPercentage(size)
});
}
get windowColor() {
return this._windowColor;
}
set windowColor(color) {
this._windowColor = color;
NativePlayerModule.setTextTrackStyle(this._view.nativeHandle, {
windowColor: convertColorToRGBA(color)
});
}
get marginBottom() {
return this._marginBottom;
}
set marginBottom(margin) {
this._marginBottom = margin;
NativePlayerModule.setTextTrackStyle(this._view.nativeHandle, {
marginBottom: margin
});
}
get marginLeft() {
return this._marginLeft;
}
set marginLeft(margin) {
this._marginLeft = margin;
NativePlayerModule.setTextTrackStyle(this._view.nativeHandle, {
marginLeft: margin
});
}
get marginRight() {
return this._marginRight;
}
set marginRight(margin) {
this._marginRight = margin;
NativePlayerModule.setTextTrackStyle(this._view.nativeHandle, {
marginRight: margin
});
}
get marginTop() {
return this._marginTop;
}
set marginTop(margin) {
this._marginTop = margin;
NativePlayerModule.setTextTrackStyle(this._view.nativeHandle, {
marginTop: margin
});
}
}
function convertColorToRGBA(color) {
if (!color) {
return null;
}
color = color.replace('#', '');
if (namedColorsMap[color.toLowerCase()]) {
color = namedColorsMap[color.toLowerCase()];
}
const colorPattern = /^(?:#|0x)?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i;
const match = color.match(colorPattern);
if (!match) {
return null;
}
const r = parseInt(match[1], 16);
const g = parseInt(match[2], 16);
const b = parseInt(match[3], 16);
const a = match[4] ? parseInt(match[4], 16) : 255;
return {
r,
g,
b,
a
};
}
function fromPercentage(pct) {
return pct ? parseFloat(pct) : 100;
}
//# sourceMappingURL=TextTrackStyleAdapter.js.map