@hyext-beyond/hy-ui-native
Version:
A native lib polyfill for huya miniapp
65 lines • 1.79 kB
JavaScript
import React, { useEffect, useRef } from "react";
import ReactDOM from "react-dom";
import { StyleSheet, View } from "react-native";
import Vap from "video-animation-player";
var hash = 1;
export function VapVideoAnimated(props) {
// 这里 props 先不用 ref 寄存了 除了src
var src = props.src,
loop = props.loop,
onEnd = props.onEnd,
onStart = props.onStart,
onError = props.onError,
onFrameChange = props.onFrameChange,
style = props.style,
config = props.config;
var ref = useRef(null);
var _ref = StyleSheet.flatten(style) || {},
width = _ref.width,
height = _ref.height;
useEffect(function () {
if (src == null || src == '') {
console.error("VideoAnimated >>> 请输入props.src");
return;
}
if (ref.current == null) {
console.error("VideoAnimated >>> ref.current 未被正确初始化");
return;
}
var view = ref.current;
var vap = new Vap({
container: ReactDOM.findDOMNode(view),
config: config,
width: width,
height: height,
type: hash++,
loop: loop,
onLoadError: onError,
accurate: true,
src: src
});
onStart && vap.on('play', onStart);
onEnd && vap.on('ended', onEnd);
onFrameChange && vap.on('frame', onFrameChange);
vap.play();
return function () {
// resources 存在证明初始化成功
vap.resources && vap.destroy();
};
}, [src, width, height]);
return /*#__PURE__*/React.createElement(View, {
style: style,
ref: ref
});
}
export function VideoAnimated() {
return null;
}
export function NormalVideoAnimated() {
return null;
}
export default {
VideoAnimated: VideoAnimated,
VapVideoAnimated: VapVideoAnimated,
NormalVideoAnimated: NormalVideoAnimated
};