Skip to content
This repository was archived by the owner on Nov 27, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions harmony/rn_webview/hvigorfile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
import { harTasks } from '@ohos/hvigor-ohos-plugin';

export default {
system: harTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
}
export { harTasks } from '@ohos/hvigor-ohos-plugin';
7 changes: 4 additions & 3 deletions harmony/rn_webview/index.ets
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
/**
* MIT License
*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Copyright (C) 2024 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -22,5 +22,6 @@
* SOFTWARE.
*/

export * from './src/main/ets/WebView'
export * from './src/main/ets/RNCWebView'

export * from './ts'
4 changes: 2 additions & 2 deletions harmony/rn_webview/oh-package.json5
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"devDependencies": {
},
"author": "",
"name": "@react-native-oh-tpl/react-native-webview",
"name": "rn_webview",
"description": "main cpai architecture",
"main": "index.ets",
"version": "13.6.3-0.1.4",
"dependencies": {
"@rnoh/react-native-openharmony": "file:../react_native_openharmony"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
/**
* MIT License
*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Copyright (C) 2024 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -22,11 +22,11 @@
* SOFTWARE.
*/

import { Descriptor, ComponentBuilderContext, RNOHContext, ViewBaseProps } from '@rnoh/react-native-openharmony'
import { Descriptor, RNOHContext, ViewBaseProps } from '@rnoh/react-native-openharmony';
import webview from '@ohos.web.webview';
import { CallbackState, ShouldRequestUrl } from './ShouldRequestUrl';
import { RNViewBase } from '@rnoh/react-native-openharmony';
import Logger from './Logger'
import { RNC } from '@rnoh/react-native-openharmony/generated';
import Logger from './Logger';

export class WebViewNewSource {
uri: string | Resource = ""
Expand Down Expand Up @@ -83,7 +83,8 @@ export class WebViewEventParams {
export type WebViewViewDescriptor = Descriptor<"RNCWebView", WebViewProps>

@Component
export struct WebView {
export struct RNCWebView {
public static readonly NAME = RNC.RNCWebView.NAME
ctx!: RNOHContext
tag: number = 0
@State descriptor: WebViewViewDescriptor = {} as WebViewViewDescriptor
Expand Down Expand Up @@ -117,7 +118,8 @@ export struct WebView {
(newDescriptor) => {
this.descriptor = (newDescriptor as WebViewViewDescriptor)
Logger.debug(TAG, `[RNOH] newDescriptor props uri, ${JSON.stringify(this.descriptor.props.newSource.uri)}`);
this.cacheMode = this.descriptor.props.cacheEnabled ? this.transCacheMode(this.descriptor.props.cacheMode) : CacheMode.Online;
this.cacheMode =
this.descriptor.props.cacheEnabled ? this.transCacheMode(this.descriptor.props.cacheMode) : CacheMode.Online;
this.javaScriptEnable = this.descriptor.props.javaScriptEnabled;
this.source = this.descriptor.props.newSource
if (this.html != "" && this.html != this.source.html) {
Expand Down Expand Up @@ -147,7 +149,8 @@ export struct WebView {
)
webview.WebviewController.setWebDebuggingAccess(this.descriptor.props.webviewDebuggingEnabled)
this.javaScriptEnable = this.descriptor.props.javaScriptEnabled;
this.cacheMode = this.descriptor.props.cacheEnabled ? this.transCacheMode(this.descriptor.props.cacheMode) : CacheMode.Online;
this.cacheMode =
this.descriptor.props.cacheEnabled ? this.transCacheMode(this.descriptor.props.cacheMode) : CacheMode.Online;
this.source = this.descriptor.props.newSource
this.html = this.source.html
this.url = this.source.uri;
Expand Down Expand Up @@ -249,7 +252,7 @@ export struct WebView {
break
case "postMessage":
Logger.debug(TAG, `[RNOH] postMessage,${JSON.stringify(args)}`)
let data = JSON.stringify({data : args[0]})
let data = JSON.stringify({ data: args[0] })
let result: string = "(function () {" +
"var event;" +
"var data = " + data.toString() + ";" +
Expand Down Expand Up @@ -364,7 +367,7 @@ export struct WebView {
build() {
//RNViewBase({ ctx: this.ctx, tag: this.tag }) {
Stack() {
Web({ src: this.source.uri, controller: this.controller,renderMode: this.renderMode })
Web({ src: this.source.uri, controller: this.controller, renderMode: this.renderMode })
.width(this.descriptor.layoutMetrics.frame.size.width)
.height(this.descriptor.layoutMetrics.frame.size.height)
.constraintSize({ minHeight: 1 })
Expand All @@ -376,18 +379,17 @@ export struct WebView {
.textZoomRatio(this.descriptor.props.textZoom)
.cacheMode(this.cacheMode)
.domStorageAccess(this.descriptor.props.domStorageEnabled)
.zoomAccess(this.descriptor.props.scalesPageToFit)
// nestedScrollFlag 为true 表示可以在嵌套滚动中,web自己能滚动
// .layoutMode(this.nestedScrollFlag ? WebLayoutMode.NONE : WebLayoutMode.FIT_CONTENT)
.zoomAccess(this.descriptor.props.scalesPageToFit)// nestedScrollFlag 为true 表示可以在嵌套滚动中,web自己能滚动
// .layoutMode(this.nestedScrollFlag ? WebLayoutMode.NONE : WebLayoutMode.FIT_CONTENT)

// .nestedScroll(this.nestedScrollFlag ? {
// scrollForward: NestedScrollMode.SELF_ONLY,
// scrollBackward: NestedScrollMode.SELF_ONLY
// } : { scrollForward: NestedScrollMode.PARENT_FIRST, scrollBackward: NestedScrollMode.PARENT_FIRST })
// .overScrollMode(OverScrollMode.NEVER)
// .onSizeChange((event)=>{
// Logger.debug(TAG, "[RNOH] event width: " + event.width + "[RNOH] event height: " + event.height)
// })
// .nestedScroll(this.nestedScrollFlag ? {
// scrollForward: NestedScrollMode.SELF_ONLY,
// scrollBackward: NestedScrollMode.SELF_ONLY
// } : { scrollForward: NestedScrollMode.PARENT_FIRST, scrollBackward: NestedScrollMode.PARENT_FIRST })
// .overScrollMode(OverScrollMode.NEVER)
// .onSizeChange((event)=>{
// Logger.debug(TAG, "[RNOH] event width: " + event.width + "[RNOH] event height: " + event.height)
// })
.onProgressChange((event) => {
if (event) {
this.progress = event.newProgress
Expand All @@ -403,7 +405,8 @@ export struct WebView {
if (event) {
let errorInfo: string = event.error.getErrorInfo();
let errorCode: number = event.error.getErrorCode();
if (errorInfo == "ERR_INTERNET_DISCONNECTED" || errorInfo == "ERR_CACHE_MISS" || !event.request.isMainFrame()) {
if (errorInfo == "ERR_INTERNET_DISCONNECTED" || errorInfo == "ERR_CACHE_MISS" ||
!event.request.isMainFrame()) {
Logger.debug(TAG, "[RNOH] ERR_INTERNET_DISCONNECTED:OR ERR_CACHE_MISS")
return
}
Expand All @@ -414,7 +417,8 @@ export struct WebView {
})
.onLoadIntercept((event) => {
if (!this.descriptor.props.shouldStartLoadWithRequestEnabled) {
Logger.debug(TAG, "[RNOH]:shouldStartLoadWithRequestEnabled:" + this.descriptor.props.shouldStartLoadWithRequestEnabled)
Logger.debug(TAG,
"[RNOH]:shouldStartLoadWithRequestEnabled:" + this.descriptor.props.shouldStartLoadWithRequestEnabled)
return false
}
if (this.source.html != undefined && this.source.html != '') {
Expand Down Expand Up @@ -466,8 +470,8 @@ export struct WebView {
let header = this.source.headers;
if (header != undefined && header != "") {
let headers: Array<webview.WebHeader> = [];
JSON.parse(header,( key: string, value: string) => {
if(key && value){
JSON.parse(header, (key: string, value: string) => {
if (key && value) {
headers.push({ headerKey: key, headerValue: value })
}
return undefined;
Expand All @@ -482,6 +486,6 @@ export struct WebView {
}
.width(this.descriptor.layoutMetrics.frame.size.width)
.height(this.descriptor.layoutMetrics.frame.size.height)
.position({x:this.descriptor.layoutMetrics.frame.origin.x,y:this.descriptor.layoutMetrics.frame.origin.y})
.position({ x: this.descriptor.layoutMetrics.frame.origin.x, y: this.descriptor.layoutMetrics.frame.origin.y })
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
/**
* MIT License
*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Copyright (C) 2024 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -22,26 +22,17 @@
* SOFTWARE.
*/

import {RNPackage,TurboModulesFactory} from '@rnoh/react-native-openharmony/ts';
import type {TurboModule,TurboModuleContext} from '@rnoh/react-native-openharmony/ts';
import {RNCWebViewTurboModule} from './RNCWebViewTurboModule';
import type {
DescriptorWrapperFactoryByDescriptorType,
DescriptorWrapperFactoryByDescriptorTypeCtx
} from '@rnoh/react-native-openharmony/ts';
import { RNPackage } from '@rnoh/react-native-openharmony/ts';
import { RNC } from '@rnoh/react-native-openharmony/generated/ts';

class WebViewTurboModulesFactory extends TurboModulesFactory{
createTurboModule(name:string):TurboModule | null{
if (name === 'RNCWebView') {
return new RNCWebViewTurboModule(this.ctx);
export class RNCWebViewPackage extends RNPackage {
createDescriptorWrapperFactoryByDescriptorType(ctx: DescriptorWrapperFactoryByDescriptorTypeCtx): DescriptorWrapperFactoryByDescriptorType {
return {
[RNC.RNCWebView.NAME]: (ctx) => new RNC.RNCWebView.DescriptorWrapper(ctx.descriptor)
}
return null;
}

hasTurboModule(name:string):boolean{
return name === 'RNCWebView';

}
}

export class WebViewPackage extends RNPackage{
createTurboModulesFactory(ctx:TurboModuleContext):TurboModulesFactory{
return new WebViewTurboModulesFactory(ctx);
}
}
50 changes: 0 additions & 50 deletions harmony/rn_webview/src/main/ets/RNCWebViewTurboModule.ts

This file was deleted.

6 changes: 5 additions & 1 deletion harmony/rn_webview/src/main/module.json5
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"module":{
"name":"rn_webview",
"type":"har",
deviceTypes:['default']
"deviceTypes": [
"default",
"tablet",
"2in1"
]
}
}
7 changes: 3 additions & 4 deletions harmony/rn_webview/ts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
/**
* MIT License
*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Copyright (C) 2024 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -22,5 +22,4 @@
* SOFTWARE.
*/

export * from './src/main/ets/RNCWebViewTurboModule'
export * from './src/main/ets/WebViewPackage'
export * from './src/main/ets/RNCWebViewPackage'
Loading