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
123 changes: 123 additions & 0 deletions harmony/rn_webview/src/main/ets/Magic.ets
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { Descriptor, ViewBaseProps } from '@rnoh/react-native-openharmony'

export class WebViewNewSourceHeader {
name?: string
value?: string
}


export class WebViewNewSource {
uri?: string | Resource
method?: string
body?: string
headers?: WebViewNewSourceHeader[]
html?: string
baseUrl?: string
}

export interface AlertEvent {
url: string;
message: string;
result: JsResult;
}

export const TAG = "WebView"

export const WEB_VIEW = "RNCWebView"

export const JAVASCRIPT_INTERFACE = "ReactNativeWebView";

export interface WebViewProps extends ViewBaseProps {
newSource: WebViewNewSource
javaScriptEnabled: boolean
injectedJavaScript: string
messagingEnabled: boolean
showsHorizontalScrollIndicator: boolean
showsVerticalScrollIndicator: boolean
textZoom: number
cacheEnabled: boolean
cacheMode: number
domStorageEnabled: boolean
scalesPageToFit: boolean
messagingModuleName: string
webviewDebuggingEnabled: boolean
scrollEnabled: boolean
incognito: boolean
userAgent: string
shouldStartLoadWithRequestEnabled: boolean
originWhitelist: Array<string>
}


export class RNCWebViewBridge {
postMessage!: (data: string) => void;
}

export class WebViewEventParams {
type: string
url?: string
loading?: boolean
title?: string
canGoBack?: boolean
canGoForward?: boolean
lockIdentifier?: number
data?: string

constructor(type: string) {
this.type = type
}
}

export enum CACHE_MODE {
'LOAD_DEFAULT' = 'LOAD_DEFAULT',
'LOAD_CACHE_ELSE_NETWORK' = 'LOAD_CACHE_ELSE_NETWORK',
'LOAD_NO_CACHE' = 'LOAD_NO_CACHE',
'LOAD_CACHE_ONLY' = 'LOAD_CACHE_ONLY',
}

export class ResultType {
url: string
loading: boolean
title: string
canGoBack: boolean
canGoForward: boolean
lockIdentifier: number
data: string

constructor(url: string, loading: boolean, title: string, canGoBack: boolean, canGoForward: boolean,
lockIdentifier: number, data: string) {
this.url = url
this.loading = loading
this.title = title
this.canGoBack = canGoBack
this.canGoForward = canGoForward
this.lockIdentifier = lockIdentifier
this.data = data
}
}

export type WebViewViewDescriptor = Descriptor<"RNCWebView", WebViewProps>


export const ZERO: number = 0

export const ONE_HUNDRED: number = 100

export interface ProgressInterface {
progress: number;
}

export interface LoadingErrorInterface {
code: number,
description: string
}

export interface ScrollInterface {
x: number,
y: number
}

export enum WebViewOverScrollMode {
ALWAYS = "always",
NEVER = "never"
}
Loading