Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
xugenyuan
2024-10-11 19:38:31 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e7425adee94813ba8738547cd62c55d16d6661a8
e7425ade
1 parent
a77a8c2b
ref |> 文章详情页Web容器复用02
Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
66 additions
and
16 deletions
sight_harmony/commons/wdWebComponent/src/main/ets/pages/NativeCallH5Type.ets
sight_harmony/commons/wdWebComponent/src/main/ets/pages/WdWebLocalComponent.ets
sight_harmony/commons/wdWebComponent/src/main/ets/webPool/WebArticleEventHandler.ets
sight_harmony/commons/wdWebComponent/src/main/ets/webPool/WebLocalPool.ets
sight_harmony/commons/wdWebComponent/src/main/ets/webPool/WebPoolManager.ets
sight_harmony/features/wdComponent/Index.ets
sight_harmony/features/wdComponent/src/main/ets/ComponentModule.ets
sight_harmony/features/wdComponent/src/main/ets/components/ImageAndTextWebComponent.ets
sight_harmony/products/phone/src/main/ets/pages/MainPage.ets
sight_harmony/commons/wdWebComponent/src/main/ets/pages/NativeCallH5Type.ets
View file @
e7425ad
...
...
@@ -26,6 +26,7 @@ export const enum NativeCallH5Event {
export const enum NativeCallH5Type {
jsCall_receiveAppData = 'jsCall_receiveAppData',
jsCall_appNotifyEvent = 'jsCall_appNotifyEvent',
jsCall_clearAppData = 'jsCall_clearAppData',
// TODO 业务自行新增类型,自行调用,例:
// TODO this.webviewControl.callHandle(NativeCallH5Type.jsCall_receiveAppData,xxxx)
...
...
sight_harmony/commons/wdWebComponent/src/main/ets/pages/WdWebLocalComponent.ets
View file @
e7425ad
...
...
@@ -21,7 +21,6 @@ export struct WdWebLocalComponent {
onWebPrepared: () => void = () => {
}
@Prop backVisibility: boolean = false
@Prop webResource: Resource = {} as Resource
@Prop @Watch('onReloadStateChanged') reload: number = 0
@State webHeight: Length = '100%'
@Link isPageEnd: boolean
...
...
sight_harmony/commons/wdWebComponent/src/main/ets/webPool/WebArticleEventHandler.ets
View file @
e7425ad
...
...
@@ -2,6 +2,7 @@ import { BridgeUtil, BridgeWebViewControl, Callback } from "wdJsBridge";
import { Message } from "wdJsBridge/src/main/ets/bean/Message";
import { Logger } from "wdKit";
import { H5CallNativeType } from "../pages/H5CallNativeType";
import { NativeCallH5Type } from "../pages/NativeCallH5Type";
import { WebEvents } from "./WebLocalPool";
const TAG = 'WebArticleEventHandler'
...
...
@@ -20,8 +21,13 @@ export class WebArticleEventHandler implements WebEvents {
//MARK: ----
onPrepareForReuse(): void {
onPrepareForReuse(): boolean {
if (!this.webviewControl || this.pageLoadEnd == false) {
return false
}
this.webviewControl?.callHandle(NativeCallH5Type.jsCall_clearAppData, '', (data) => {
})
return true
}
onPageBegin(event: OnPageBeginEvent): void {
...
...
sight_harmony/commons/wdWebComponent/src/main/ets/webPool/WebLocalPool.ets
View file @
e7425ad
...
...
@@ -109,7 +109,7 @@ export class WebNodeController extends NodeController {
aboutToAppear(): void {
this.webNodeInTree = true;
Logger.debug(TAG, `WebNodeController aboutToAppear target: ${this.target} ==> url:${this.webOption.src}`);
Logger.debug(TAG, `WebNodeController aboutToAppear target: ${this.target} ==> url:${this.webOption.src
.toString()
}`);
}
aboutToDisappear(): void {
...
...
@@ -123,7 +123,7 @@ export class WebNodeController extends NodeController {
// "UTF-8"
// );
// }
Logger.debug(TAG, `WebNodeController aboutToDisappear target: ${this.target} ==> url:${this.webOption.src}`);
Logger.debug(TAG, `WebNodeController aboutToDisappear target: ${this.target} ==> url:${this.webOption.src
.toString()
}`);
} catch (error) {
Logger.error(TAG,`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`);
}
...
...
@@ -152,8 +152,8 @@ export class WebNodeController extends NodeController {
new WebViewPoolData(this.webOption, this.target, this.webHeight, this.webEvents));
}
prepareForReuse() {
this.webEvents?.onPrepareForReuse()
prepareForReuse(): boolean | undefined {
return this.webEvents?.onPrepareForReuse()
}
destoryWeb() {
...
...
@@ -189,7 +189,7 @@ export class WebNodeController extends NodeController {
}
export interface WebEvents {
onPrepareForReuse():
void
onPrepareForReuse():
boolean
onPageBegin(event: OnPageBeginEvent): void;
onPageEnd(event: OnPageEndEvent): void;
onLoadIntercept(event: OnLoadInterceptEvent): boolean;
...
...
sight_harmony/commons/wdWebComponent/src/main/ets/webPool/WebPoolManager.ets
View file @
e7425ad
...
...
@@ -11,6 +11,8 @@ interface ArticleWebInterface {
webArticleEventHandler: WebArticleEventHandler
}
const MAX_POOL_COUNT = 2
export class WebPoolManager {
private webTargets: string[] = []
...
...
@@ -28,12 +30,12 @@ export class WebPoolManager {
createArticleWeb(param: ArticleWebInterface, taking?: boolean) : string {
let target = util.generateRandomUUID()
createReuseableWeb(param.uiContext,
{src: param.webSrc, controller: param.webController},
{src: param.webSrc, controller: param.webController
, renderMode: RenderMode.SYNC_RENDER
},
target,
800,
param.webArticleEventHandler
)
if (taking != true) {
if (taking != true
&& this.webTargets.length < MAX_POOL_COUNT
) {
this.webTargets.push(target)
}
return target
...
...
@@ -43,7 +45,15 @@ export class WebPoolManager {
// 当使用完成,需要调用recycleTarget()
takeAvaiableArticleWebTarget(param: ArticleWebInterface): string {
if (this.webTargets.length) {
return this.webTargets.slice(0, 1).pop()!
let target = this.webTargets.splice(0, 1).pop()!
// 当pool里没有缓存,主动提前加载一个
if (this.webTargets.length == 0) {
setTimeout(() => {
this.createArticleWeb(param)
}, 500)
}
return target
}
return this.createArticleWeb(param, true)
}
...
...
@@ -59,8 +69,14 @@ export class WebPoolManager {
return
}
nodeController.prepareForReuse()
this.webTargets.push(target)
if (this.webTargets.length < MAX_POOL_COUNT) {
if (nodeController.prepareForReuse() == true) {
this.webTargets.push(target)
return
}
}
this.destoryTarget(target)
}
// 撤底销毁
...
...
sight_harmony/features/wdComponent/Index.ets
View file @
e7425ad
...
...
@@ -111,4 +111,6 @@ export { GrayManageModel } from './src/main/ets/viewmodel/GrayManageModel'
export { VoiceInputView } from './src/main/ets/components/comment/view/VoiceInputView'
export { ComponentModule } from './src/main/ets/ComponentModule'
// export {voicese}
\ No newline at end of file
...
...
sight_harmony/features/wdComponent/src/main/ets/ComponentModule.ets
0 → 100644
View file @
e7425ad
import { BridgeUtil, BridgeWebViewControl } from "wdJsBridge";
import { WebArticleEventHandler, WebPoolManager } from "wdWebComponent";
export class ComponentModule {
static preInitArticleWebTemplate(context: UIContext) {
let webviewControl = new BridgeWebViewControl()
WebPoolManager.sharedInstance().createArticleWeb({
uiContext: context,
webSrc: $rawfile("apph5/index.html"),
webController: webviewControl,
webArticleEventHandler: new WebArticleEventHandler(webviewControl)
})
}
}
\ No newline at end of file
...
...
sight_harmony/features/wdComponent/src/main/ets/components/ImageAndTextWebComponent.ets
View file @
e7425ad
...
...
@@ -99,20 +99,24 @@ export struct ImageAndTextWebComponent {
this.webPoolTargetId = WebPoolManager.sharedInstance().takeAvaiableArticleWebTarget({
uiContext: this.getUIContext(),
webSrc: $rawfile(
'apph5/index.html'
),
webSrc: $rawfile(
"apph5/index.html"
),
webController: this.webviewControl,
webArticleEventHandler: new WebArticleEventHandler(this.webviewControl)
})
this.webviewControl = WebPoolManager.sharedInstance().getWebController(this.webPoolTargetId)!
}
aboutToDisappear(): void {
Logger.debug(TAG, 'H5模板加载控件 aboutToDisappear');
WebPoolManager.sharedInstance().recycleTarget(this.webPoolTargetId)
}
build() {
Column() {
WdWebLocalComponent({
webPoolTargetId: this.webPoolTargetId,
webviewControl: this.webviewControl,
reload:this.reload,
webResource: $rawfile('apph5/index.html'),
backVisibility: false,
onWebPrepared: this.onWebPrepared.bind(this),
isPageEnd: $isPageEnd
...
...
sight_harmony/products/phone/src/main/ets/pages/MainPage.ets
View file @
e7425ad
import { LogoutViewModel } from 'wdComponent';
import {
ComponentModule,
LogoutViewModel } from 'wdComponent';
import { GrayManageModel, mournsInfoModel } from 'wdComponent/src/main/ets/viewmodel/GrayManageModel'
import { BreakpointConstants, SpConstants } from 'wdConstant';
...
...
@@ -14,6 +14,8 @@ import { BottomNavigationComponent } from './view/BottomNavigationComponent';
import LaunchDataModel from './viewModel/LaunchDataModel';
import { LaunchPageModel } from './viewModel/LaunchPageModel';
import { JSON } from '@kit.ArkTS';
import { WebArticleEventHandler, WebPoolManager } from 'wdWebComponent';
import { BridgeWebViewControl } from 'wdJsBridge';
const TAG = 'MainPage';
...
...
@@ -60,6 +62,10 @@ struct MainPage {
} catch (e) {
Logger.error(TAG, `Unexpected Text in JSON ??` + JSON.stringify(e) +" " + dataModelStr);
}
setTimeout(() => {
ComponentModule.preInitArticleWebTemplate(this.getUIContext())
}, 500)
}
pageTransition() {
...
...
Please
register
or
login
to post a comment