File tree Expand file tree Collapse file tree 5 files changed +26
-13
lines changed
com.msgbyte.webview/src/group Expand file tree Collapse file tree 5 files changed +26
-13
lines changed Original file line number Diff line number Diff line change 11import { regCustomPanel } from '@capital/common' ;
2+ import { WebviewKeepAlive } from '@capital/component' ;
23import React from 'react' ;
34import { Translate } from './translate' ;
45
@@ -10,6 +11,9 @@ regCustomPanel({
1011 label : Translate . panelName ,
1112 icon : 'mdi:radio-tower' ,
1213 render : ( ) => (
13- < iframe className = "w-full h-full bg-white" src = "https://snapdrop.net/" />
14+ < WebviewKeepAlive
15+ className = "w-full h-full bg-white"
16+ url = "https://snapdrop.net/"
17+ />
1418 ) ,
1519} ) ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { encode } from 'js-base64';
33import { isValidStr } from '@capital/common' ;
44import { Translate } from '../translate' ;
55import { sanitize } from 'script_sanitize' ;
6+ import { WebviewKeepAlive } from '@capital/component' ;
67
78function getInjectedStyle ( ) {
89 try {
@@ -25,7 +26,7 @@ const GroupCustomWebPanelRender: React.FC<{ panelInfo: any }> = (props) => {
2526 }
2627
2728 const html = panelInfo ?. meta ?. html ;
28- const src = useMemo ( ( ) => {
29+ const url = useMemo ( ( ) => {
2930 if ( isValidStr ( html ) ) {
3031 const appendHtml = getInjectedStyle ( ) ; // 额外追加的样式
3132 try {
@@ -40,7 +41,7 @@ const GroupCustomWebPanelRender: React.FC<{ panelInfo: any }> = (props) => {
4041 }
4142 } , [ html ] ) ;
4243
43- return < iframe className = "w-full h-full" src = { src } /> ;
44+ return < WebviewKeepAlive className = "w-full h-full" url = { url } /> ;
4445} ;
4546GroupCustomWebPanelRender . displayName = 'GroupCustomWebPanelRender' ;
4647
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import { Translate } from '../translate' ;
3- import { Webview } from '@capital/component' ;
3+ import { WebviewKeepAlive } from '@capital/component' ;
44
55const GroupWebPanelRender : React . FC < { panelInfo : any } > = ( props ) => {
66 const panelInfo = props . panelInfo ;
@@ -11,7 +11,9 @@ const GroupWebPanelRender: React.FC<{ panelInfo: any }> = (props) => {
1111
1212 const url = panelInfo ?. meta ?. url ;
1313
14- return < Webview key = { String ( url ) } className = "w-full h-full" url = { url } /> ;
14+ return (
15+ < WebviewKeepAlive key = { String ( url ) } className = "w-full h-full" url = { url } />
16+ ) ;
1517} ;
1618GroupWebPanelRender . displayName = 'GroupWebPanelRender' ;
1719
Original file line number Diff line number Diff line change @@ -10,11 +10,17 @@ interface WebviewProps {
1010/**
1111 * 网页渲染容器
1212 */
13- export const Webview : React . FC < WebviewProps > =
14- withKeepAliveOverlay < WebviewProps > (
15- ( props ) => {
16- return < iframe className = "w-full h-full bg-white" src = { props . url } /> ;
17- } ,
18- { cacheId : ( props ) => props . url }
19- ) ;
13+ export const Webview : React . FC < WebviewProps > = ( props ) => {
14+ return < iframe className = "w-full h-full" src = { props . url } /> ;
15+ } ;
2016Webview . displayName = 'Webview' ;
17+
18+ /**
19+ * 带缓存的网页渲染容器
20+ * 用于需要在切换时依旧保持加载的case
21+ */
22+ export const WebviewKeepAlive : React . FC < WebviewProps > =
23+ withKeepAliveOverlay < WebviewProps > ( Webview , {
24+ cacheId : ( props ) => props . url ,
25+ } ) ;
26+ WebviewKeepAlive . displayName = 'WebviewKeepAlive' ;
Original file line number Diff line number Diff line change @@ -56,4 +56,4 @@ export { ErrorBoundary } from '@/components/ErrorBoundary';
5656export { UserAvatar } from '@/components/UserAvatar' ;
5757export { UserName } from '@/components/UserName' ;
5858export { Markdown } from '@/components/Markdown' ;
59- export { Webview } from '@/components/Webview' ;
59+ export { Webview , WebviewKeepAlive } from '@/components/Webview' ;
You can’t perform that action at this time.
0 commit comments