-
Notifications
You must be signed in to change notification settings - Fork 9
/
App.js
70 lines (63 loc) · 1.91 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React, { useEffect, useRef } from "react";
import { StatusBar } from "expo-status-bar";
import { StyleSheet, View, Text } from "react-native";
import { WebView } from "react-native-webview";
const styles = StyleSheet.create({
container: {
flex: 1,
},
fullScreen: {
flex: 1,
},
});
export default function App() {
const webviewRef = useRef(null);
useEffect(() => {
// 加载时的操作,比如设置 WebView
return () => {
// 组件卸载时的清理操作
if (webviewRef.current) {
webviewRef.current.stopLoading(); // 停止加载
// 进行其他必要的清理
}
};
}, []);
handleLoad = () => {
const INJECTED_JAVASCRIPT = `(function() {
setTimeout(()=>{
var videoPlayerDiv = document.querySelector("#video");
if (videoPlayerDiv) {
videoPlayerDiv.style.width = '100vw';
videoPlayerDiv.style.height = '98vh';
videoPlayerDiv.style.position = 'fixed';
videoPlayerDiv.style.top = '0';
videoPlayerDiv.style.left = '0';
videoPlayerDiv.style.zIndex = '9999';
}
},10000)})();`;
if (webviewRef.current) {
webviewRef.current.injectJavaScript(INJECTED_JAVASCRIPT);
}
};
return (
<View style={styles.container}>
<StatusBar style="auto" />
<WebView
style={styles.fullScreen}
source={{
uri: "https://www.gdtv.cn/tvChannelDetail/44",
headers: {
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
},
}}
mediaPlaybackRequiresUserAction={false}
ref={webviewRef}
onLoad={this.handleLoad}
allowsFullscreenVideo
javaScriptEnabled={true}
domStorageEnabled={true}
/>
</View>
);
}