diff --git a/harmony/rn_webview/oh-package-lock.json5 b/harmony/rn_webview/oh-package-lock.json5 new file mode 100644 index 000000000..f251cef21 --- /dev/null +++ b/harmony/rn_webview/oh-package-lock.json5 @@ -0,0 +1,18 @@ +{ + "meta": { + "stableOrder": true + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "@rnoh/react-native-openharmony@../react_native_openharmony": "@rnoh/react-native-openharmony@../react_native_openharmony" + }, + "packages": { + "@rnoh/react-native-openharmony@../react_native_openharmony": { + "name": "@rnoh/react-native-openharmony", + "version": "0.72.20", + "resolved": "../react_native_openharmony", + "registryType": "local" + } + } +} \ No newline at end of file diff --git a/harmony/rn_webview/src/main/cpp/EventEmitters.cpp b/harmony/rn_webview/src/main/cpp/EventEmitters.cpp deleted file mode 100644 index d942eeb59..000000000 --- a/harmony/rn_webview/src/main/cpp/EventEmitters.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/* - * MIT License - * - * Copyright (C) 2023 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 - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GenerateEventEmitterCpp.js - */ - -#include "EventEmitters.h" - -namespace facebook { -namespace react { - -void WebViewEventEmitter::onContentSizeChange(OnContentSizeChange event) const -{ - dispatchEvent("contentSizeChange", [event = std::move(event)](jsi::Runtime &runtime) { - auto payload = jsi::Object(runtime); - payload.setProperty(runtime, "url", event.url); - payload.setProperty(runtime, "loading", event.loading); - payload.setProperty(runtime, "title", event.title); - payload.setProperty(runtime, "canGoBack", event.canGoBack); - payload.setProperty(runtime, "canGoForward", event.canGoForward); - payload.setProperty(runtime, "lockIdentifier", event.lockIdentifier); - return payload; - }); -} -void WebViewEventEmitter::onRenderProcessGone(OnRenderProcessGone event) const -{ - dispatchEvent("renderProcessGone", [event = std::move(event)](jsi::Runtime &runtime) { - auto payload = jsi::Object(runtime); - payload.setProperty(runtime, "didCrash", event.didCrash); - return payload; - }); -} -void WebViewEventEmitter::onContentProcessDidTerminate(OnContentProcessDidTerminate event) const -{ - dispatchEvent("contentProcessDidTerminate", [event = std::move(event)](jsi::Runtime &runtime) { - auto payload = jsi::Object(runtime); - payload.setProperty(runtime, "url", event.url); - payload.setProperty(runtime, "loading", event.loading); - payload.setProperty(runtime, "title", event.title); - payload.setProperty(runtime, "canGoBack", event.canGoBack); - payload.setProperty(runtime, "canGoForward", event.canGoForward); - payload.setProperty(runtime, "lockIdentifier", event.lockIdentifier); - return payload; - }); -} -void WebViewEventEmitter::onCustomMenuSelection(OnCustomMenuSelection event) const -{ - dispatchEvent("customMenuSelection", [event = std::move(event)](jsi::Runtime &runtime) { - auto payload = jsi::Object(runtime); - payload.setProperty(runtime, "label", event.label); - payload.setProperty(runtime, "key", event.key); - payload.setProperty(runtime, "selectedText", event.selectedText); - return payload; - }); -} -void WebViewEventEmitter::onFileDownload(OnFileDownload event) const -{ - dispatchEvent("fileDownload", [event = std::move(event)](jsi::Runtime &runtime) { - auto payload = jsi::Object(runtime); - payload.setProperty(runtime, "downloadUrl", event.downloadUrl); - return payload; - }); -} -void WebViewEventEmitter::onLoadingError(OnLoadingError event) const -{ - dispatchEvent("loadingError", [event = std::move(event)](jsi::Runtime &runtime) { - auto payload = jsi::Object(runtime); - payload.setProperty(runtime, "url", event.url); - payload.setProperty(runtime, "loading", event.loading); - payload.setProperty(runtime, "title", event.title); - payload.setProperty(runtime, "canGoBack", event.canGoBack); - payload.setProperty(runtime, "canGoForward", event.canGoForward); - payload.setProperty(runtime, "lockIdentifier", event.lockIdentifier); - payload.setProperty(runtime, "domain", event.domain); - payload.setProperty(runtime, "code", event.code); - payload.setProperty(runtime, "description", event.description); - return payload; - }); -} -void WebViewEventEmitter::onLoadingFinish(OnLoadingFinish event) const -{ - dispatchEvent("loadingFinish", [event = std::move(event)](jsi::Runtime &runtime) { - auto payload = jsi::Object(runtime); - payload.setProperty(runtime, "url", event.url); - payload.setProperty(runtime, "loading", event.loading); - payload.setProperty(runtime, "title", event.title); - payload.setProperty(runtime, "canGoBack", event.canGoBack); - payload.setProperty(runtime, "canGoForward", event.canGoForward); - payload.setProperty(runtime, "lockIdentifier", event.lockIdentifier); - payload.setProperty(runtime, "navigationType", event.navigationType); - payload.setProperty(runtime, "mainDocumentURL", event.mainDocumentURL); - return payload; - }); -} -void WebViewEventEmitter::onLoadingProgress(OnLoadingProgress event) const -{ - dispatchEvent("loadingProgress", [event = std::move(event)](jsi::Runtime &runtime) { - auto payload = jsi::Object(runtime); - payload.setProperty(runtime, "url", event.url); - payload.setProperty(runtime, "loading", event.loading); - payload.setProperty(runtime, "title", event.title); - payload.setProperty(runtime, "canGoBack", event.canGoBack); - payload.setProperty(runtime, "canGoForward", event.canGoForward); - payload.setProperty(runtime, "lockIdentifier", event.lockIdentifier); - payload.setProperty(runtime, "progress", event.progress); - return payload; - }); -} -void WebViewEventEmitter::onLoadingStart(OnLoadingStart event) const -{ - dispatchEvent("loadingStart", [event = std::move(event)](jsi::Runtime &runtime) { - auto payload = jsi::Object(runtime); - payload.setProperty(runtime, "url", event.url); - payload.setProperty(runtime, "loading", event.loading); - payload.setProperty(runtime, "title", event.title); - payload.setProperty(runtime, "canGoBack", event.canGoBack); - payload.setProperty(runtime, "canGoForward", event.canGoForward); - payload.setProperty(runtime, "lockIdentifier", event.lockIdentifier); - payload.setProperty(runtime, "navigationType", toString(event.navigationType)); - payload.setProperty(runtime, "mainDocumentURL", event.mainDocumentURL); - return payload; - }); -} -void WebViewEventEmitter::onHttpError(OnHttpError event) const -{ - dispatchEvent("httpError", [event = std::move(event)](jsi::Runtime &runtime) { - auto payload = jsi::Object(runtime); - payload.setProperty(runtime, "url", event.url); - payload.setProperty(runtime, "loading", event.loading); - payload.setProperty(runtime, "title", event.title); - payload.setProperty(runtime, "canGoBack", event.canGoBack); - payload.setProperty(runtime, "canGoForward", event.canGoForward); - payload.setProperty(runtime, "lockIdentifier", event.lockIdentifier); - payload.setProperty(runtime, "description", event.description); - payload.setProperty(runtime, "statusCode", event.statusCode); - return payload; - }); -} -void WebViewEventEmitter::onMessage(OnMessage event) const -{ - dispatchEvent("message", [event = std::move(event)](jsi::Runtime &runtime) { - auto payload = jsi::Object(runtime); - payload.setProperty(runtime, "url", event.url); - payload.setProperty(runtime, "loading", event.loading); - payload.setProperty(runtime, "title", event.title); - payload.setProperty(runtime, "canGoBack", event.canGoBack); - payload.setProperty(runtime, "canGoForward", event.canGoForward); - payload.setProperty(runtime, "lockIdentifier", event.lockIdentifier); - payload.setProperty(runtime, "data", event.data); - return payload; - }); -} -void WebViewEventEmitter::onOpenWindow(OnOpenWindow event) const -{ - dispatchEvent("openWindow", [event = std::move(event)](jsi::Runtime &runtime) { - auto payload = jsi::Object(runtime); - payload.setProperty(runtime, "targetUrl", event.targetUrl); - return payload; - }); -} -void WebViewEventEmitter::onScroll(OnScroll event) const -{ - dispatchEvent("scroll", [event = std::move(event)](jsi::Runtime &runtime) { - auto payload = jsi::Object(runtime); - { - auto contentInset = jsi::Object(runtime); - contentInset.setProperty(runtime, "bottom", event.contentInset.bottom); - contentInset.setProperty(runtime, "left", event.contentInset.left); - contentInset.setProperty(runtime, "right", event.contentInset.right); - contentInset.setProperty(runtime, "top", event.contentInset.top); - - payload.setProperty(runtime, "contentInset", contentInset); - } - { - auto contentOffset = jsi::Object(runtime); - contentOffset.setProperty(runtime, "y", event.contentOffset.y); - contentOffset.setProperty(runtime, "x", event.contentOffset.x); - - payload.setProperty(runtime, "contentOffset", contentOffset); - } - { - auto contentSize = jsi::Object(runtime); - contentSize.setProperty(runtime, "height", event.contentSize.height); - contentSize.setProperty(runtime, "width", event.contentSize.width); - - payload.setProperty(runtime, "contentSize", contentSize); - } - { - auto layoutMeasurement = jsi::Object(runtime); - layoutMeasurement.setProperty(runtime, "height", event.layoutMeasurement.height); - layoutMeasurement.setProperty(runtime, "width", event.layoutMeasurement.width); - - payload.setProperty(runtime, "layoutMeasurement", layoutMeasurement); - } - { - auto targetContentOffset = jsi::Object(runtime); - targetContentOffset.setProperty(runtime, "y", event.targetContentOffset.y); - targetContentOffset.setProperty(runtime, "x", event.targetContentOffset.x); - - payload.setProperty(runtime, "targetContentOffset", targetContentOffset); - } - { - auto velocity = jsi::Object(runtime); - velocity.setProperty(runtime, "y", event.velocity.y); - velocity.setProperty(runtime, "x", event.velocity.x); - - payload.setProperty(runtime, "velocity", velocity); - } - payload.setProperty(runtime, "zoomScale", event.zoomScale); - payload.setProperty(runtime, "responderIgnoreScroll", event.responderIgnoreScroll); - return payload; - }); -} -void WebViewEventEmitter::onShouldStartLoadWithRequest(OnShouldStartLoadWithRequest event) const -{ - dispatchEvent("shouldStartLoadWithRequest", [event = std::move(event)](jsi::Runtime &runtime) { - auto payload = jsi::Object(runtime); - payload.setProperty(runtime, "url", event.url); - payload.setProperty(runtime, "loading", event.loading); - payload.setProperty(runtime, "title", event.title); - payload.setProperty(runtime, "canGoBack", event.canGoBack); - payload.setProperty(runtime, "canGoForward", event.canGoForward); - payload.setProperty(runtime, "lockIdentifier", event.lockIdentifier); - payload.setProperty(runtime, "navigationType", event.navigationType); - payload.setProperty(runtime, "mainDocumentURL", event.mainDocumentURL); - payload.setProperty(runtime, "isTopFrame", event.isTopFrame); - return payload; - }); -} - -} // namespace react -} // namespace facebook diff --git a/harmony/rn_webview/src/main/cpp/EventEmitters.h b/harmony/rn_webview/src/main/cpp/EventEmitters.h deleted file mode 100644 index 1dd0166f7..000000000 --- a/harmony/rn_webview/src/main/cpp/EventEmitters.h +++ /dev/null @@ -1,289 +0,0 @@ -/* - * MIT License - * - * Copyright (C) 2023 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 - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GenerateEventEmitterH.js - */ -#pragma once - -#include -#include - -namespace facebook { -namespace react { - -class JSI_EXPORT WebViewEventEmitter : public ViewEventEmitter { - public: - using ViewEventEmitter::ViewEventEmitter; - - struct OnContentSizeChange { - std::string url; - bool loading; - std::string title; - bool canGoBack; - bool canGoForward; - double lockIdentifier; - }; - - struct OnRenderProcessGone { - bool didCrash; - }; - - struct OnContentProcessDidTerminate { - std::string url; - bool loading; - std::string title; - bool canGoBack; - bool canGoForward; - double lockIdentifier; - }; - - struct OnCustomMenuSelection { - std::string label; - std::string key; - std::string selectedText; - }; - - struct OnFileDownload { - std::string downloadUrl; - }; - - struct OnLoadingError { - std::string url; - bool loading; - std::string title; - bool canGoBack; - bool canGoForward; - double lockIdentifier; - std::string domain; - int code; - std::string description; - }; - - enum class OnLoadingFinishNavigationType { - Click, - Formsubmit, - Backforward, - Reload, - Formresubmit, - Other - }; - - static char const *toString(const OnLoadingFinishNavigationType value) { - switch (value) { - case OnLoadingFinishNavigationType::Click: return "click"; - case OnLoadingFinishNavigationType::Formsubmit: return "formsubmit"; - case OnLoadingFinishNavigationType::Backforward: return "backforward"; - case OnLoadingFinishNavigationType::Reload: return "reload"; - case OnLoadingFinishNavigationType::Formresubmit: return "formresubmit"; - case OnLoadingFinishNavigationType::Other: return "other"; - } - } - - struct OnLoadingFinish { - std::string url; - bool loading; - std::string title; - bool canGoBack; - bool canGoForward; - double lockIdentifier; - std::string navigationType; - std::string mainDocumentURL; - }; - - struct OnLoadingProgress { - std::string url; - bool loading; - std::string title; - bool canGoBack; - bool canGoForward; - double lockIdentifier; - double progress; - }; - - enum class OnLoadingStartNavigationType { - Click, - Formsubmit, - Backforward, - Reload, - Formresubmit, - Other - }; - - static char const *toString(const OnLoadingStartNavigationType value) { - switch (value) { - case OnLoadingStartNavigationType::Click: return "click"; - case OnLoadingStartNavigationType::Formsubmit: return "formsubmit"; - case OnLoadingStartNavigationType::Backforward: return "backforward"; - case OnLoadingStartNavigationType::Reload: return "reload"; - case OnLoadingStartNavigationType::Formresubmit: return "formresubmit"; - case OnLoadingStartNavigationType::Other: return "other"; - } - } - - struct OnLoadingStart { - std::string url; - bool loading; - std::string title; - bool canGoBack; - bool canGoForward; - double lockIdentifier; - OnLoadingStartNavigationType navigationType; - std::string mainDocumentURL; - }; - - struct OnHttpError { - std::string url; - bool loading; - std::string title; - bool canGoBack; - bool canGoForward; - double lockIdentifier; - std::string description; - int statusCode; - }; - - struct OnMessage { - std::string url; - bool loading; - std::string title; - bool canGoBack; - bool canGoForward; - double lockIdentifier; - std::string data; - }; - - struct OnOpenWindow { - std::string targetUrl; - }; - - struct OnScrollContentInset { - double bottom; - double left; - double right; - double top; - }; - - struct OnScrollContentOffset { - double y; - double x; - }; - - struct OnScrollContentSize { - double height; - double width; - }; - - struct OnScrollLayoutMeasurement { - double height; - double width; - }; - - struct OnScrollTargetContentOffset { - double y; - double x; - }; - - struct OnScrollVelocity { - double y; - double x; - }; - - struct OnScroll { - OnScrollContentInset contentInset; - OnScrollContentOffset contentOffset; - OnScrollContentSize contentSize; - OnScrollLayoutMeasurement layoutMeasurement; - OnScrollTargetContentOffset targetContentOffset; - OnScrollVelocity velocity; - double zoomScale; - bool responderIgnoreScroll; - }; - - enum class OnShouldStartLoadWithRequestNavigationType { - Click, - Formsubmit, - Backforward, - Reload, - Formresubmit, - Other - }; - - static char const *toString(const OnShouldStartLoadWithRequestNavigationType value) { - switch (value) { - case OnShouldStartLoadWithRequestNavigationType::Click: return "click"; - case OnShouldStartLoadWithRequestNavigationType::Formsubmit: return "formsubmit"; - case OnShouldStartLoadWithRequestNavigationType::Backforward: return "backforward"; - case OnShouldStartLoadWithRequestNavigationType::Reload: return "reload"; - case OnShouldStartLoadWithRequestNavigationType::Formresubmit: return "formresubmit"; - case OnShouldStartLoadWithRequestNavigationType::Other: return "other"; - } - } - - struct OnShouldStartLoadWithRequest { - std::string url; - bool loading; - std::string title; - bool canGoBack; - bool canGoForward; - double lockIdentifier; - std::string navigationType; - std::string mainDocumentURL; - bool isTopFrame; - }; - - void onContentSizeChange(OnContentSizeChange value) const; - - void onRenderProcessGone(OnRenderProcessGone value) const; - - void onContentProcessDidTerminate(OnContentProcessDidTerminate value) const; - - void onCustomMenuSelection(OnCustomMenuSelection value) const; - - void onFileDownload(OnFileDownload value) const; - - void onLoadingError(OnLoadingError value) const; - - void onLoadingFinish(OnLoadingFinish value) const; - - void onLoadingProgress(OnLoadingProgress value) const; - - void onLoadingStart(OnLoadingStart value) const; - - void onHttpError(OnHttpError value) const; - - void onMessage(OnMessage value) const; - - void onOpenWindow(OnOpenWindow value) const; - - void onScroll(OnScroll value) const; - - void onShouldStartLoadWithRequest(OnShouldStartLoadWithRequest value) const; -}; - -} // namespace react -} // namespace facebook diff --git a/harmony/rn_webview/src/main/cpp/Props.cpp b/harmony/rn_webview/src/main/cpp/Props.cpp deleted file mode 100644 index 8a081bda8..000000000 --- a/harmony/rn_webview/src/main/cpp/Props.cpp +++ /dev/null @@ -1,592 +0,0 @@ -/* - * MIT License - * - * Copyright (C) 2023 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 - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GeneratePropsCpp.js - */ - -#include "Props.h" -#include -#include - -namespace facebook { -namespace react { -static inline void fromRawValue(const PropsParserContext &context, const RawValue &value, WebViewLayerType &result) -{ - auto string = (std::string)value; - if (string == "none") { - result = WebViewLayerType::None; - return; - } - if (string == "software") { - result = WebViewLayerType::Software; - return; - } - if (string == "hardware") { - result = WebViewLayerType::Hardware; - return; - } -} - -static inline std::string toString(const WebViewLayerType &value) -{ - switch (value) { - case WebViewLayerType::None: - return "none"; - case WebViewLayerType::Software: - return "software"; - case WebViewLayerType::Hardware: - return "hardware"; - } -} -static inline void fromRawValue(const PropsParserContext &context, const RawValue &value, WebViewCacheMode &result) -{ - auto string = (std::string)value; - if (string == "LOAD_DEFAULT") { - result = WebViewCacheMode::LOAD_DEFAULT; - return; - } - if (string == "LOAD_CACHE_ELSE_NETWORK") { - result = WebViewCacheMode::LOAD_CACHE_ELSE_NETWORK; - return; - } - if (string == "LOAD_NO_CACHE") { - result = WebViewCacheMode::LOAD_NO_CACHE; - return; - } - if (string == "LOAD_CACHE_ONLY") { - result = WebViewCacheMode::LOAD_CACHE_ONLY; - return; - } -} - -static inline std::string toString(const WebViewCacheMode &value) -{ - switch (value) { - case WebViewCacheMode::LOAD_DEFAULT: - return "LOAD_DEFAULT"; - case WebViewCacheMode::LOAD_CACHE_ELSE_NETWORK: - return "LOAD_CACHE_ELSE_NETWORK"; - case WebViewCacheMode::LOAD_NO_CACHE: - return "LOAD_NO_CACHE"; - case WebViewCacheMode::LOAD_CACHE_ONLY: - return "LOAD_CACHE_ONLY"; - } -} -static inline void fromRawValue(const PropsParserContext &context, const RawValue &value, - WebViewMixedContentMode &result) -{ - auto string = (std::string)value; - if (string == "never") { - result = WebViewMixedContentMode::Never; - return; - } - if (string == "always") { - result = WebViewMixedContentMode::Always; - return; - } - if (string == "compatibility") { - result = WebViewMixedContentMode::Compatibility; - return; - } -} - -static inline std::string toString(const WebViewMixedContentMode &value) -{ - switch (value) { - case WebViewMixedContentMode::Never: - return "never"; - case WebViewMixedContentMode::Always: - return "always"; - case WebViewMixedContentMode::Compatibility: - return "compatibility"; - } -} -static inline void fromRawValue(const PropsParserContext &context, const RawValue &value, - WebViewContentInsetAdjustmentBehavior &result) -{ - auto string = (std::string)value; - if (string == "never") { - result = WebViewContentInsetAdjustmentBehavior::Never; - return; - } - if (string == "automatic") { - result = WebViewContentInsetAdjustmentBehavior::Automatic; - return; - } - if (string == "scrollableAxes") { - result = WebViewContentInsetAdjustmentBehavior::ScrollableAxes; - return; - } - if (string == "always") { - result = WebViewContentInsetAdjustmentBehavior::Always; - return; - } -} - -static inline std::string toString(const WebViewContentInsetAdjustmentBehavior &value) -{ - switch (value) { - case WebViewContentInsetAdjustmentBehavior::Never: - return "never"; - case WebViewContentInsetAdjustmentBehavior::Automatic: - return "automatic"; - case WebViewContentInsetAdjustmentBehavior::ScrollableAxes: - return "scrollableAxes"; - case WebViewContentInsetAdjustmentBehavior::Always: - return "always"; - } -} -static inline void fromRawValue(const PropsParserContext &context, const RawValue &value, WebViewContentMode &result) -{ - auto string = (std::string)value; - if (string == "recommended") { - result = WebViewContentMode::Recommended; - return; - } - if (string == "mobile") { - result = WebViewContentMode::Mobile; - return; - } - if (string == "desktop") { - result = WebViewContentMode::Desktop; - return; - } -} - -static inline std::string toString(const WebViewContentMode &value) -{ - switch (value) { - case WebViewContentMode::Recommended: - return "recommended"; - case WebViewContentMode::Mobile: - return "mobile"; - case WebViewContentMode::Desktop: - return "desktop"; - } -} -static inline void fromRawValue(const PropsParserContext &context, const RawValue &value, - WebViewDataDetectorTypesMask &result) -{ - auto items = std::vector{value}; - for (const auto &item : items) { - if (item == "address") { - result |= WebViewDataDetectorTypes::Address; - continue; - } - if (item == "link") { - result |= WebViewDataDetectorTypes::Link; - continue; - } - if (item == "calendarEvent") { - result |= WebViewDataDetectorTypes::CalendarEvent; - continue; - } - if (item == "trackingNumber") { - result |= WebViewDataDetectorTypes::TrackingNumber; - continue; - } - if (item == "flightNumber") { - result |= WebViewDataDetectorTypes::FlightNumber; - continue; - } - if (item == "lookupSuggestion") { - result |= WebViewDataDetectorTypes::LookupSuggestion; - continue; - } - if (item == "phoneNumber") { - result |= WebViewDataDetectorTypes::PhoneNumber; - continue; - } - if (item == "all") { - result |= WebViewDataDetectorTypes::All; - continue; - } - if (item == "none") { - result |= WebViewDataDetectorTypes::None; - continue; - } - } -} - -static inline std::string toString(const WebViewDataDetectorTypesMask &value) -{ - auto result = std::string{}; - auto separator = std::string{", "}; - - if (value & WebViewDataDetectorTypes::Address) { - result += "address" + separator; - } - if (value & WebViewDataDetectorTypes::Link) { - result += "link" + separator; - } - if (value & WebViewDataDetectorTypes::CalendarEvent) { - result += "calendarEvent" + separator; - } - if (value & WebViewDataDetectorTypes::TrackingNumber) { - result += "trackingNumber" + separator; - } - if (value & WebViewDataDetectorTypes::FlightNumber) { - result += "flightNumber" + separator; - } - if (value & WebViewDataDetectorTypes::LookupSuggestion) { - result += "lookupSuggestion" + separator; - } - if (value & WebViewDataDetectorTypes::PhoneNumber) { - result += "phoneNumber" + separator; - } - if (value & WebViewDataDetectorTypes::All) { - result += "all" + separator; - } - if (value & WebViewDataDetectorTypes::None) { - result += "none" + separator; - } - if (!result.empty()) { - result.erase(result.length() - separator.length()); - } - return result; -} -static inline void fromRawValue(const PropsParserContext &context, const RawValue &value, - WebViewMediaCapturePermissionGrantType &result) -{ - auto string = (std::string)value; - if (string == "prompt") { - result = WebViewMediaCapturePermissionGrantType::Prompt; - return; - } - if (string == "grant") { - result = WebViewMediaCapturePermissionGrantType::Grant; - return; - } - if (string == "deny") { - result = WebViewMediaCapturePermissionGrantType::Deny; - return; - } - if (string == "grantIfSameHostElsePrompt") { - result = WebViewMediaCapturePermissionGrantType::GrantIfSameHostElsePrompt; - return; - } - if (string == "grantIfSameHostElseDeny") { - result = WebViewMediaCapturePermissionGrantType::GrantIfSameHostElseDeny; - return; - } -} - -static inline std::string toString(const WebViewMediaCapturePermissionGrantType &value) -{ - switch (value) { - case WebViewMediaCapturePermissionGrantType::Prompt: - return "prompt"; - case WebViewMediaCapturePermissionGrantType::Grant: - return "grant"; - case WebViewMediaCapturePermissionGrantType::Deny: - return "deny"; - case WebViewMediaCapturePermissionGrantType::GrantIfSameHostElsePrompt: - return "grantIfSameHostElsePrompt"; - case WebViewMediaCapturePermissionGrantType::GrantIfSameHostElseDeny: - return "grantIfSameHostElseDeny"; - } -} -static inline void fromRawValue(const PropsParserContext &context, const RawValue &value, - WebViewContentInsetStruct &result) -{ - auto map = (butter::map)value; - - auto tmp_top = map.find("top"); - if (tmp_top != map.end()) { - fromRawValue(context, tmp_top->second, result.top); - } - auto tmp_left = map.find("left"); - if (tmp_left != map.end()) { - fromRawValue(context, tmp_left->second, result.left); - } - auto tmp_bottom = map.find("bottom"); - if (tmp_bottom != map.end()) { - fromRawValue(context, tmp_bottom->second, result.bottom); - } - auto tmp_right = map.find("right"); - if (tmp_right != map.end()) { - fromRawValue(context, tmp_right->second, result.right); - } -} - -static inline std::string toString(const WebViewContentInsetStruct &value) -{ - return "[Object WebViewContentInsetStruct]"; -} -static inline void fromRawValue(const PropsParserContext &context, const RawValue &value, - WebViewMenuItemsStruct &result) -{ - auto map = (butter::map)value; - - auto tmp_label = map.find("label"); - if (tmp_label != map.end()) { - fromRawValue(context, tmp_label->second, result.label); - } - auto tmp_key = map.find("key"); - if (tmp_key != map.end()) { - fromRawValue(context, tmp_key->second, result.key); - } -} - -static inline std::string toString(const WebViewMenuItemsStruct &value) -{ - return "[Object WebViewMenuItemsStruct]"; -} - -static inline void fromRawValue(const PropsParserContext &context, const RawValue &value, - std::vector &result) -{ - auto items = (std::vector)value; - for (const auto &item : items) { - WebViewMenuItemsStruct newItem; - fromRawValue(context, item, newItem); - result.emplace_back(newItem); - } -} -static inline void fromRawValue(const PropsParserContext &context, const RawValue &value, - WebViewBasicAuthCredentialStruct &result) -{ - auto map = (butter::map)value; - - auto tmp_username = map.find("username"); - if (tmp_username != map.end()) { - fromRawValue(context, tmp_username->second, result.username); - } - auto tmp_password = map.find("password"); - if (tmp_password != map.end()) { - fromRawValue(context, tmp_password->second, result.password); - } -} - -static inline std::string toString(const WebViewBasicAuthCredentialStruct &value) -{ - return "[Object WebViewBasicAuthCredentialStruct]"; -} -static inline std::string getValues(const PropsParserContext &context, const RawValue &value) { - auto map = (butter::map)value; - std::string result = ""; - std::string itemValue1; - auto tmp_name = map.find("name"); - if (tmp_name != map.end()) { - fromRawValue(context, tmp_name->second, itemValue1); - result += "\"" + itemValue1 + "\":\""; - } - auto tmp_value = map.find("value"); - std::string itemValue2; - if (tmp_value != map.end()) { - fromRawValue(context, tmp_value->second, itemValue2); - result += itemValue2 + "\""; - } - return result; -} - -static inline std::string toString(const WebViewNewSourceHeadersStruct &value) -{ - return "[Object WebViewNewSourceHeadersStruct]"; -} - -static inline std::string getSourceHeaders(const PropsParserContext &context, const RawValue &value) { - auto items = (std::vector)value; - std::string headers = "{"; - bool isFirst = true; - for (const auto &item : items) { - std::string tmp = getValues(context, item); - if (!isFirst) { - headers += ","; - } - headers += tmp; - isFirst = false; - } - headers += "}"; - return headers; -} - -static inline void fromRawValue(const PropsParserContext &context, const RawValue &value, - WebViewNewSourceStruct &result) -{ - auto map = (butter::map)value; - - auto tmp_uri = map.find("uri"); - if (tmp_uri != map.end()) { - fromRawValue(context, tmp_uri->second, result.uri); - } - auto tmp_method = map.find("method"); - if (tmp_method != map.end()) { - fromRawValue(context, tmp_method->second, result.method); - } - auto tmp_body = map.find("body"); - if (tmp_body != map.end()) { - fromRawValue(context, tmp_body->second, result.body); - } - auto tmp_headers = map.find("headers"); - if (tmp_headers != map.end()) { - result.headers = getSourceHeaders(context, tmp_headers->second); - } - auto tmp_html = map.find("html"); - if (tmp_html != map.end()) { - fromRawValue(context, tmp_html->second, result.html); - } - auto tmp_baseUrl = map.find("baseUrl"); - if (tmp_baseUrl != map.end()) { - fromRawValue(context, tmp_baseUrl->second, result.baseUrl); - } -} - -static inline std::string toString(const WebViewNewSourceStruct &value) -{ - return "[Object WebViewNewSourceStruct]"; -} -WebViewProps::WebViewProps( - const PropsParserContext &context, - const WebViewProps &sourceProps, - const RawProps &rawProps): ViewProps(context, sourceProps, rawProps), - - allowFileAccess(convertRawProp(context, rawProps, "allowFileAccess", sourceProps.allowFileAccess, {false})), - allowsProtectedMedia(convertRawProp(context, rawProps, "allowsProtectedMedia", - sourceProps.allowsProtectedMedia, {false})), - allowsFullscreenVideo(convertRawProp(context, rawProps, "allowsFullscreenVideo", - sourceProps.allowsFullscreenVideo, {false})), - androidLayerType(convertRawProp(context, rawProps, "androidLayerType", sourceProps.androidLayerType, - {WebViewLayerType::None})), - cacheMode(convertRawProp(context, rawProps, "cacheMode", sourceProps.cacheMode, {WebViewCacheMode::LOAD_DEFAULT})), - domStorageEnabled(convertRawProp(context, rawProps, "domStorageEnabled", sourceProps.domStorageEnabled, {false})), - downloadingMessage(convertRawProp(context, rawProps, "downloadingMessage", sourceProps.downloadingMessage, {})), - forceDarkOn(convertRawProp(context, rawProps, "forceDarkOn", sourceProps.forceDarkOn, {false})), - geolocationEnabled(convertRawProp(context, rawProps, "geolocationEnabled", - sourceProps.geolocationEnabled, {false})), - lackPermissionToDownloadMessage(convertRawProp(context, rawProps, "lackPermissionToDownloadMessage", - sourceProps.lackPermissionToDownloadMessage, {})), - messagingModuleName(convertRawProp(context, rawProps, "messagingModuleName", sourceProps.messagingModuleName, {})), - minimumFontSize(convertRawProp(context, rawProps, "minimumFontSize", sourceProps.minimumFontSize, {0})), - mixedContentMode(convertRawProp(context, rawProps, "mixedContentMode", sourceProps.mixedContentMode, - {WebViewMixedContentMode::Never})), - nestedScrollEnabled(convertRawProp(context, rawProps, "nestedScrollEnabled", - sourceProps.nestedScrollEnabled, {false})), - overScrollMode(convertRawProp(context, rawProps, "overScrollMode", sourceProps.overScrollMode, {})), - saveFormDataDisabled(convertRawProp(context, rawProps, "saveFormDataDisabled", - sourceProps.saveFormDataDisabled, {false})), - scalesPageToFit(convertRawProp(context, rawProps, "scalesPageToFit", sourceProps.scalesPageToFit, {false})), - setBuiltInZoomControls(convertRawProp(context, rawProps, "setBuiltInZoomControls", - sourceProps.setBuiltInZoomControls, {false})), - setDisplayZoomControls(convertRawProp(context, rawProps, "setDisplayZoomControls", - sourceProps.setDisplayZoomControls, {false})), - setSupportMultipleWindows(convertRawProp(context, rawProps, "setSupportMultipleWindows", - sourceProps.setSupportMultipleWindows, {false})), - textZoom(convertRawProp(context, rawProps, "textZoom", sourceProps.textZoom, {0})), - thirdPartyCookiesEnabled(convertRawProp(context, rawProps, "thirdPartyCookiesEnabled", - sourceProps.thirdPartyCookiesEnabled, {false})), - hasOnScroll(convertRawProp(context, rawProps, "hasOnScroll", sourceProps.hasOnScroll, {false})), - injectedJavaScriptObject(convertRawProp(context, rawProps, "injectedJavaScriptObject", - sourceProps.injectedJavaScriptObject, {})), - allowingReadAccessToURL(convertRawProp(context, rawProps, "allowingReadAccessToURL", - sourceProps.allowingReadAccessToURL, {})), - allowsBackForwardNavigationGestures(convertRawProp(context, rawProps, "allowsBackForwardNavigationGestures", - sourceProps.allowsBackForwardNavigationGestures, {false})), - allowsInlineMediaPlayback(convertRawProp(context, rawProps, "allowsInlineMediaPlayback", - sourceProps.allowsInlineMediaPlayback, {false})), - allowsAirPlayForMediaPlayback(convertRawProp(context, rawProps, "allowsAirPlayForMediaPlayback", - sourceProps.allowsAirPlayForMediaPlayback, {false})), - allowsLinkPreview(convertRawProp(context, rawProps, "allowsLinkPreview", sourceProps.allowsLinkPreview, {false})), - automaticallyAdjustContentInsets(convertRawProp(context, rawProps, "automaticallyAdjustContentInsets", - sourceProps.automaticallyAdjustContentInsets, {false})), - autoManageStatusBarEnabled(convertRawProp(context, rawProps, "autoManageStatusBarEnabled", - sourceProps.autoManageStatusBarEnabled, {false})), - bounces(convertRawProp(context, rawProps, "bounces", sourceProps.bounces, {false})), - contentInset(convertRawProp(context, rawProps, "contentInset", sourceProps.contentInset, {})), - contentInsetAdjustmentBehavior(convertRawProp(context, rawProps, "contentInsetAdjustmentBehavior", - sourceProps.contentInsetAdjustmentBehavior, {WebViewContentInsetAdjustmentBehavior::Never})), - contentMode(convertRawProp(context, rawProps, "contentMode", sourceProps.contentMode, - {WebViewContentMode::Recommended})), - dataDetectorTypes(convertRawProp(context, rawProps, "dataDetectorTypes", sourceProps.dataDetectorTypes, - {static_cast(WebViewDataDetectorTypes::PhoneNumber)})), - decelerationRate(convertRawProp(context, rawProps, "decelerationRate", sourceProps.decelerationRate, {0.0})), - directionalLockEnabled(convertRawProp(context, rawProps, "directionalLockEnabled", - sourceProps.directionalLockEnabled, {false})), - enableApplePay(convertRawProp(context, rawProps, "enableApplePay", sourceProps.enableApplePay, {false})), - hideKeyboardAccessoryView(convertRawProp(context, rawProps, "hideKeyboardAccessoryView", - sourceProps.hideKeyboardAccessoryView, {false})), - keyboardDisplayRequiresUserAction(convertRawProp(context, rawProps, "keyboardDisplayRequiresUserAction", - sourceProps.keyboardDisplayRequiresUserAction, {false})), - limitsNavigationsToAppBoundDomains(convertRawProp(context, rawProps, "limitsNavigationsToAppBoundDomains", - sourceProps.limitsNavigationsToAppBoundDomains, {false})), - mediaCapturePermissionGrantType(convertRawProp(context, rawProps, "mediaCapturePermissionGrantType", - sourceProps.mediaCapturePermissionGrantType, {WebViewMediaCapturePermissionGrantType::Prompt})), - pagingEnabled(convertRawProp(context, rawProps, "pagingEnabled", sourceProps.pagingEnabled, {false})), - pullToRefreshEnabled(convertRawProp(context, rawProps, "pullToRefreshEnabled", - sourceProps.pullToRefreshEnabled, {false})), - scrollEnabled(convertRawProp(context, rawProps, "scrollEnabled", sourceProps.scrollEnabled, {false})), - sharedCookiesEnabled(convertRawProp(context, rawProps, "sharedCookiesEnabled", - sourceProps.sharedCookiesEnabled, {false})), - textInteractionEnabled(convertRawProp(context, rawProps, "textInteractionEnabled", - sourceProps.textInteractionEnabled, {false})), - useSharedProcessPool(convertRawProp(context, rawProps, "useSharedProcessPool", - sourceProps.useSharedProcessPool, {false})), - menuItems(convertRawProp(context, rawProps, "menuItems", sourceProps.menuItems, {})), - suppressMenuItems(convertRawProp(context, rawProps, "suppressMenuItems", sourceProps.suppressMenuItems, {})), - hasOnFileDownload(convertRawProp(context, rawProps, "hasOnFileDownload", sourceProps.hasOnFileDownload, {false})), - fraudulentWebsiteWarningEnabled(convertRawProp(context, rawProps, "fraudulentWebsiteWarningEnabled", - sourceProps.fraudulentWebsiteWarningEnabled, {false})), - allowFileAccessFromFileURLs(convertRawProp(context, rawProps, "allowFileAccessFromFileURLs", - sourceProps.allowFileAccessFromFileURLs, {false})), - allowUniversalAccessFromFileURLs(convertRawProp(context, rawProps, "allowUniversalAccessFromFileURLs", - sourceProps.allowUniversalAccessFromFileURLs, {false})), - applicationNameForUserAgent(convertRawProp(context, rawProps, "applicationNameForUserAgent", - sourceProps.applicationNameForUserAgent, {})), - basicAuthCredential(convertRawProp(context, rawProps, "basicAuthCredential", sourceProps.basicAuthCredential, {})), - cacheEnabled(convertRawProp(context, rawProps, "cacheEnabled", sourceProps.cacheEnabled, {false})), - incognito(convertRawProp(context, rawProps, "incognito", sourceProps.incognito, {false})), - injectedJavaScript(convertRawProp(context, rawProps, "injectedJavaScript", sourceProps.injectedJavaScript, {})), - injectedJavaScriptBeforeContentLoaded(convertRawProp(context, rawProps, "injectedJavaScriptBeforeContentLoaded", - sourceProps.injectedJavaScriptBeforeContentLoaded, {})), - injectedJavaScriptForMainFrameOnly(convertRawProp(context, rawProps, "injectedJavaScriptForMainFrameOnly", - sourceProps.injectedJavaScriptForMainFrameOnly, {false})), - injectedJavaScriptBeforeContentLoadedForMainFrameOnly(convertRawProp(context, rawProps, - "injectedJavaScriptBeforeContentLoadedForMainFrameOnly", - sourceProps.injectedJavaScriptBeforeContentLoadedForMainFrameOnly, {false})), - javaScriptCanOpenWindowsAutomatically(convertRawProp(context, rawProps, "javaScriptCanOpenWindowsAutomatically", - sourceProps.javaScriptCanOpenWindowsAutomatically, {false})), - javaScriptEnabled(convertRawProp(context, rawProps, "javaScriptEnabled", sourceProps.javaScriptEnabled, {false})), - webviewDebuggingEnabled(convertRawProp(context, rawProps, "webviewDebuggingEnabled", - sourceProps.webviewDebuggingEnabled, {false})), - mediaPlaybackRequiresUserAction(convertRawProp(context, rawProps, "mediaPlaybackRequiresUserAction", - sourceProps.mediaPlaybackRequiresUserAction, {false})), - messagingEnabled(convertRawProp(context, rawProps, "messagingEnabled", sourceProps.messagingEnabled, {false})), - hasOnOpenWindowEvent(convertRawProp(context, rawProps, "hasOnOpenWindowEvent", - sourceProps.hasOnOpenWindowEvent, {false})), - showsHorizontalScrollIndicator(convertRawProp(context, rawProps, "showsHorizontalScrollIndicator", - sourceProps.showsHorizontalScrollIndicator, {true})), - showsVerticalScrollIndicator(convertRawProp(context, rawProps, "showsVerticalScrollIndicator", - sourceProps.showsVerticalScrollIndicator, {true})), - newSource(convertRawProp(context, rawProps, "newSource", sourceProps.newSource, {})), - userAgent(convertRawProp(context, rawProps, "userAgent", sourceProps.userAgent, {})), - shouldStartLoadWithRequestEnabled(convertRawProp(context, rawProps, "shouldStartLoadWithRequestEnabled", - sourceProps.shouldStartLoadWithRequestEnabled, {false})) - {} - -} // namespace react -} // namespace facebook diff --git a/harmony/rn_webview/src/main/cpp/Props.h b/harmony/rn_webview/src/main/cpp/Props.h deleted file mode 100644 index 429f2a16f..000000000 --- a/harmony/rn_webview/src/main/cpp/Props.h +++ /dev/null @@ -1,190 +0,0 @@ -/* - * MIT License - * - * Copyright (C) 2023 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 - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GeneratePropsH.js - */ -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace facebook { -namespace react { -enum class WebViewLayerType { None, Software, Hardware }; -enum class WebViewCacheMode { LOAD_DEFAULT, LOAD_CACHE_ELSE_NETWORK, LOAD_NO_CACHE, LOAD_CACHE_ONLY }; -enum class WebViewMixedContentMode { Never, Always, Compatibility }; -enum class WebViewContentInsetAdjustmentBehavior { Never, Automatic, ScrollableAxes, Always }; -enum class WebViewContentMode { Recommended, Mobile, Desktop }; -using WebViewDataDetectorTypesMask = uint32_t; -enum class WebViewDataDetectorTypes: WebViewDataDetectorTypesMask { - Address = 1 << 0, - Link = 1 << 1, - CalendarEvent = 1 << 2, - TrackingNumber = 1 << 3, - FlightNumber = 1 << 4, - LookupSuggestion = 1 << 5, - PhoneNumber = 1 << 6, - All = 1 << 7, - None = 1 << 8 -}; -constexpr bool operator&(WebViewDataDetectorTypesMask const lhs, enum WebViewDataDetectorTypes const rhs) -{ - return lhs & static_cast(rhs); -} -constexpr WebViewDataDetectorTypesMask operator|( - WebViewDataDetectorTypesMask const lhs, - enum WebViewDataDetectorTypes const rhs) -{ - return lhs | static_cast(rhs); -} -constexpr void operator|=( - WebViewDataDetectorTypesMask &lhs, - enum WebViewDataDetectorTypes const rhs) -{ - lhs = lhs | static_cast(rhs); -} -enum class WebViewMediaCapturePermissionGrantType { - Prompt, Grant, Deny, GrantIfSameHostElsePrompt, GrantIfSameHostElseDeny -}; -struct WebViewContentInsetStruct { - double top; - double left; - double bottom; - double right; -}; -struct WebViewMenuItemsStruct { - std::string label; - std::string key; -}; -struct WebViewBasicAuthCredentialStruct { - std::string username; - std::string password; -}; -struct WebViewNewSourceHeadersStruct { - std::string name; - std::string value; -}; -struct WebViewNewSourceStruct { - std::string uri; - std::string method; - std::string body; - std::string headers; - std::string html; - std::string baseUrl; -}; -class JSI_EXPORT WebViewProps final : public ViewProps { - public: - WebViewProps() = default; - WebViewProps(const PropsParserContext &context, const WebViewProps &sourceProps, const RawProps &rawProps); - -#pragma mark - Props - - bool allowFileAccess{false}; - bool allowsProtectedMedia{false}; - bool allowsFullscreenVideo{false}; - WebViewLayerType androidLayerType{WebViewLayerType::None}; - WebViewCacheMode cacheMode{WebViewCacheMode::LOAD_DEFAULT}; - bool domStorageEnabled{false}; - std::string downloadingMessage{}; - bool forceDarkOn{false}; - bool geolocationEnabled{false}; - std::string lackPermissionToDownloadMessage{}; - std::string messagingModuleName{}; - int minimumFontSize{0}; - WebViewMixedContentMode mixedContentMode{WebViewMixedContentMode::Never}; - bool nestedScrollEnabled{false}; - std::string overScrollMode{}; - bool saveFormDataDisabled{false}; - bool scalesPageToFit{false}; - bool setBuiltInZoomControls{false}; - bool setDisplayZoomControls{false}; - bool setSupportMultipleWindows{false}; - int textZoom{0}; - bool thirdPartyCookiesEnabled{false}; - bool hasOnScroll{false}; - std::string injectedJavaScriptObject{}; - std::string allowingReadAccessToURL{}; - bool allowsBackForwardNavigationGestures{false}; - bool allowsInlineMediaPlayback{false}; - bool allowsAirPlayForMediaPlayback{false}; - bool allowsLinkPreview{false}; - bool automaticallyAdjustContentInsets{false}; - bool autoManageStatusBarEnabled{false}; - bool bounces{false}; - WebViewContentInsetStruct contentInset{}; - WebViewContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior{WebViewContentInsetAdjustmentBehavior::Never}; - WebViewContentMode contentMode{WebViewContentMode::Recommended}; - WebViewDataDetectorTypesMask dataDetectorTypes{static_cast( - WebViewDataDetectorTypes::PhoneNumber)}; - double decelerationRate{0.0}; - bool directionalLockEnabled{false}; - bool enableApplePay{false}; - bool hideKeyboardAccessoryView{false}; - bool keyboardDisplayRequiresUserAction{false}; - bool limitsNavigationsToAppBoundDomains{false}; - WebViewMediaCapturePermissionGrantType mediaCapturePermissionGrantType{ - WebViewMediaCapturePermissionGrantType::Prompt}; - bool pagingEnabled{false}; - bool pullToRefreshEnabled{false}; - bool scrollEnabled{false}; - bool sharedCookiesEnabled{false}; - bool textInteractionEnabled{false}; - bool useSharedProcessPool{false}; - std::vector menuItems{}; - std::vector suppressMenuItems{}; - bool hasOnFileDownload{false}; - bool fraudulentWebsiteWarningEnabled{false}; - bool allowFileAccessFromFileURLs{false}; - bool allowUniversalAccessFromFileURLs{false}; - std::string applicationNameForUserAgent{}; - WebViewBasicAuthCredentialStruct basicAuthCredential{}; - bool cacheEnabled{false}; - bool incognito{false}; - std::string injectedJavaScript{}; - std::string injectedJavaScriptBeforeContentLoaded{}; - bool injectedJavaScriptForMainFrameOnly{false}; - bool injectedJavaScriptBeforeContentLoadedForMainFrameOnly{false}; - bool javaScriptCanOpenWindowsAutomatically{false}; - bool javaScriptEnabled{false}; - bool webviewDebuggingEnabled{false}; - bool mediaPlaybackRequiresUserAction{false}; - bool messagingEnabled{false}; - bool hasOnOpenWindowEvent{false}; - bool showsHorizontalScrollIndicator{false}; - bool showsVerticalScrollIndicator{false}; - WebViewNewSourceStruct newSource{}; - std::string userAgent{}; - bool shouldStartLoadWithRequestEnabled{false}; -}; - -} // namespace react -} // namespace facebook diff --git a/harmony/rn_webview/src/main/cpp/RNCWebViewComponentDescriptor.h b/harmony/rn_webview/src/main/cpp/RNCWebViewComponentDescriptor.h new file mode 100644 index 000000000..3181bf1c3 --- /dev/null +++ b/harmony/rn_webview/src/main/cpp/RNCWebViewComponentDescriptor.h @@ -0,0 +1,36 @@ + +#pragma once + +// This file was generated. + +#include +#include +#include + +namespace facebook { +namespace react { + +extern const char RNCWebViewComponentName[] = "RNCWebView"; + +class RNCWebViewProps : public ViewProps { + public: + RNCWebViewProps() = default; + + RNCWebViewProps(const PropsParserContext &context, const RNCWebViewProps &sourceProps, const RawProps &rawProps) + : ViewProps(context, sourceProps, rawProps) {} +}; + +using RNCWebViewShadowNode = ConcreteViewShadowNode< + RNCWebViewComponentName, + RNCWebViewProps, + ViewEventEmitter>; + +class RNCWebViewComponentDescriptor final + : public ConcreteComponentDescriptor { + public: + RNCWebViewComponentDescriptor(ComponentDescriptorParameters const ¶meters) + : ConcreteComponentDescriptor(parameters) {} +}; + +} // namespace react +} // namespace facebook diff --git a/harmony/rn_webview/src/main/cpp/RNCWebViewJSIBinder.h b/harmony/rn_webview/src/main/cpp/RNCWebViewJSIBinder.h new file mode 100644 index 000000000..04787e00a --- /dev/null +++ b/harmony/rn_webview/src/main/cpp/RNCWebViewJSIBinder.h @@ -0,0 +1,113 @@ +#pragma once + +// This file was generated. + +#include "RNOHCorePackage/ComponentBinders/ViewComponentJSIBinder.h" + +namespace rnoh { +class RNCWebViewJSIBinder : public ViewComponentJSIBinder { + protected: + facebook::jsi::Object createNativeProps(facebook::jsi::Runtime &rt) override { + auto object = ViewComponentJSIBinder::createNativeProps(rt); + object.setProperty(rt, "allowFileAccess", true); + object.setProperty(rt, "allowsProtectedMedia", true); + object.setProperty(rt, "allowsFullscreenVideo", true); + object.setProperty(rt, "androidLayerType", true); + object.setProperty(rt, "cacheMode", true); + object.setProperty(rt, "domStorageEnabled", true); + object.setProperty(rt, "downloadingMessage", true); + object.setProperty(rt, "forceDarkOn", true); + object.setProperty(rt, "geolocationEnabled", true); + object.setProperty(rt, "lackPermissionToDownloadMessage", true); + object.setProperty(rt, "messagingModuleName", true); + object.setProperty(rt, "minimumFontSize", true); + object.setProperty(rt, "mixedContentMode", true); + object.setProperty(rt, "nestedScrollEnabled", true); + object.setProperty(rt, "overScrollMode", true); + object.setProperty(rt, "saveFormDataDisabled", true); + object.setProperty(rt, "scalesPageToFit", true); + object.setProperty(rt, "setBuiltInZoomControls", true); + object.setProperty(rt, "setDisplayZoomControls", true); + object.setProperty(rt, "setSupportMultipleWindows", true); + object.setProperty(rt, "textZoom", true); + object.setProperty(rt, "thirdPartyCookiesEnabled", true); + object.setProperty(rt, "hasOnScroll", true); + object.setProperty(rt, "injectedJavaScriptObject", true); + object.setProperty(rt, "allowingReadAccessToURL", true); + object.setProperty(rt, "allowsBackForwardNavigationGestures", true); + object.setProperty(rt, "allowsInlineMediaPlayback", true); + object.setProperty(rt, "allowsAirPlayForMediaPlayback", true); + object.setProperty(rt, "allowsLinkPreview", true); + object.setProperty(rt, "automaticallyAdjustContentInsets", true); + object.setProperty(rt, "autoManageStatusBarEnabled", true); + object.setProperty(rt, "bounces", true); + object.setProperty(rt, "contentInset", "Object"); + object.setProperty(rt, "contentInsetAdjustmentBehavior", true); + object.setProperty(rt, "contentMode", true); + object.setProperty(rt, "dataDetectorTypes", true); + object.setProperty(rt, "decelerationRate", true); + object.setProperty(rt, "directionalLockEnabled", true); + object.setProperty(rt, "enableApplePay", true); + object.setProperty(rt, "hideKeyboardAccessoryView", true); + object.setProperty(rt, "keyboardDisplayRequiresUserAction", true); + object.setProperty(rt, "limitsNavigationsToAppBoundDomains", true); + object.setProperty(rt, "mediaCapturePermissionGrantType", true); + object.setProperty(rt, "pagingEnabled", true); + object.setProperty(rt, "pullToRefreshEnabled", true); + object.setProperty(rt, "scrollEnabled", true); + object.setProperty(rt, "sharedCookiesEnabled", true); + object.setProperty(rt, "textInteractionEnabled", true); + object.setProperty(rt, "useSharedProcessPool", true); + object.setProperty(rt, "menuItems", true); + object.setProperty(rt, "suppressMenuItems", true); + object.setProperty(rt, "hasOnFileDownload", true); + object.setProperty(rt, "fraudulentWebsiteWarningEnabled", true); + object.setProperty(rt, "allowFileAccessFromFileURLs", true); + object.setProperty(rt, "allowUniversalAccessFromFileURLs", true); + object.setProperty(rt, "applicationNameForUserAgent", true); + object.setProperty(rt, "basicAuthCredential", "Object"); + object.setProperty(rt, "cacheEnabled", true); + object.setProperty(rt, "incognito", true); + object.setProperty(rt, "injectedJavaScript", true); + object.setProperty(rt, "injectedJavaScriptBeforeContentLoaded", true); + object.setProperty(rt, "injectedJavaScriptForMainFrameOnly", true); + object.setProperty(rt, "injectedJavaScriptBeforeContentLoadedForMainFrameOnly", true); + object.setProperty(rt, "javaScriptCanOpenWindowsAutomatically", true); + object.setProperty(rt, "javaScriptEnabled", true); + object.setProperty(rt, "webviewDebuggingEnabled", true); + object.setProperty(rt, "mediaPlaybackRequiresUserAction", true); + object.setProperty(rt, "messagingEnabled", true); + object.setProperty(rt, "shouldStartLoadWithRequestEnabled", true); + object.setProperty(rt, "hasOnOpenWindowEvent", true); + object.setProperty(rt, "showsHorizontalScrollIndicator", true); + object.setProperty(rt, "showsVerticalScrollIndicator", true); + object.setProperty(rt, "newSource", "Object"); + object.setProperty(rt, "userAgent", true); + return object; + } + + facebook::jsi::Object createBubblingEventTypes(facebook::jsi::Runtime &rt) override { + facebook::jsi::Object events(rt); + return events; + } + + facebook::jsi::Object createDirectEventTypes(facebook::jsi::Runtime &rt) override { + facebook::jsi::Object events(rt); + events.setProperty(rt, "topContentSizeChange", createDirectEvent(rt, "onContentSizeChange")); + events.setProperty(rt, "topRenderProcessGone", createDirectEvent(rt, "onRenderProcessGone")); + events.setProperty(rt, "topContentProcessDidTerminate", createDirectEvent(rt, "onContentProcessDidTerminate")); + events.setProperty(rt, "topCustomMenuSelection", createDirectEvent(rt, "onCustomMenuSelection")); + events.setProperty(rt, "topFileDownload", createDirectEvent(rt, "onFileDownload")); + events.setProperty(rt, "topLoadingError", createDirectEvent(rt, "onLoadingError")); + events.setProperty(rt, "topLoadingFinish", createDirectEvent(rt, "onLoadingFinish")); + events.setProperty(rt, "topLoadingProgress", createDirectEvent(rt, "onLoadingProgress")); + events.setProperty(rt, "topLoadingStart", createDirectEvent(rt, "onLoadingStart")); + events.setProperty(rt, "topHttpError", createDirectEvent(rt, "onHttpError")); + events.setProperty(rt, "topMessage", createDirectEvent(rt, "onMessage")); + events.setProperty(rt, "topOpenWindow", createDirectEvent(rt, "onOpenWindow")); + events.setProperty(rt, "topScroll", createDirectEvent(rt, "onScroll")); + events.setProperty(rt, "topShouldStartLoadWithRequest", createDirectEvent(rt, "onShouldStartLoadWithRequest")); + return events; + } +}; +} // namespace rnoh diff --git a/harmony/rn_webview/src/main/cpp/WebViewEventEmitRequestHandler.h b/harmony/rn_webview/src/main/cpp/WebViewEventEmitRequestHandler.h deleted file mode 100644 index 54f5ae3e3..000000000 --- a/harmony/rn_webview/src/main/cpp/WebViewEventEmitRequestHandler.h +++ /dev/null @@ -1,137 +0,0 @@ -/* - * MIT License - * - * Copyright (C) 2023 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 - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once -#include -#include "RNOH/ArkJS.h" -#include "RNOH/EventEmitRequestHandler.h" -#include "EventEmitters.h" - -using namespace facebook; -namespace rnoh { - -enum WebViewEventType { - LOADING_ERROR = 0, - LOADING_FINISH = 1, - ON_MESSAGE = 2, - SHOULD_START_LOAD_WITH_REQUEST = 3, -}; - -WebViewEventType getWebViewEventType(ArkJS &arkJs, napi_value eventObject) -{ - auto eventType = arkJs.getString(arkJs.getObjectProperty(eventObject, "type")); - if (eventType == "onLoadingError") { - return WebViewEventType::LOADING_ERROR; - } else if (eventType == "onLoadingFinish") { - return WebViewEventType::LOADING_FINISH; - } else if (eventType == "onMessage") { - return WebViewEventType::ON_MESSAGE; - } else if (eventType == "onShouldStartLoadWithRequest") { - return WebViewEventType::SHOULD_START_LOAD_WITH_REQUEST; - } else { - throw std::runtime_error("Unknown Page event type"); - } -} - -class WebViewEventEmitRequestHandler : public EventEmitRequestHandler { -public: - void handleEvent(EventEmitRequestHandler::Context const &ctx) override -{ - if (ctx.eventName != "RNCWebView") { - return; - } - ArkJS arkJs(ctx.env); - auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter(ctx.tag); - if (eventEmitter == nullptr) { - return; - } - - switch (getWebViewEventType(arkJs, ctx.payload)) { - case WebViewEventType::LOADING_ERROR: { - std::string url = arkJs.getString(arkJs.getObjectProperty(ctx.payload, "url")); - bool loading = arkJs.getBoolean(arkJs.getObjectProperty(ctx.payload, "loading")); - std::string title = arkJs.getString(arkJs.getObjectProperty(ctx.payload, "title")); - bool canGoBack = arkJs.getBoolean(arkJs.getObjectProperty(ctx.payload, "canGoBack")); - bool canGoForward = arkJs.getBoolean(arkJs.getObjectProperty(ctx.payload, "canGoForward")); - double lockIdentifier = arkJs.getDouble(arkJs.getObjectProperty(ctx.payload, "lockIdentifier")); - std::string domain = arkJs.getString(arkJs.getObjectProperty(ctx.payload, "domain")); - int code = (int)arkJs.getDouble(arkJs.getObjectProperty(ctx.payload, "code")); - std::string description = arkJs.getString(arkJs.getObjectProperty(ctx.payload, "description")); - react::WebViewEventEmitter::OnLoadingError event{url, loading, title, canGoBack, - canGoForward, lockIdentifier, domain, code, description}; - eventEmitter->onLoadingError(event); - break; - } - case WebViewEventType::LOADING_FINISH: { - std::string url = arkJs.getString(arkJs.getObjectProperty(ctx.payload, "url")); - bool loading = arkJs.getBoolean(arkJs.getObjectProperty(ctx.payload, "loading")); - std::string title = arkJs.getString(arkJs.getObjectProperty(ctx.payload, "title")); - bool canGoBack = arkJs.getBoolean(arkJs.getObjectProperty(ctx.payload, "canGoBack")); - bool canGoForward = arkJs.getBoolean(arkJs.getObjectProperty(ctx.payload, "canGoForward")); - double lockIdentifier = arkJs.getDouble(arkJs.getObjectProperty(ctx.payload, "lockIdentifier")); - std::string navigationType = arkJs.getString(arkJs.getObjectProperty(ctx.payload, - "navigationType")); - std::string mainDocumentURL = arkJs.getString(arkJs.getObjectProperty(ctx.payload, - "mainDocumentURL")); - react::WebViewEventEmitter::OnLoadingFinish event{url, loading, title, canGoBack, - canGoForward, lockIdentifier, navigationType, mainDocumentURL}; - eventEmitter->onLoadingFinish(event); - break; - } - case WebViewEventType::ON_MESSAGE: { - std::string url = arkJs.getString(arkJs.getObjectProperty(ctx.payload, "url")); - bool loading = arkJs.getBoolean(arkJs.getObjectProperty(ctx.payload, "loading")); - std::string title = arkJs.getString(arkJs.getObjectProperty(ctx.payload, "title")); - bool canGoBack = arkJs.getBoolean(arkJs.getObjectProperty(ctx.payload, "canGoBack")); - bool canGoForward = arkJs.getBoolean(arkJs.getObjectProperty(ctx.payload, "canGoForward")); - double lockIdentifier = arkJs.getDouble(arkJs.getObjectProperty(ctx.payload, "lockIdentifier")); - std::string data = arkJs.getString(arkJs.getObjectProperty(ctx.payload, "data")); - react::WebViewEventEmitter::OnMessage event{url, loading, title, canGoBack, - canGoForward, lockIdentifier, data}; - eventEmitter->onMessage(event); - break; - } - case WebViewEventType::SHOULD_START_LOAD_WITH_REQUEST: { - std::string url = arkJs.getString(arkJs.getObjectProperty(ctx.payload, "url")); - bool loading = arkJs.getBoolean(arkJs.getObjectProperty(ctx.payload, "loading")); - std::string title = arkJs.getString(arkJs.getObjectProperty(ctx.payload, "title")); - bool canGoBack = arkJs.getBoolean(arkJs.getObjectProperty(ctx.payload, "canGoBack")); - bool canGoForward = arkJs.getBoolean(arkJs.getObjectProperty(ctx.payload, "canGoForward")); - double lockIdentifier = arkJs.getDouble(arkJs.getObjectProperty(ctx.payload, "lockIdentifier")); - std::string navigationType = arkJs.getString(arkJs.getObjectProperty(ctx.payload, - "navigationType")); - std::string mainDocumentURL = arkJs.getString(arkJs.getObjectProperty(ctx.payload, - "mainDocumentURL")); - bool isTopFrame = arkJs.getBoolean(arkJs.getObjectProperty(ctx.payload, "isTopFrame")); - react::WebViewEventEmitter::OnShouldStartLoadWithRequest event{url, loading, title, canGoBack, - canGoForward, lockIdentifier, navigationType, mainDocumentURL, isTopFrame}; - eventEmitter->onShouldStartLoadWithRequest(event); - break; - } - default: - break; - } - }; -}; -} // namespace rnoh \ No newline at end of file diff --git a/harmony/rn_webview/src/main/cpp/WebViewJSIBinder.h b/harmony/rn_webview/src/main/cpp/WebViewJSIBinder.h deleted file mode 100644 index 90fa0e087..000000000 --- a/harmony/rn_webview/src/main/cpp/WebViewJSIBinder.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * MIT License - * - * Copyright (C) 2023 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 - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once -#include "RNOHCorePackage/ComponentBinders/ViewComponentJSIBinder.h" - -namespace rnoh { - class WebViewJSIBinder : public ViewComponentJSIBinder { - facebook::jsi::Object createNativeProps(facebook::jsi::Runtime &rt) override - { - auto object = ViewComponentJSIBinder::createNativeProps(rt); - object.setProperty(rt, "newSource", "object"); - object.setProperty(rt, "bounces", "bool"); - object.setProperty(rt, "javaScriptEnabled", "bool"); - object.setProperty(rt, "injectedJavaScript", "string"); - object.setProperty(rt, "messagingEnabled", "bool"); - object.setProperty(rt, "showsHorizontalScrollIndicator", "bool"); - object.setProperty(rt, "showsVerticalScrollIndicator", "bool"); - object.setProperty(rt, "textZoom", "int"); - object.setProperty(rt, "cacheEnabled", "bool"); - object.setProperty(rt, "dataDetectorTypes", "Array"); - object.setProperty(rt, "cacheMode", "string"); - object.setProperty(rt, "domStorageEnabled", "bool"); - object.setProperty(rt, "scalesPageToFit", "bool"); - object.setProperty(rt, "messagingModuleName", "string"); - object.setProperty(rt, "shouldStartLoadWithRequestEnabled", "bool"); - object.setProperty(rt, "webviewDebuggingEnabled", "bool"); - return object; - } - - facebook::jsi::Object createDirectEventTypes(facebook::jsi::Runtime &rt) override - { - facebook::jsi::Object events(rt); - events.setProperty(rt, "topLoadingError", createDirectEvent(rt, "onLoadingError")); - events.setProperty(rt, "topLoadingFinish", createDirectEvent(rt, "onLoadingFinish")); - events.setProperty(rt, "topMessage", createDirectEvent(rt, "onMessage")); - events.setProperty(rt, "topShouldStartLoadWithRequest", createDirectEvent(rt, "onShouldStartLoadWithRequest")); - return events; - } - }; -} // namespace rnoh \ No newline at end of file diff --git a/harmony/rn_webview/src/main/cpp/WebViewNapiBinder.h b/harmony/rn_webview/src/main/cpp/WebViewNapiBinder.h deleted file mode 100644 index d4bb55b02..000000000 --- a/harmony/rn_webview/src/main/cpp/WebViewNapiBinder.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * MIT License - * - * Copyright (C) 2023 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 - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once -#include "RNOHCorePackage/ComponentBinders/ViewComponentNapiBinder.h" -#include "Props.h" - -namespace rnoh { - - class WebViewNapiBinder : public ViewComponentNapiBinder { - public: - napi_value createProps(napi_env env, facebook::react::ShadowView const shadowView) override - { - napi_value napiViewProps = ViewComponentNapiBinder::createProps(env, shadowView); - if (auto props = std::dynamic_pointer_cast(shadowView.props)) { - auto objectBuilder = ArkJS(env).getObjectBuilder(napiViewProps); - auto sourceObject = ArkJS(env).createObjectBuilder(); - sourceObject.addProperty("uri", props->newSource.uri); - sourceObject.addProperty("method", props->newSource.method); - sourceObject.addProperty("body", props->newSource.body); - sourceObject.addProperty("html", props->newSource.html); - sourceObject.addProperty("baseUrl", props->newSource.baseUrl); - sourceObject.addProperty("headers", props->newSource.headers); - return objectBuilder.addProperty("newSource", sourceObject.build()) - .addProperty("javaScriptEnabled", props->javaScriptEnabled) - .addProperty("injectedJavaScript", props->injectedJavaScript) - .addProperty("bounces", props->bounces) - .addProperty("messagingEnabled", props->messagingEnabled) - .addProperty("showsHorizontalScrollIndicator", props->showsHorizontalScrollIndicator) - .addProperty("showsVerticalScrollIndicator", props->showsVerticalScrollIndicator) - .addProperty("textZoom", props->textZoom) - .addProperty("cacheEnabled", props->cacheEnabled) - .addProperty("cacheMode", static_cast(props->cacheMode)) - .addProperty("domStorageEnabled", props->domStorageEnabled) - .addProperty("scalesPageToFit", props->scalesPageToFit) - .addProperty("messagingModuleName", props->messagingModuleName) - .addProperty("shouldStartLoadWithRequestEnabled", props->shouldStartLoadWithRequestEnabled) - .addProperty("webviewDebuggingEnabled", props->webviewDebuggingEnabled) - .build(); - } - return napiViewProps; - }; - }; - -} // namespace rnoh \ No newline at end of file diff --git a/harmony/rn_webview/src/main/cpp/ComponentDescriptors.h b/harmony/rn_webview/src/main/cpp/WebViewPackage.cpp similarity index 57% rename from harmony/rn_webview/src/main/cpp/ComponentDescriptors.h rename to harmony/rn_webview/src/main/cpp/WebViewPackage.cpp index a96968e7e..30eb2b685 100644 --- a/harmony/rn_webview/src/main/cpp/ComponentDescriptors.h +++ b/harmony/rn_webview/src/main/cpp/WebViewPackage.cpp @@ -20,29 +20,8 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. - * - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GenerateComponentDescriptorH.js */ #pragma once - -#include -#include -#include -#include "Props.h" -#include "EventEmitters.h" - -namespace facebook { -namespace react { -extern const char WebViewComponentName[] = "RNCWebView"; -using WebViewShadowNode = - ConcreteViewShadowNode; -using WebViewComponentDescriptor = ConcreteComponentDescriptor; - -} // namespace react -} // namespace facebook +#include "RNOH/Package.h" +// namespace rnoh \ No newline at end of file diff --git a/harmony/rn_webview/src/main/cpp/WebViewPackage.h b/harmony/rn_webview/src/main/cpp/WebViewPackage.h index ab4b666dd..fd8375659 100644 --- a/harmony/rn_webview/src/main/cpp/WebViewPackage.h +++ b/harmony/rn_webview/src/main/cpp/WebViewPackage.h @@ -24,57 +24,83 @@ #pragma once #include "RNOH/Package.h" -#include "ComponentDescriptors.h" -#include "WebViewJSIBinder.h" -#include "WebViewNapiBinder.h" -#include "WebViewEventEmitRequestHandler.h" -#include "RNCWebViewTurboModule.h" +#include "RNOH/ArkTSTurboModule.h" +#include "./RNCWebViewJSIBinder.h" +#include "./RNCWebViewComponentDescriptor.h" +#include "./RNCWebViewTurboModule.h" + using namespace rnoh; using namespace facebook; + class WebViewTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate { public: - SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override - { - if (name == "RNCWebView") { - return std::make_shared(ctx, name); - } + SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override { + if (name == "RNCWebView") { + return std::make_shared(ctx, name); + } return nullptr; }; }; - namespace rnoh { + +class WebViewEventEmitRequestHandler : public EventEmitRequestHandler { +public: + void handleEvent(Context const &ctx) override { + auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter(ctx.tag); + if (eventEmitter == nullptr) { + return; + } + + std::vector supportedEventNames = { + "contentSizeChange", + "renderProcessGone", + "contentProcessDidTerminate", + "customMenuSelection", + "fileDownload", + "loadingError", + "loadingFinish", + "loadingProgress", + "loadingStart", + "httpError", + "message", + "openWindow", + "scroll", + "shouldStartLoadWithRequest", + }; + if (std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != + supportedEventNames.end()) { + eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload)); + } + } +}; + class WebViewPackage : public Package { public: WebViewPackage(Package::Context ctx) : Package(ctx) {} - std::unique_ptr createTurboModuleFactoryDelegate() override - { + std::unique_ptr createTurboModuleFactoryDelegate() override { return std::make_unique(); } - - std::vector createComponentDescriptorProviders() override - { + + std::vector createComponentDescriptorProviders() override { return { - facebook::react::concreteComponentDescriptorProvider(), + facebook::react::concreteComponentDescriptorProvider(), }; } - - ComponentJSIBinderByString createComponentJSIBinderByName() override - { - return {{"RNCWebView", std::make_shared()}}; - }; - - ComponentNapiBinderByString createComponentNapiBinderByName() override - { - return {{"RNCWebView", std::make_shared()}}; + + ComponentJSIBinderByString createComponentJSIBinderByName() override { + return {{"RNCWebView", std::make_shared()}}; }; - - EventEmitRequestHandlers createEventEmitRequestHandlers() override - { - return {std::make_shared()}; + + ComponentNapiBinderByString createComponentNapiBinderByName() override { return {}; }; + + EventEmitRequestHandlers createEventEmitRequestHandlers() override { + return { + std::make_shared(), + }; } - }; +}; } // namespace rnoh \ No newline at end of file diff --git a/harmony/rn_webview/src/main/ets/RNCWebView.ets b/harmony/rn_webview/src/main/ets/RNCWebView.ets index eb754266b..67aecfcfa 100644 --- a/harmony/rn_webview/src/main/ets/RNCWebView.ets +++ b/harmony/rn_webview/src/main/ets/RNCWebView.ets @@ -25,7 +25,7 @@ import { Descriptor, RNOHContext, ViewBaseProps } from '@rnoh/react-native-openharmony'; import webview from '@ohos.web.webview'; import { CallbackState, ShouldRequestUrl } from './ShouldRequestUrl'; -import { RNC } from '@rnoh/react-native-openharmony/generated'; +import { RNC } from './namespace'; import Logger from './Logger'; export class WebViewNewSourceHeader { diff --git a/harmony/rn_webview/src/main/ets/RNCWebViewPackage.ts b/harmony/rn_webview/src/main/ets/RNCWebViewPackage.ts index c01521a16..222cb4dd6 100644 --- a/harmony/rn_webview/src/main/ets/RNCWebViewPackage.ts +++ b/harmony/rn_webview/src/main/ets/RNCWebViewPackage.ts @@ -27,7 +27,7 @@ import type { DescriptorWrapperFactoryByDescriptorTypeCtx } from '@rnoh/react-native-openharmony/ts'; import { RNPackage } from '@rnoh/react-native-openharmony/ts'; -import { RNC } from '@rnoh/react-native-openharmony/generated/ts'; +import { RNC } from './namespace'; export class RNCWebViewPackage extends RNPackage { createDescriptorWrapperFactoryByDescriptorType(ctx: DescriptorWrapperFactoryByDescriptorTypeCtx): DescriptorWrapperFactoryByDescriptorType { diff --git a/harmony/rn_webview/src/main/ets/namespace/index.ts b/harmony/rn_webview/src/main/ets/namespace/index.ts new file mode 100644 index 000000000..b5ac46160 --- /dev/null +++ b/harmony/rn_webview/src/main/ets/namespace/index.ts @@ -0,0 +1 @@ +export * as RNC from "./webview" \ No newline at end of file diff --git a/harmony/rn_webview/src/main/ets/namespace/webview.ts b/harmony/rn_webview/src/main/ets/namespace/webview.ts new file mode 100644 index 000000000..7ab31c28c --- /dev/null +++ b/harmony/rn_webview/src/main/ets/namespace/webview.ts @@ -0,0 +1,495 @@ +import { + Descriptor as ComponentDescriptor, + ViewBaseProps, + ViewRawProps, + ViewDescriptorWrapperBase, + ColorValue, + Color, + RNInstance, + Tag, + RNComponentCommandReceiver, + ViewPropsSelector, +} from '@rnoh/react-native-openharmony/ts'; + + +export namespace RNCWebView { + export const NAME = "RNCWebView" as const + + export interface DirectRawProps { + allowFileAccess?: boolean; + allowsProtectedMedia?: boolean; + allowsFullscreenVideo?: boolean; + androidLayerType?: 'none' | 'software' | 'hardware'; + cacheMode?: 'LOAD_DEFAULT' | 'LOAD_CACHE_ELSE_NETWORK' | 'LOAD_NO_CACHE' | 'LOAD_CACHE_ONLY'; + domStorageEnabled?: boolean; + downloadingMessage?: string; + forceDarkOn?: boolean; + geolocationEnabled?: boolean; + lackPermissionToDownloadMessage?: string; + messagingModuleName: string; + minimumFontSize?: number; + mixedContentMode?: 'never' | 'always' | 'compatibility'; + nestedScrollEnabled?: boolean; + overScrollMode?: string; + saveFormDataDisabled?: boolean; + scalesPageToFit?: boolean; + setBuiltInZoomControls?: boolean; + setDisplayZoomControls?: boolean; + setSupportMultipleWindows?: boolean; + textZoom?: number; + thirdPartyCookiesEnabled?: boolean; + hasOnScroll?: boolean; + injectedJavaScriptObject?: string; + allowingReadAccessToURL?: string; + allowsBackForwardNavigationGestures?: boolean; + allowsInlineMediaPlayback?: boolean; + allowsAirPlayForMediaPlayback?: boolean; + allowsLinkPreview?: boolean; + automaticallyAdjustContentInsets?: boolean; + autoManageStatusBarEnabled?: boolean; + bounces?: boolean; + contentInset?: {top?: number, left?: number, bottom?: number, right?: number}; + contentInsetAdjustmentBehavior?: 'never' | 'automatic' | 'scrollableAxes' | 'always'; + contentMode?: 'recommended' | 'mobile' | 'desktop'; + dataDetectorTypes?: 'address' | 'link' | 'calendarEvent' | 'trackingNumber' | 'flightNumber' | 'lookupSuggestion' | 'phoneNumber' | 'all' | 'none'[]; + decelerationRate?: number; + directionalLockEnabled?: boolean; + enableApplePay?: boolean; + hideKeyboardAccessoryView?: boolean; + keyboardDisplayRequiresUserAction?: boolean; + limitsNavigationsToAppBoundDomains?: boolean; + mediaCapturePermissionGrantType?: 'prompt' | 'grant' | 'deny' | 'grantIfSameHostElsePrompt' | 'grantIfSameHostElseDeny'; + pagingEnabled?: boolean; + pullToRefreshEnabled?: boolean; + scrollEnabled?: boolean; + sharedCookiesEnabled?: boolean; + textInteractionEnabled?: boolean; + useSharedProcessPool?: boolean; + menuItems?: {label: string, key: string}[]; + suppressMenuItems?: string[]; + hasOnFileDownload?: boolean; + fraudulentWebsiteWarningEnabled?: boolean; + allowFileAccessFromFileURLs?: boolean; + allowUniversalAccessFromFileURLs?: boolean; + applicationNameForUserAgent?: string; + basicAuthCredential?: {username: string, password: string}; + cacheEnabled?: boolean; + incognito?: boolean; + injectedJavaScript?: string; + injectedJavaScriptBeforeContentLoaded?: string; + injectedJavaScriptForMainFrameOnly?: boolean; + injectedJavaScriptBeforeContentLoadedForMainFrameOnly?: boolean; + javaScriptCanOpenWindowsAutomatically?: boolean; + javaScriptEnabled?: boolean; + webviewDebuggingEnabled?: boolean; + mediaPlaybackRequiresUserAction?: boolean; + messagingEnabled: boolean; + shouldStartLoadWithRequestEnabled: boolean; + hasOnOpenWindowEvent?: boolean; + showsHorizontalScrollIndicator?: boolean; + showsVerticalScrollIndicator?: boolean; + newSource: {uri?: string, method?: string, body?: string, headers?: {name: string, value: string}[], html?: string, baseUrl?: string}; + userAgent?: string; + } + + export interface Props extends ViewBaseProps {} + + export interface State {} + + export interface RawProps extends ViewRawProps, DirectRawProps {} + + export class PropsSelector extends ViewPropsSelector { + get allowFileAccess() { + return this.rawProps.allowFileAccess ?? false; + } + + get allowsProtectedMedia() { + return this.rawProps.allowsProtectedMedia ?? false; + } + + get allowsFullscreenVideo() { + return this.rawProps.allowsFullscreenVideo ?? false; + } + + get androidLayerType() { + return this.rawProps.androidLayerType ?? 'none'; + } + + get cacheMode() { + return this.rawProps.cacheMode ?? 'LOAD_DEFAULT'; + } + + get domStorageEnabled() { + return this.rawProps.domStorageEnabled ?? false; + } + + get downloadingMessage() { + return this.rawProps.downloadingMessage; + } + + get forceDarkOn() { + return this.rawProps.forceDarkOn ?? false; + } + + get geolocationEnabled() { + return this.rawProps.geolocationEnabled ?? false; + } + + get lackPermissionToDownloadMessage() { + return this.rawProps.lackPermissionToDownloadMessage; + } + + get messagingModuleName() { + return this.rawProps.messagingModuleName; + } + + get minimumFontSize() { + return this.rawProps.minimumFontSize ?? 0; + } + + get mixedContentMode() { + return this.rawProps.mixedContentMode ?? 'never'; + } + + get nestedScrollEnabled() { + return this.rawProps.nestedScrollEnabled ?? false; + } + + get overScrollMode() { + return this.rawProps.overScrollMode; + } + + get saveFormDataDisabled() { + return this.rawProps.saveFormDataDisabled ?? false; + } + + get scalesPageToFit() { + return this.rawProps.scalesPageToFit ?? false; + } + + get setBuiltInZoomControls() { + return this.rawProps.setBuiltInZoomControls ?? false; + } + + get setDisplayZoomControls() { + return this.rawProps.setDisplayZoomControls ?? false; + } + + get setSupportMultipleWindows() { + return this.rawProps.setSupportMultipleWindows ?? false; + } + + get textZoom() { + return this.rawProps.textZoom ?? 0; + } + + get thirdPartyCookiesEnabled() { + return this.rawProps.thirdPartyCookiesEnabled ?? false; + } + + get hasOnScroll() { + return this.rawProps.hasOnScroll ?? false; + } + + get injectedJavaScriptObject() { + return this.rawProps.injectedJavaScriptObject; + } + + get allowingReadAccessToURL() { + return this.rawProps.allowingReadAccessToURL; + } + + get allowsBackForwardNavigationGestures() { + return this.rawProps.allowsBackForwardNavigationGestures ?? false; + } + + get allowsInlineMediaPlayback() { + return this.rawProps.allowsInlineMediaPlayback ?? false; + } + + get allowsAirPlayForMediaPlayback() { + return this.rawProps.allowsAirPlayForMediaPlayback ?? false; + } + + get allowsLinkPreview() { + return this.rawProps.allowsLinkPreview ?? false; + } + + get automaticallyAdjustContentInsets() { + return this.rawProps.automaticallyAdjustContentInsets ?? false; + } + + get autoManageStatusBarEnabled() { + return this.rawProps.autoManageStatusBarEnabled ?? false; + } + + get bounces() { + return this.rawProps.bounces ?? false; + } + + get contentInset() { + return this.rawProps.contentInset; + } + + get contentInsetAdjustmentBehavior() { + return this.rawProps.contentInsetAdjustmentBehavior ?? 'never'; + } + + get contentMode() { + return this.rawProps.contentMode ?? 'recommended'; + } + + get dataDetectorTypes() { + return this.rawProps.dataDetectorTypes; + } + + get decelerationRate() { + return this.rawProps.decelerationRate ?? 0; + } + + get directionalLockEnabled() { + return this.rawProps.directionalLockEnabled ?? false; + } + + get enableApplePay() { + return this.rawProps.enableApplePay ?? false; + } + + get hideKeyboardAccessoryView() { + return this.rawProps.hideKeyboardAccessoryView ?? false; + } + + get keyboardDisplayRequiresUserAction() { + return this.rawProps.keyboardDisplayRequiresUserAction ?? false; + } + + get limitsNavigationsToAppBoundDomains() { + return this.rawProps.limitsNavigationsToAppBoundDomains ?? false; + } + + get mediaCapturePermissionGrantType() { + return this.rawProps.mediaCapturePermissionGrantType ?? 'prompt'; + } + + get pagingEnabled() { + return this.rawProps.pagingEnabled ?? false; + } + + get pullToRefreshEnabled() { + return this.rawProps.pullToRefreshEnabled ?? false; + } + + get scrollEnabled() { + return this.rawProps.scrollEnabled ?? false; + } + + get sharedCookiesEnabled() { + return this.rawProps.sharedCookiesEnabled ?? false; + } + + get textInteractionEnabled() { + return this.rawProps.textInteractionEnabled ?? false; + } + + get useSharedProcessPool() { + return this.rawProps.useSharedProcessPool ?? false; + } + + get menuItems() { + return this.rawProps.menuItems; + } + + get suppressMenuItems() { + return this.rawProps.suppressMenuItems; + } + + get hasOnFileDownload() { + return this.rawProps.hasOnFileDownload ?? false; + } + + get fraudulentWebsiteWarningEnabled() { + return this.rawProps.fraudulentWebsiteWarningEnabled ?? false; + } + + get allowFileAccessFromFileURLs() { + return this.rawProps.allowFileAccessFromFileURLs ?? false; + } + + get allowUniversalAccessFromFileURLs() { + return this.rawProps.allowUniversalAccessFromFileURLs ?? false; + } + + get applicationNameForUserAgent() { + return this.rawProps.applicationNameForUserAgent; + } + + get basicAuthCredential() { + return this.rawProps.basicAuthCredential; + } + + get cacheEnabled() { + return this.rawProps.cacheEnabled ?? false; + } + + get incognito() { + return this.rawProps.incognito ?? false; + } + + get injectedJavaScript() { + return this.rawProps.injectedJavaScript; + } + + get injectedJavaScriptBeforeContentLoaded() { + return this.rawProps.injectedJavaScriptBeforeContentLoaded; + } + + get injectedJavaScriptForMainFrameOnly() { + return this.rawProps.injectedJavaScriptForMainFrameOnly ?? false; + } + + get injectedJavaScriptBeforeContentLoadedForMainFrameOnly() { + return this.rawProps.injectedJavaScriptBeforeContentLoadedForMainFrameOnly ?? false; + } + + get javaScriptCanOpenWindowsAutomatically() { + return this.rawProps.javaScriptCanOpenWindowsAutomatically ?? false; + } + + get javaScriptEnabled() { + return this.rawProps.javaScriptEnabled ?? false; + } + + get webviewDebuggingEnabled() { + return this.rawProps.webviewDebuggingEnabled ?? false; + } + + get mediaPlaybackRequiresUserAction() { + return this.rawProps.mediaPlaybackRequiresUserAction ?? false; + } + + get messagingEnabled() { + return this.rawProps.messagingEnabled ?? false; + } + + get shouldStartLoadWithRequestEnabled() { + return this.rawProps.shouldStartLoadWithRequestEnabled ?? false; + } + + get hasOnOpenWindowEvent() { + return this.rawProps.hasOnOpenWindowEvent ?? false; + } + + get showsHorizontalScrollIndicator() { + return this.rawProps.showsHorizontalScrollIndicator ?? false; + } + + get showsVerticalScrollIndicator() { + return this.rawProps.showsVerticalScrollIndicator ?? false; + } + + get newSource() { + return this.rawProps.newSource; + } + + get userAgent() { + return this.rawProps.userAgent; + } + + + } + + export type Descriptor = ComponentDescriptor< + typeof NAME, + Props, + State, + RawProps + >; + + export class DescriptorWrapper extends ViewDescriptorWrapperBase< + typeof NAME, + Props, + State, + RawProps, + PropsSelector + > { + protected createPropsSelector() { + return new PropsSelector(this.descriptor.props, this.descriptor.rawProps) + } + } + + export interface EventPayloadByName { + "contentSizeChange": {url: string, loading: boolean, title: string, canGoBack: boolean, canGoForward: boolean, lockIdentifier: number} + "renderProcessGone": {didCrash: boolean} + "contentProcessDidTerminate": {url: string, loading: boolean, title: string, canGoBack: boolean, canGoForward: boolean, lockIdentifier: number} + "customMenuSelection": {label: string, key: string, selectedText: string} + "fileDownload": {downloadUrl: string} + "loadingError": {url: string, loading: boolean, title: string, canGoBack: boolean, canGoForward: boolean, lockIdentifier: number, domain?: string, code: number, description: string} + "loadingFinish": {url: string, loading: boolean, title: string, canGoBack: boolean, canGoForward: boolean, lockIdentifier: number, navigationType: 'click' | 'formsubmit' | 'backforward' | 'reload' | 'formresubmit' | 'other', mainDocumentURL?: string} + "loadingProgress": {url: string, loading: boolean, title: string, canGoBack: boolean, canGoForward: boolean, lockIdentifier: number, progress: number} + "loadingStart": {url: string, loading: boolean, title: string, canGoBack: boolean, canGoForward: boolean, lockIdentifier: number, navigationType: 'click' | 'formsubmit' | 'backforward' | 'reload' | 'formresubmit' | 'other', mainDocumentURL?: string} + "httpError": {url: string, loading: boolean, title: string, canGoBack: boolean, canGoForward: boolean, lockIdentifier: number, description: string, statusCode: number} + "message": {url: string, loading: boolean, title: string, canGoBack: boolean, canGoForward: boolean, lockIdentifier: number, data: string} + "openWindow": {targetUrl: string} + "scroll": {contentInset: {bottom: number, left: number, right: number, top: number}, contentOffset: {y: number, x: number}, contentSize: {height: number, width: number}, layoutMeasurement: {height: number, width: number}, targetContentOffset?: {y: number, x: number}, velocity?: {y: number, x: number}, zoomScale?: number, responderIgnoreScroll?: boolean} + "shouldStartLoadWithRequest": {url: string, loading: boolean, title: string, canGoBack: boolean, canGoForward: boolean, lockIdentifier: number, navigationType: 'click' | 'formsubmit' | 'backforward' | 'reload' | 'formresubmit' | 'other', mainDocumentURL?: string, isTopFrame: boolean} + } + + export class EventEmitter { + constructor(private rnInstance: RNInstance, private tag: Tag) {} + + emit(eventName: TEventName, payload: EventPayloadByName[TEventName]) { + this.rnInstance.emitComponentEvent(this.tag, eventName, payload) + } + } + + export interface CommandArgvByName { + "goBack": [] + "goForward": [] + "reload": [] + "stopLoading": [] + "injectJavaScript": [string] + "requestFocus": [] + "postMessage": [string] + "loadUrl": [string] + "clearFormData": [] + "clearCache": [boolean] + "clearHistory": [] + } + + export class CommandReceiver { + private listenersByCommandName = new Map void>>() + private cleanUp: (() => void) | undefined = undefined + + constructor(private componentCommandReceiver: RNComponentCommandReceiver, private tag: Tag) { + } + + subscribe(commandName: TCommandName, listener: (argv: CommandArgvByName[TCommandName]) => void) { + if (!this.listenersByCommandName.has(commandName)) { + this.listenersByCommandName.set(commandName, new Set()) + } + this.listenersByCommandName.get(commandName)!.add(listener) + const hasRegisteredCommandReceiver = !!this.cleanUp + if (!hasRegisteredCommandReceiver) { + this.cleanUp = this.componentCommandReceiver.registerCommandCallback(this.tag, (commandName: string, argv: any[]) => { + if (this.listenersByCommandName.has(commandName)) { + const listeners = this.listenersByCommandName.get(commandName)! + listeners.forEach(listener => { + listener(argv) + }) + } + }) + } + + return () => { + this.listenersByCommandName.get(commandName)?.delete(listener) + if (this.listenersByCommandName.get(commandName)?.size ?? 0 === 0) { + this.listenersByCommandName.delete(commandName) + } + if (this.listenersByCommandName.size === 0) { + this.cleanUp?.() + } + } + } + } + +}