Showing
4 changed files
with
43 additions
and
2 deletions
| 1 | + | ||
| 2 | +export interface eventParams { | ||
| 3 | + event: string; | ||
| 4 | +} | ||
| 5 | + | ||
| 6 | +export const enum NativeCallH5Event { | ||
| 7 | + NativeCallH5EventPageWillAppear = '1', | ||
| 8 | + NativeCallH5EventPageWillDisAppear = '2', | ||
| 9 | + NativeCallH5EventAppWillEnterForeground = '3', | ||
| 10 | + NativeCallH5EventAppEnterBackground = '4', | ||
| 11 | + NativeCallH5EventAppPlayingAudio = '5', | ||
| 12 | + NativeCallH5EventUpdateBrowseCount = '6', | ||
| 13 | + NativeCallH5EventStartLoadingOnReuse = '7', | ||
| 14 | + | ||
| 15 | + NativeCallH5EventNightModel = '9', | ||
| 16 | + NativeCallH5EventFontSizesChange = '10', | ||
| 17 | + NativeCallH5EventFollowEvent = '11', | ||
| 18 | + NativeCallH5EventLikeEvent = '12' | ||
| 19 | + | ||
| 20 | +} | ||
| 21 | + | ||
| 1 | /** | 22 | /** |
| 2 | * native调用h5,事件id枚举 | 23 | * native调用h5,事件id枚举 |
| 3 | * app主动调用h5方法 | 24 | * app主动调用h5方法 |
| 4 | */ | 25 | */ |
| 5 | export const enum NativeCallH5Type { | 26 | export const enum NativeCallH5Type { |
| 6 | jsCall_receiveAppData = 'jsCall_receiveAppData', | 27 | jsCall_receiveAppData = 'jsCall_receiveAppData', |
| 28 | + jsCall_appNotifyEvent = 'jsCall_appNotifyEvent', | ||
| 7 | // TODO 业务自行新增类型,自行调用,例: | 29 | // TODO 业务自行新增类型,自行调用,例: |
| 8 | // TODO this.webviewControl.callHandle(NativeCallH5Type.jsCall_receiveAppData,xxxx) | 30 | // TODO this.webviewControl.callHandle(NativeCallH5Type.jsCall_receiveAppData,xxxx) |
| 9 | 31 |
| @@ -4,8 +4,9 @@ import { Logger, WindowModel } from 'wdKit/Index'; | @@ -4,8 +4,9 @@ import { Logger, WindowModel } from 'wdKit/Index'; | ||
| 4 | import { performJSCallNative } from './JsBridgeBiz'; | 4 | import { performJSCallNative } from './JsBridgeBiz'; |
| 5 | import { H5CallNativeType } from './H5CallNativeType'; | 5 | import { H5CallNativeType } from './H5CallNativeType'; |
| 6 | import { Message } from 'wdJsBridge/src/main/ets/bean/Message'; | 6 | import { Message } from 'wdJsBridge/src/main/ets/bean/Message'; |
| 7 | -import { DateTimeUtils } from 'wdKit' | 7 | +import { DateTimeUtils,EmitterUtils,EmitterEventId } from 'wdKit' |
| 8 | import { window } from '@kit.ArkUI'; | 8 | import { window } from '@kit.ArkUI'; |
| 9 | +import { NativeCallH5Type,NativeCallH5Event,eventParams } from './NativeCallH5Type'; | ||
| 9 | 10 | ||
| 10 | const TAG = 'WdWebLocalComponent'; | 11 | const TAG = 'WdWebLocalComponent'; |
| 11 | 12 | ||
| @@ -183,6 +184,7 @@ export struct WdWebLocalComponent { | @@ -183,6 +184,7 @@ export struct WdWebLocalComponent { | ||
| 183 | private defaultPerformJSCallNative: (data: Message, f: Callback) => void = (data: Message, f: Callback) => { | 184 | private defaultPerformJSCallNative: (data: Message, f: Callback) => void = (data: Message, f: Callback) => { |
| 184 | performJSCallNative(data, f) | 185 | performJSCallNative(data, f) |
| 185 | } | 186 | } |
| 187 | + | ||
| 186 | onPageBegin: (url?: string) => void = () => { | 188 | onPageBegin: (url?: string) => void = () => { |
| 187 | Logger.debug(TAG, 'onPageBegin'); | 189 | Logger.debug(TAG, 'onPageBegin'); |
| 188 | this.registerHandlers(); | 190 | this.registerHandlers(); |
| @@ -228,6 +230,17 @@ export struct WdWebLocalComponent { | @@ -228,6 +230,17 @@ export struct WdWebLocalComponent { | ||
| 228 | } | 230 | } |
| 229 | } | 231 | } |
| 230 | 232 | ||
| 233 | + aboutToAppear(): void { | ||
| 234 | + EmitterUtils.receiveEvent(EmitterEventId.APP_PAGE_SHOW, () => { | ||
| 235 | + Logger.info(TAG, 'APP_PAGE_SHOW'); | ||
| 236 | + let params = {'event':NativeCallH5Event.NativeCallH5EventPageWillAppear} as eventParams; | ||
| 237 | + let jsonString = JSON.stringify(params); | ||
| 238 | + this.webviewControl.callHandle(NativeCallH5Type.jsCall_appNotifyEvent, jsonString, (data: string) => { | ||
| 239 | + Logger.debug(TAG, "from js data = " + data); | ||
| 240 | + }) | ||
| 241 | + }) | ||
| 242 | + } | ||
| 243 | + | ||
| 231 | @Builder | 244 | @Builder |
| 232 | videoComp(){ | 245 | videoComp(){ |
| 233 | Video({ | 246 | Video({ |
| 1 | import { Action } from 'wdBean'; | 1 | import { Action } from 'wdBean'; |
| 2 | import { ImageAndTextPageComponent } from 'wdComponent' | 2 | import { ImageAndTextPageComponent } from 'wdComponent' |
| 3 | -import { Logger } from 'wdKit' | 3 | +import { Logger,EmitterUtils,EmitterEventId } from 'wdKit' |
| 4 | import router from '@ohos.router'; | 4 | import router from '@ohos.router'; |
| 5 | import { TrackConstants } from 'wdTracking/Index'; | 5 | import { TrackConstants } from 'wdTracking/Index'; |
| 6 | 6 | ||
| @@ -47,6 +47,7 @@ struct ImageAndTextDetailPage { | @@ -47,6 +47,7 @@ struct ImageAndTextDetailPage { | ||
| 47 | 47 | ||
| 48 | onPageShow() { | 48 | onPageShow() { |
| 49 | this.pageShow = Math.random() | 49 | this.pageShow = Math.random() |
| 50 | + EmitterUtils.sendEmptyEvent(EmitterEventId.APP_PAGE_SHOW) | ||
| 50 | Logger.info(TAG, 'onPageShow'); | 51 | Logger.info(TAG, 'onPageShow'); |
| 51 | } | 52 | } |
| 52 | 53 |
-
Please register or login to post a comment