@ng-native/desktop 0.0.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +52 -0
- package/app.plugin.cjs +17 -0
- package/bin/app-config.mjs +168 -0
- package/bin/autolink.mjs +224 -0
- package/bin/cli.mjs +158 -0
- package/bin/host.mjs +427 -0
- package/bin/ng-native-desktop.mjs +4 -0
- package/bin/package.mjs +971 -0
- package/bin/plist.mjs +68 -0
- package/bin/prebuilt.mjs +328 -0
- package/bin/toolchain.mjs +192 -0
- package/native/CMakeLists.txt +276 -0
- package/native/appkit/CMakeLists.txt +109 -0
- package/native/appkit/address-search.h +26 -0
- package/native/appkit/address-search.mm +277 -0
- package/native/appkit/animation-frames.h +14 -0
- package/native/appkit/animation-frames.mm +106 -0
- package/native/appkit/app-info.h +12 -0
- package/native/appkit/app-info.mm +98 -0
- package/native/appkit/app-updater.mm +128 -0
- package/native/appkit/app-windows.h +81 -0
- package/native/appkit/app-windows.mm +318 -0
- package/native/appkit/appkit-backend.h +73 -0
- package/native/appkit/appkit-backend.mm +276 -0
- package/native/appkit/apple-authentication.h +19 -0
- package/native/appkit/apple-authentication.mm +248 -0
- package/native/appkit/apple-button-view.h +10 -0
- package/native/appkit/apple-button-view.mm +37 -0
- package/native/appkit/apple-id-button.h +16 -0
- package/native/appkit/apple-id-button.mm +50 -0
- package/native/appkit/audio.h +16 -0
- package/native/appkit/audio.mm +275 -0
- package/native/appkit/battery.h +13 -0
- package/native/appkit/battery.mm +92 -0
- package/native/appkit/bookmarks.h +17 -0
- package/native/appkit/bookmarks.mm +145 -0
- package/native/appkit/calendar.h +25 -0
- package/native/appkit/calendar.mm +660 -0
- package/native/appkit/camera-view.h +15 -0
- package/native/appkit/camera-view.mm +130 -0
- package/native/appkit/camera.h +39 -0
- package/native/appkit/camera.mm +362 -0
- package/native/appkit/cg-canvas.h +17 -0
- package/native/appkit/cg-canvas.mm +518 -0
- package/native/appkit/component-view.h +17 -0
- package/native/appkit/crypto.h +19 -0
- package/native/appkit/crypto.mm +78 -0
- package/native/appkit/desktop-expo.h +29 -0
- package/native/appkit/desktop-expo.mm +385 -0
- package/native/appkit/expo-image-drawing.h +46 -0
- package/native/appkit/expo-image-drawing.mm +131 -0
- package/native/appkit/expo-image-view.h +15 -0
- package/native/appkit/expo-image-view.mm +182 -0
- package/native/appkit/expo-ui-renderer.h +68 -0
- package/native/appkit/expo-ui-renderer.mm +101 -0
- package/native/appkit/expo-ui-view.h +26 -0
- package/native/appkit/expo-ui-view.mm +134 -0
- package/native/appkit/expo-ui.swift +1284 -0
- package/native/appkit/file-system.h +16 -0
- package/native/appkit/file-system.mm +140 -0
- package/native/appkit/fonts.h +12 -0
- package/native/appkit/fonts.mm +48 -0
- package/native/appkit/geocoder.h +19 -0
- package/native/appkit/geocoder.mm +101 -0
- package/native/appkit/glass-effect.h +22 -0
- package/native/appkit/glass-effect.mm +63 -0
- package/native/appkit/glass-view.h +8 -0
- package/native/appkit/glass-view.mm +65 -0
- package/native/appkit/header-toolbar.h +60 -0
- package/native/appkit/header-toolbar.mm +629 -0
- package/native/appkit/host-view.h +54 -0
- package/native/appkit/host-view.mm +1200 -0
- package/native/appkit/image-manipulator.h +14 -0
- package/native/appkit/image-manipulator.mm +191 -0
- package/native/appkit/image-request.h +22 -0
- package/native/appkit/image-request.mm +62 -0
- package/native/appkit/image-view.h +8 -0
- package/native/appkit/image-view.mm +142 -0
- package/native/appkit/input-replay.h +25 -0
- package/native/appkit/input-replay.mm +418 -0
- package/native/appkit/language-model.h +14 -0
- package/native/appkit/language-model.mm +99 -0
- package/native/appkit/language-model.swift +472 -0
- package/native/appkit/local-authentication.h +15 -0
- package/native/appkit/local-authentication.mm +133 -0
- package/native/appkit/location.h +16 -0
- package/native/appkit/location.mm +214 -0
- package/native/appkit/main.mm +1515 -0
- package/native/appkit/map-view.h +15 -0
- package/native/appkit/map-view.mm +109 -0
- package/native/appkit/maps.h +35 -0
- package/native/appkit/maps.mm +343 -0
- package/native/appkit/menu-bar.h +22 -0
- package/native/appkit/menu-bar.mm +208 -0
- package/native/appkit/modal-focus.h +16 -0
- package/native/appkit/modal-focus.mm +26 -0
- package/native/appkit/modal-host-view.h +79 -0
- package/native/appkit/modal-host-view.mm +442 -0
- package/native/appkit/native-controls.h +22 -0
- package/native/appkit/native-controls.mm +431 -0
- package/native/appkit/network-state.h +12 -0
- package/native/appkit/network-state.mm +64 -0
- package/native/appkit/network.h +14 -0
- package/native/appkit/network.mm +396 -0
- package/native/appkit/notifications.h +19 -0
- package/native/appkit/notifications.mm +309 -0
- package/native/appkit/photo-library.h +33 -0
- package/native/appkit/photo-library.mm +548 -0
- package/native/appkit/pointer-buttons.h +32 -0
- package/native/appkit/presentation-label.h +15 -0
- package/native/appkit/presentation-label.mm +12 -0
- package/native/appkit/presented-screen.h +19 -0
- package/native/appkit/presented-screen.mm +181 -0
- package/native/appkit/printing.h +42 -0
- package/native/appkit/printing.mm +393 -0
- package/native/appkit/push.h +19 -0
- package/native/appkit/push.mm +81 -0
- package/native/appkit/red-box.h +26 -0
- package/native/appkit/red-box.mm +387 -0
- package/native/appkit/screen-capture.h +21 -0
- package/native/appkit/screen-capture.mm +92 -0
- package/native/appkit/scroll-view.h +13 -0
- package/native/appkit/scroll-view.mm +251 -0
- package/native/appkit/scrollers.h +25 -0
- package/native/appkit/scrollers.mm +43 -0
- package/native/appkit/search-field.h +34 -0
- package/native/appkit/search-field.mm +291 -0
- package/native/appkit/search-toolbar-item.h +19 -0
- package/native/appkit/search-toolbar-item.mm +269 -0
- package/native/appkit/share-picker.h +34 -0
- package/native/appkit/share-picker.mm +121 -0
- package/native/appkit/split-view.h +77 -0
- package/native/appkit/split-view.mm +1206 -0
- package/native/appkit/store-review.h +13 -0
- package/native/appkit/store-review.mm +28 -0
- package/native/appkit/surface-view.h +45 -0
- package/native/appkit/surface-view.mm +558 -0
- package/native/appkit/svg-view.h +17 -0
- package/native/appkit/svg-view.mm +57 -0
- package/native/appkit/symbol-drawing.h +24 -0
- package/native/appkit/symbol-drawing.mm +117 -0
- package/native/appkit/symbol-view.h +8 -0
- package/native/appkit/symbol-view.mm +33 -0
- package/native/appkit/system-access.h +34 -0
- package/native/appkit/system-access.mm +210 -0
- package/native/appkit/system.h +24 -0
- package/native/appkit/system.mm +403 -0
- package/native/appkit/test-launch.h +36 -0
- package/native/appkit/test-launch.mm +115 -0
- package/native/appkit/text-input-field.h +76 -0
- package/native/appkit/text-input-field.mm +444 -0
- package/native/appkit/text-layout.h +58 -0
- package/native/appkit/text-layout.mm +477 -0
- package/native/appkit/text-recognition.h +13 -0
- package/native/appkit/text-recognition.mm +102 -0
- package/native/appkit/tracking.h +13 -0
- package/native/appkit/tracking.mm +51 -0
- package/native/appkit/tray-and-dock.h +45 -0
- package/native/appkit/tray-and-dock.mm +130 -0
- package/native/appkit/undo.h +23 -0
- package/native/appkit/undo.mm +125 -0
- package/native/appkit/updates.h +17 -0
- package/native/appkit/updates.mm +71 -0
- package/native/appkit/video-view.h +10 -0
- package/native/appkit/video-view.mm +42 -0
- package/native/appkit/video.h +38 -0
- package/native/appkit/video.mm +404 -0
- package/native/appkit/web-browser.h +12 -0
- package/native/appkit/web-browser.mm +97 -0
- package/native/appkit/web-view-component.h +9 -0
- package/native/appkit/web-view-component.mm +56 -0
- package/native/appkit/web-view.h +31 -0
- package/native/appkit/web-view.mm +394 -0
- package/native/cmake/libraries/react-native-reanimated.cmake +45 -0
- package/native/cmake/libraries/react-native-worklets.cmake +46 -0
- package/native/cmake/libraries.cmake +109 -0
- package/native/cmake/linked-modules.cmake +112 -0
- package/native/cmake/react-native.cmake +175 -0
- package/native/cmake/runtime-dependencies.cmake +34 -0
- package/native/cmake/swift.cmake +43 -0
- package/native/cmake/third-party.cmake +74 -0
- package/native/core/include/ngn/absent-views.h +27 -0
- package/native/core/include/ngn/accessibility.h +140 -0
- package/native/core/include/ngn/address-search.h +69 -0
- package/native/core/include/ngn/animation-frames.h +39 -0
- package/native/core/include/ngn/app-info.h +52 -0
- package/native/core/include/ngn/app-menus.h +146 -0
- package/native/core/include/ngn/app-windows.h +181 -0
- package/native/core/include/ngn/apple-authentication.h +116 -0
- package/native/core/include/ngn/asset.h +28 -0
- package/native/core/include/ngn/audio.h +125 -0
- package/native/core/include/ngn/back-swipe.h +112 -0
- package/native/core/include/ngn/battery.h +48 -0
- package/native/core/include/ngn/bytes.h +59 -0
- package/native/core/include/ngn/calendar.h +180 -0
- package/native/core/include/ngn/camera.h +128 -0
- package/native/core/include/ngn/control-sizes.h +111 -0
- package/native/core/include/ngn/core-modules.h +105 -0
- package/native/core/include/ngn/crypto.h +38 -0
- package/native/core/include/ngn/default-menu.h +91 -0
- package/native/core/include/ngn/desktop-expo.h +193 -0
- package/native/core/include/ngn/desktop-modal.h +109 -0
- package/native/core/include/ngn/desktop-props.h +75 -0
- package/native/core/include/ngn/desktop-view-props.h +110 -0
- package/native/core/include/ngn/dev-server.h +33 -0
- package/native/core/include/ngn/download.h +24 -0
- package/native/core/include/ngn/expo-image.h +192 -0
- package/native/core/include/ngn/expo-ui.h +133 -0
- package/native/core/include/ngn/file-system.h +274 -0
- package/native/core/include/ngn/focus-order.h +63 -0
- package/native/core/include/ngn/fonts.h +64 -0
- package/native/core/include/ngn/gestures.h +305 -0
- package/native/core/include/ngn/glass.h +67 -0
- package/native/core/include/ngn/header-bar.h +112 -0
- package/native/core/include/ngn/host-state.h +243 -0
- package/native/core/include/ngn/image-manipulator.h +70 -0
- package/native/core/include/ngn/input-dispatcher.h +211 -0
- package/native/core/include/ngn/input-script.h +56 -0
- package/native/core/include/ngn/input.h +112 -0
- package/native/core/include/ngn/key-value-store.h +41 -0
- package/native/core/include/ngn/language-model.h +69 -0
- package/native/core/include/ngn/launch-frame.h +47 -0
- package/native/core/include/ngn/launch-settings.h +98 -0
- package/native/core/include/ngn/layout-animations.h +24 -0
- package/native/core/include/ngn/library-components.h +13 -0
- package/native/core/include/ngn/library-glue.h +53 -0
- package/native/core/include/ngn/live-regions.h +54 -0
- package/native/core/include/ngn/local-authentication.h +74 -0
- package/native/core/include/ngn/location.h +89 -0
- package/native/core/include/ngn/maps.h +226 -0
- package/native/core/include/ngn/module-registry.h +51 -0
- package/native/core/include/ngn/mounting-backend.h +96 -0
- package/native/core/include/ngn/mounting-manager.h +155 -0
- package/native/core/include/ngn/native-controls.h +161 -0
- package/native/core/include/ngn/native-module.h +109 -0
- package/native/core/include/ngn/network-state.h +44 -0
- package/native/core/include/ngn/network.h +100 -0
- package/native/core/include/ngn/notifications.h +185 -0
- package/native/core/include/ngn/photo-library.h +130 -0
- package/native/core/include/ngn/printing.h +69 -0
- package/native/core/include/ngn/processes.h +114 -0
- package/native/core/include/ngn/red-box.h +119 -0
- package/native/core/include/ngn/reload-thread.h +258 -0
- package/native/core/include/ngn/runtime.h +161 -0
- package/native/core/include/ngn/safe-areas.h +77 -0
- package/native/core/include/ngn/screen-capture.h +35 -0
- package/native/core/include/ngn/screen-presentation.h +85 -0
- package/native/core/include/ngn/screen-stacks.h +80 -0
- package/native/core/include/ngn/scrollers.h +106 -0
- package/native/core/include/ngn/sharing.h +39 -0
- package/native/core/include/ngn/spawn-rules.h +78 -0
- package/native/core/include/ngn/splash-screen.h +41 -0
- package/native/core/include/ngn/split-view.h +270 -0
- package/native/core/include/ngn/sqlite.h +38 -0
- package/native/core/include/ngn/store-review.h +26 -0
- package/native/core/include/ngn/surface-book.h +101 -0
- package/native/core/include/ngn/svg.h +393 -0
- package/native/core/include/ngn/symbol.h +90 -0
- package/native/core/include/ngn/system.h +102 -0
- package/native/core/include/ngn/tabs-host.h +171 -0
- package/native/core/include/ngn/text-input.h +125 -0
- package/native/core/include/ngn/text-measurer.h +38 -0
- package/native/core/include/ngn/text-recognition.h +55 -0
- package/native/core/include/ngn/tracking.h +34 -0
- package/native/core/include/ngn/tray-and-dock.h +107 -0
- package/native/core/include/ngn/undo.h +37 -0
- package/native/core/include/ngn/updates.h +253 -0
- package/native/core/include/ngn/video.h +126 -0
- package/native/core/include/ngn/view-box.h +126 -0
- package/native/core/include/ngn/view-transform.h +26 -0
- package/native/core/include/ngn/view-tree.h +85 -0
- package/native/core/include/ngn/web-browser.h +45 -0
- package/native/core/include/ngn/web-view.h +133 -0
- package/native/core/include/ngn/worklet-host.h +98 -0
- package/native/core/src/absent-views.cpp +41 -0
- package/native/core/src/accessibility.cpp +374 -0
- package/native/core/src/animation-frames.cpp +49 -0
- package/native/core/src/app-menus.cpp +352 -0
- package/native/core/src/app-windows.cpp +444 -0
- package/native/core/src/back-swipe.cpp +91 -0
- package/native/core/src/bytes.cpp +158 -0
- package/native/core/src/control-sizes.cpp +232 -0
- package/native/core/src/default-menu.cpp +96 -0
- package/native/core/src/desktop-modal.cpp +162 -0
- package/native/core/src/desktop-view-props.cpp +80 -0
- package/native/core/src/dev-server-helper.cpp +152 -0
- package/native/core/src/dev-server.cpp +103 -0
- package/native/core/src/download.cpp +53 -0
- package/native/core/src/expo-image.cpp +548 -0
- package/native/core/src/expo-ui.cpp +203 -0
- package/native/core/src/focus-order.cpp +441 -0
- package/native/core/src/gestures.cpp +1806 -0
- package/native/core/src/glass.cpp +49 -0
- package/native/core/src/header-bar.cpp +104 -0
- package/native/core/src/host-services.cpp +50 -0
- package/native/core/src/host-state.cpp +61 -0
- package/native/core/src/input-dispatcher.cpp +727 -0
- package/native/core/src/input-script.cpp +123 -0
- package/native/core/src/key-value-store.cpp +169 -0
- package/native/core/src/launch-settings.cpp +148 -0
- package/native/core/src/layout-animations.cpp +62 -0
- package/native/core/src/libraries/RNCWebViewSpec.cpp +80 -0
- package/native/core/src/libraries/react-native-reanimated.cpp +216 -0
- package/native/core/src/libraries/react-native-worklets.cpp +192 -0
- package/native/core/src/libraries/rnscreens.cpp +125 -0
- package/native/core/src/libraries/rnsvg.cpp +345 -0
- package/native/core/src/libraries/safeareacontext.cpp +70 -0
- package/native/core/src/libraries/worklets-idle-frames.js +70 -0
- package/native/core/src/library-glue.cpp +35 -0
- package/native/core/src/live-regions.cpp +122 -0
- package/native/core/src/module-registry.cpp +50 -0
- package/native/core/src/modules/accessibility-manager.cpp +98 -0
- package/native/core/src/modules/address-search.cpp +219 -0
- package/native/core/src/modules/alert-manager.cpp +140 -0
- package/native/core/src/modules/app-info.cpp +74 -0
- package/native/core/src/modules/app-modules.cpp +405 -0
- package/native/core/src/modules/apple-authentication.cpp +188 -0
- package/native/core/src/modules/asset.cpp +111 -0
- package/native/core/src/modules/async-storage.cpp +192 -0
- package/native/core/src/modules/audio.cpp +541 -0
- package/native/core/src/modules/battery.cpp +88 -0
- package/native/core/src/modules/calendar.cpp +457 -0
- package/native/core/src/modules/camera.cpp +221 -0
- package/native/core/src/modules/core-modules.cpp +62 -0
- package/native/core/src/modules/crypto.cpp +117 -0
- package/native/core/src/modules/desktop-expo.cpp +527 -0
- package/native/core/src/modules/file-system.cpp +941 -0
- package/native/core/src/modules/fonts.cpp +163 -0
- package/native/core/src/modules/image-loader.cpp +105 -0
- package/native/core/src/modules/image-manipulator.cpp +305 -0
- package/native/core/src/modules/language-model.cpp +195 -0
- package/native/core/src/modules/local-authentication.cpp +140 -0
- package/native/core/src/modules/location.cpp +186 -0
- package/native/core/src/modules/maps.cpp +500 -0
- package/native/core/src/modules/network-state.cpp +72 -0
- package/native/core/src/modules/networking.cpp +387 -0
- package/native/core/src/modules/notifications.cpp +549 -0
- package/native/core/src/modules/photo-library.cpp +371 -0
- package/native/core/src/modules/printing.cpp +201 -0
- package/native/core/src/modules/screen-capture.cpp +71 -0
- package/native/core/src/modules/sharing.cpp +59 -0
- package/native/core/src/modules/splash-screen.cpp +70 -0
- package/native/core/src/modules/sqlite.cpp +421 -0
- package/native/core/src/modules/store-review.cpp +23 -0
- package/native/core/src/modules/text-recognition.cpp +107 -0
- package/native/core/src/modules/tracking.cpp +46 -0
- package/native/core/src/modules/undo.cpp +59 -0
- package/native/core/src/modules/video.cpp +366 -0
- package/native/core/src/modules/web-browser.cpp +100 -0
- package/native/core/src/modules/web-socket.cpp +266 -0
- package/native/core/src/mounting-manager.cpp +380 -0
- package/native/core/src/native-controls.cpp +129 -0
- package/native/core/src/native-module.cpp +250 -0
- package/native/core/src/network.cpp +219 -0
- package/native/core/src/posix-launcher.cpp +366 -0
- package/native/core/src/processes.cpp +324 -0
- package/native/core/src/red-box-errors.js +83 -0
- package/native/core/src/red-box.cpp +306 -0
- package/native/core/src/runtime.cpp +422 -0
- package/native/core/src/safe-areas.cpp +130 -0
- package/native/core/src/screen-presentation.cpp +61 -0
- package/native/core/src/screen-stacks.cpp +254 -0
- package/native/core/src/scrollers.cpp +181 -0
- package/native/core/src/spawn-rules.cpp +292 -0
- package/native/core/src/split-view.cpp +343 -0
- package/native/core/src/svg.cpp +1883 -0
- package/native/core/src/symbol.cpp +94 -0
- package/native/core/src/tabs-host.cpp +234 -0
- package/native/core/src/text-input.cpp +126 -0
- package/native/core/src/text-layout-manager.cpp +63 -0
- package/native/core/src/tray-and-dock.cpp +154 -0
- package/native/core/src/updates.cpp +965 -0
- package/native/core/src/view-box.cpp +788 -0
- package/native/core/src/view-transform.cpp +45 -0
- package/native/core/src/view-tree.cpp +234 -0
- package/native/core/src/web-view.cpp +143 -0
- package/native/core/src/worklet-host.cpp +10 -0
- package/native/scripts/build-hermes.sh +44 -0
- package/native/scripts/build.sh +171 -0
- package/native/scripts/cache-dir.sh +18 -0
- package/native/scripts/codegen-library.sh +193 -0
- package/native/scripts/compiler-launcher.sh +17 -0
- package/native/scripts/fetch.sh +174 -0
- package/native/scripts/hermes-built.sh +10 -0
- package/native/scripts/host-dir.sh +16 -0
- package/native/scripts/macos-target.sh +8 -0
- package/native/scripts/make-prebuilt.mjs +360 -0
- package/native/scripts/prebuilt-host-cache.mjs +158 -0
- package/native/shim/openssl/sha.h +22 -0
- package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +37 -0
- package/package.json +73 -1
- package/prebuilt.json +33 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
#import "web-view.h"
|
|
2
|
+
|
|
3
|
+
#include <set>
|
|
4
|
+
|
|
5
|
+
using ngn::WebViewConfig;
|
|
6
|
+
|
|
7
|
+
namespace {
|
|
8
|
+
|
|
9
|
+
NSString *ns(const std::string &text) {
|
|
10
|
+
NSString *made = [[NSString alloc] initWithBytes:text.data() length:text.size() encoding:NSUTF8StringEncoding];
|
|
11
|
+
return made != nil ? made : @"";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
std::string str(NSString *text) {
|
|
15
|
+
return text != nil ? std::string(text.UTF8String) : std::string();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
NSString *navigationTypeName(WKNavigationType type) {
|
|
19
|
+
switch (type) {
|
|
20
|
+
case WKNavigationTypeLinkActivated:
|
|
21
|
+
return @"click";
|
|
22
|
+
case WKNavigationTypeFormSubmitted:
|
|
23
|
+
return @"formsubmit";
|
|
24
|
+
case WKNavigationTypeBackForward:
|
|
25
|
+
return @"backforward";
|
|
26
|
+
case WKNavigationTypeReload:
|
|
27
|
+
return @"reload";
|
|
28
|
+
case WKNavigationTypeFormResubmitted:
|
|
29
|
+
return @"formresubmit";
|
|
30
|
+
default:
|
|
31
|
+
return @"other";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
bool sameScripts(const WebViewConfig &a, const WebViewConfig &b) {
|
|
36
|
+
return a.injectedJavaScript == b.injectedJavaScript &&
|
|
37
|
+
a.injectedJavaScriptBeforeContentLoaded == b.injectedJavaScriptBeforeContentLoaded &&
|
|
38
|
+
a.injectedJavaScriptForMainFrameOnly == b.injectedJavaScriptForMainFrameOnly &&
|
|
39
|
+
a.injectedJavaScriptBeforeContentLoadedForMainFrameOnly == b.injectedJavaScriptBeforeContentLoadedForMainFrameOnly &&
|
|
40
|
+
a.injectedJavaScriptObject == b.injectedJavaScriptObject && a.messagingEnabled == b.messagingEnabled;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
} // namespace
|
|
44
|
+
|
|
45
|
+
// A weak hop for WKUserContentController, which keeps its script message handlers strongly.
|
|
46
|
+
@interface NGNWeakScriptMessageHandler : NSObject <WKScriptMessageHandler>
|
|
47
|
+
@property (nonatomic, weak) id<WKScriptMessageHandler> target;
|
|
48
|
+
@end
|
|
49
|
+
|
|
50
|
+
@implementation NGNWeakScriptMessageHandler
|
|
51
|
+
- (void)userContentController:(WKUserContentController *)controller didReceiveScriptMessage:(WKScriptMessage *)message {
|
|
52
|
+
[self.target userContentController:controller didReceiveScriptMessage:message];
|
|
53
|
+
}
|
|
54
|
+
@end
|
|
55
|
+
|
|
56
|
+
@implementation NGNWebViewController {
|
|
57
|
+
std::shared_ptr<ngn::NavigationLocks> _locks;
|
|
58
|
+
std::function<void(const std::string &, folly::dynamic)> _send;
|
|
59
|
+
std::function<void(const std::string &)> _openExternally;
|
|
60
|
+
std::optional<WebViewConfig> _config;
|
|
61
|
+
std::set<int> _held;
|
|
62
|
+
WKWebView *_webView;
|
|
63
|
+
// The pick holding the page's file, open while the page is shown.
|
|
64
|
+
std::shared_ptr<ngn::FileAccess::Use> _fileUse;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
- (instancetype)initWithLocks:(std::shared_ptr<ngn::NavigationLocks>)locks
|
|
68
|
+
send:(std::function<void(const std::string &, folly::dynamic)>)send
|
|
69
|
+
openExternally:(std::function<void(const std::string &)>)openExternally {
|
|
70
|
+
if ((self = [super init])) {
|
|
71
|
+
_locks = std::move(locks);
|
|
72
|
+
_send = std::move(send);
|
|
73
|
+
_openExternally = std::move(openExternally);
|
|
74
|
+
}
|
|
75
|
+
return self;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
- (void)dealloc {
|
|
79
|
+
[self invalidate];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
- (WKWebView *)webView {
|
|
83
|
+
return _webView;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
- (folly::dynamic)baseEvent {
|
|
87
|
+
return ngn::webViewEvent({
|
|
88
|
+
.url = str(_webView.URL.absoluteString),
|
|
89
|
+
.title = str(_webView.title),
|
|
90
|
+
.loading = static_cast<bool>(_webView.loading),
|
|
91
|
+
.canGoBack = static_cast<bool>(_webView.canGoBack),
|
|
92
|
+
.canGoForward = static_cast<bool>(_webView.canGoForward),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
- (void)send:(const std::string &)name extra:(folly::dynamic)extra {
|
|
97
|
+
auto event = [self baseEvent];
|
|
98
|
+
if (extra.isObject()) {
|
|
99
|
+
event.update(extra);
|
|
100
|
+
}
|
|
101
|
+
if (_send) {
|
|
102
|
+
_send(name, std::move(event));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
- (void)makeWebView:(const WebViewConfig &)config {
|
|
107
|
+
WKWebViewConfiguration *configuration = [WKWebViewConfiguration new];
|
|
108
|
+
// Chosen when the view is made: WebKit takes no other data store afterwards.
|
|
109
|
+
configuration.websiteDataStore = config.incognito ? WKWebsiteDataStore.nonPersistentDataStore : WKWebsiteDataStore.defaultDataStore;
|
|
110
|
+
if (!config.applicationNameForUserAgent.empty()) {
|
|
111
|
+
configuration.applicationNameForUserAgent = ns(config.applicationNameForUserAgent);
|
|
112
|
+
}
|
|
113
|
+
_webView = [[WKWebView alloc] initWithFrame:NSZeroRect configuration:configuration];
|
|
114
|
+
_webView.navigationDelegate = self;
|
|
115
|
+
_webView.UIDelegate = self;
|
|
116
|
+
[_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
- (void)installScripts:(const WebViewConfig &)config {
|
|
120
|
+
WKUserContentController *content = _webView.configuration.userContentController;
|
|
121
|
+
[content removeAllUserScripts];
|
|
122
|
+
[content removeScriptMessageHandlerForName:@"ReactNativeWebView"];
|
|
123
|
+
if (config.messagingEnabled) {
|
|
124
|
+
NGNWeakScriptMessageHandler *handler = [NGNWeakScriptMessageHandler new];
|
|
125
|
+
handler.target = self;
|
|
126
|
+
[content addScriptMessageHandler:handler name:@"ReactNativeWebView"];
|
|
127
|
+
[content addUserScript:[[WKUserScript alloc] initWithSource:ns(ngn::webViewMessagingScript())
|
|
128
|
+
injectionTime:WKUserScriptInjectionTimeAtDocumentStart
|
|
129
|
+
forMainFrameOnly:YES]];
|
|
130
|
+
}
|
|
131
|
+
if (!config.injectedJavaScriptObject.empty()) {
|
|
132
|
+
[content addUserScript:[[WKUserScript alloc] initWithSource:ns(ngn::webViewInjectedObjectScript(config.injectedJavaScriptObject))
|
|
133
|
+
injectionTime:WKUserScriptInjectionTimeAtDocumentStart
|
|
134
|
+
forMainFrameOnly:YES]];
|
|
135
|
+
}
|
|
136
|
+
if (!config.injectedJavaScriptBeforeContentLoaded.empty()) {
|
|
137
|
+
[content addUserScript:[[WKUserScript alloc] initWithSource:ns(config.injectedJavaScriptBeforeContentLoaded)
|
|
138
|
+
injectionTime:WKUserScriptInjectionTimeAtDocumentStart
|
|
139
|
+
forMainFrameOnly:config.injectedJavaScriptBeforeContentLoadedForMainFrameOnly]];
|
|
140
|
+
}
|
|
141
|
+
if (!config.injectedJavaScript.empty()) {
|
|
142
|
+
[content addUserScript:[[WKUserScript alloc] initWithSource:ns(config.injectedJavaScript)
|
|
143
|
+
injectionTime:WKUserScriptInjectionTimeAtDocumentEnd
|
|
144
|
+
forMainFrameOnly:config.injectedJavaScriptForMainFrameOnly]];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
- (void)load:(const ngn::WebViewSource &)source {
|
|
149
|
+
_fileUse.reset();
|
|
150
|
+
if (!source.html.empty()) {
|
|
151
|
+
NSURL *base = source.baseUrl.empty() ? [NSURL URLWithString:@"about:blank"] : [NSURL URLWithString:ns(source.baseUrl)];
|
|
152
|
+
// A file base url only inside the file boundary: WebKit lets the page read beside it.
|
|
153
|
+
try {
|
|
154
|
+
if (auto file = ngn::webViewFile(ngn::viewFileAccess().get(), source.baseUrl)) {
|
|
155
|
+
base = [NSURL URLWithString:ns(file->uri)];
|
|
156
|
+
_fileUse = file->use;
|
|
157
|
+
}
|
|
158
|
+
} catch (const ngn::FileRefused &) {
|
|
159
|
+
base = [NSURL URLWithString:@"about:blank"];
|
|
160
|
+
}
|
|
161
|
+
[_webView loadHTMLString:ns(source.html) baseURL:base];
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
// A file page only inside the file boundary, reading no further than the app may.
|
|
165
|
+
try {
|
|
166
|
+
if (auto file = ngn::webViewFile(ngn::viewFileAccess().get(), source.uri)) {
|
|
167
|
+
_fileUse = file->use;
|
|
168
|
+
[_webView loadFileURL:[NSURL URLWithString:ns(file->uri)] allowingReadAccessToURL:[NSURL URLWithString:ns(file->readAccess)]];
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
} catch (const ngn::FileRefused &refused) {
|
|
172
|
+
[_webView loadHTMLString:@"" baseURL:[NSURL URLWithString:@"about:blank"]];
|
|
173
|
+
[self failed:[NSError errorWithDomain:NSURLErrorDomain
|
|
174
|
+
code:NSURLErrorNoPermissionsToReadFile
|
|
175
|
+
userInfo:@{NSLocalizedDescriptionKey : ns(refused.what())}]];
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
NSURL *url = source.uri.empty() ? nil : [NSURL URLWithString:ns(source.uri)];
|
|
179
|
+
if (url == nil) {
|
|
180
|
+
[_webView loadHTMLString:@"" baseURL:[NSURL URLWithString:@"about:blank"]];
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (url.isFileURL) {
|
|
184
|
+
// A file url webViewFile did not take (no path): nothing to load.
|
|
185
|
+
[_webView loadHTMLString:@"" baseURL:[NSURL URLWithString:@"about:blank"]];
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
|
|
189
|
+
if (!source.method.empty()) {
|
|
190
|
+
request.HTTPMethod = ns(source.method);
|
|
191
|
+
}
|
|
192
|
+
if (!source.body.empty()) {
|
|
193
|
+
request.HTTPBody = [NSData dataWithBytes:source.body.data() length:source.body.size()];
|
|
194
|
+
}
|
|
195
|
+
for (const auto &[name, value] : source.headers) {
|
|
196
|
+
[request setValue:ns(value) forHTTPHeaderField:ns(name)];
|
|
197
|
+
}
|
|
198
|
+
[_webView loadRequest:request];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
- (void)apply:(const WebViewConfig &)config {
|
|
202
|
+
bool fresh = _webView == nil;
|
|
203
|
+
if (fresh) {
|
|
204
|
+
[self makeWebView:config];
|
|
205
|
+
}
|
|
206
|
+
if (fresh || !sameScripts(*_config, config)) {
|
|
207
|
+
[self installScripts:config];
|
|
208
|
+
}
|
|
209
|
+
_webView.configuration.defaultWebpagePreferences.allowsContentJavaScript = config.javaScriptEnabled;
|
|
210
|
+
_webView.configuration.preferences.javaScriptCanOpenWindowsAutomatically = config.javaScriptCanOpenWindowsAutomatically;
|
|
211
|
+
_webView.customUserAgent = config.userAgent.empty() ? nil : ns(config.userAgent);
|
|
212
|
+
_webView.allowsBackForwardNavigationGestures = config.allowsBackForwardNavigationGestures;
|
|
213
|
+
if (@available(macOS 13.3, *)) {
|
|
214
|
+
_webView.inspectable = config.webviewDebuggingEnabled;
|
|
215
|
+
}
|
|
216
|
+
bool reload = fresh || _config->source != config.source;
|
|
217
|
+
_config = config;
|
|
218
|
+
if (reload) {
|
|
219
|
+
[self load:config.source];
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
- (void)command:(const std::string &)name args:(const folly::dynamic &)args {
|
|
224
|
+
auto text = [&]() -> std::string { return !args.empty() && args[0].isString() ? args[0].asString() : ""; };
|
|
225
|
+
if (name == "goBack") {
|
|
226
|
+
[_webView goBack];
|
|
227
|
+
} else if (name == "goForward") {
|
|
228
|
+
[_webView goForward];
|
|
229
|
+
} else if (name == "reload") {
|
|
230
|
+
[_webView reload];
|
|
231
|
+
} else if (name == "stopLoading") {
|
|
232
|
+
[_webView stopLoading];
|
|
233
|
+
} else if (name == "injectJavaScript") {
|
|
234
|
+
[_webView evaluateJavaScript:ns(text()) completionHandler:nil];
|
|
235
|
+
} else if (name == "postMessage") {
|
|
236
|
+
[_webView evaluateJavaScript:ns(ngn::webViewPostMessageScript(text())) completionHandler:nil];
|
|
237
|
+
} else if (name == "loadUrl") {
|
|
238
|
+
if (NSURL *url = [NSURL URLWithString:ns(text())]) {
|
|
239
|
+
[_webView loadRequest:[NSURLRequest requestWithURL:url]];
|
|
240
|
+
}
|
|
241
|
+
} else if (name == "requestFocus") {
|
|
242
|
+
[_webView.window makeFirstResponder:_webView];
|
|
243
|
+
} else if (name == "clearCache") {
|
|
244
|
+
// Caches only, as react-native-webview clears them on iOS: never cookies or the page's storage.
|
|
245
|
+
bool disk = !args.empty() && args[0].isBool() && args[0].asBool();
|
|
246
|
+
NSMutableSet *types = [NSMutableSet setWithObjects:WKWebsiteDataTypeMemoryCache, WKWebsiteDataTypeOfflineWebApplicationCache, nil];
|
|
247
|
+
if (disk) {
|
|
248
|
+
[types addObjectsFromArray:@[ WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeFetchCache ]];
|
|
249
|
+
}
|
|
250
|
+
[_webView.configuration.websiteDataStore removeDataOfTypes:types modifiedSince:NSDate.distantPast completionHandler:^{}];
|
|
251
|
+
}
|
|
252
|
+
// clearHistory and clearFormData: WKWebView has no way to, as on iOS.
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
- (void)invalidate {
|
|
256
|
+
for (int lock : std::set<int>(_held)) {
|
|
257
|
+
_locks->settle(lock, false);
|
|
258
|
+
}
|
|
259
|
+
_held.clear();
|
|
260
|
+
if (_webView != nil) {
|
|
261
|
+
[_webView removeObserver:self forKeyPath:@"estimatedProgress"];
|
|
262
|
+
[_webView.configuration.userContentController removeScriptMessageHandlerForName:@"ReactNativeWebView"];
|
|
263
|
+
[_webView stopLoading];
|
|
264
|
+
_webView.navigationDelegate = nil;
|
|
265
|
+
_webView.UIDelegate = nil;
|
|
266
|
+
_webView = nil;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
|
|
271
|
+
if ([keyPath isEqualToString:@"estimatedProgress"] && object == _webView) {
|
|
272
|
+
[self send:"loadingProgress" extra:folly::dynamic::object("progress", _webView.estimatedProgress)];
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// MARK: navigation
|
|
277
|
+
|
|
278
|
+
- (void)webView:(WKWebView *)webView
|
|
279
|
+
decidePolicyForNavigationAction:(WKNavigationAction *)action
|
|
280
|
+
decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
|
|
281
|
+
NSURLRequest *request = action.request;
|
|
282
|
+
std::string url = str(request.URL.absoluteString);
|
|
283
|
+
bool topFrame = [request.URL isEqual:request.mainDocumentURL];
|
|
284
|
+
bool hasTargetFrame = action.targetFrame != nil;
|
|
285
|
+
NSString *type = navigationTypeName(action.navigationType);
|
|
286
|
+
if (_config && _config->hasOnOpenWindowEvent && !hasTargetFrame) {
|
|
287
|
+
decisionHandler(WKNavigationActionPolicyCancel);
|
|
288
|
+
[self send:"openWindow" extra:folly::dynamic::object("targetUrl", url)];
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
auto step = _config ? ngn::navigationStep(*_config, url, topFrame, str(type)) : ngn::NavigationStep::AskApp;
|
|
292
|
+
if (step != ngn::NavigationStep::AskApp) {
|
|
293
|
+
decisionHandler(WKNavigationActionPolicyCancel);
|
|
294
|
+
if (step == ngn::NavigationStep::OpenExternally && _openExternally) {
|
|
295
|
+
_openExternally(url);
|
|
296
|
+
}
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
__weak NGNWebViewController *weakSelf = self;
|
|
300
|
+
__weak WKWebView *asking = webView;
|
|
301
|
+
auto lockBox = std::make_shared<int>(0);
|
|
302
|
+
int lock = _locks->hold([weakSelf, asking, decisionHandler, topFrame, url, type, lockBox](bool shouldStart) {
|
|
303
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
304
|
+
NGNWebViewController *strong = weakSelf;
|
|
305
|
+
if (strong != nil) {
|
|
306
|
+
strong->_held.erase(*lockBox);
|
|
307
|
+
}
|
|
308
|
+
// An answer that comes once its view is invalidated or replaced is a refusal, and says nothing.
|
|
309
|
+
WKWebView *current = strong != nil ? strong->_webView : nil;
|
|
310
|
+
if (current == nil || current != asking) {
|
|
311
|
+
decisionHandler(WKNavigationActionPolicyCancel);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (!shouldStart) {
|
|
315
|
+
decisionHandler(WKNavigationActionPolicyCancel);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (strong != nil && topFrame) {
|
|
319
|
+
[strong send:"loadingStart" extra:folly::dynamic::object("url", url)("navigationType", str(type))];
|
|
320
|
+
}
|
|
321
|
+
decisionHandler(WKNavigationActionPolicyAllow);
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
*lockBox = lock;
|
|
325
|
+
_held.insert(lock);
|
|
326
|
+
folly::dynamic extra = folly::dynamic::object("url", url)("navigationType", str(type))("isTopFrame", topFrame)("hasTargetFrame", hasTargetFrame)(
|
|
327
|
+
"lockIdentifier", lock);
|
|
328
|
+
if (request.mainDocumentURL != nil) {
|
|
329
|
+
extra["mainDocumentURL"] = str(request.mainDocumentURL.absoluteString);
|
|
330
|
+
}
|
|
331
|
+
[self send:"shouldStartLoadWithRequest" extra:std::move(extra)];
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
- (void)webView:(WKWebView *)webView
|
|
335
|
+
decidePolicyForNavigationResponse:(WKNavigationResponse *)response
|
|
336
|
+
decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
|
|
337
|
+
if (response.forMainFrame && [response.response isKindOfClass:NSHTTPURLResponse.class]) {
|
|
338
|
+
NSInteger status = ((NSHTTPURLResponse *)response.response).statusCode;
|
|
339
|
+
if (status >= 400) {
|
|
340
|
+
[self send:"httpError"
|
|
341
|
+
extra:folly::dynamic::object("statusCode", status)("description", str([NSHTTPURLResponse localizedStringForStatusCode:status]))];
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
decisionHandler(WKNavigationResponsePolicyAllow);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
|
|
348
|
+
[self send:"loadingFinish" extra:nullptr];
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
- (void)failed:(NSError *)error {
|
|
352
|
+
// A navigation the app or a new load cancelled is not a failure, as on iOS.
|
|
353
|
+
if ([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorCancelled) {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
if ([error.domain isEqualToString:@"WebKitErrorDomain"] && error.code == 102) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
[self send:"loadingError"
|
|
360
|
+
extra:folly::dynamic::object("domain", str(error.domain))("code", error.code)("description", str(error.localizedDescription))];
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error {
|
|
364
|
+
[self failed:error];
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error {
|
|
368
|
+
[self failed:error];
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView {
|
|
372
|
+
[self send:"contentProcessDidTerminate" extra:nullptr];
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
- (WKWebView *)webView:(WKWebView *)webView
|
|
376
|
+
createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration
|
|
377
|
+
forNavigationAction:(WKNavigationAction *)action
|
|
378
|
+
windowFeatures:(WKWindowFeatures *)windowFeatures {
|
|
379
|
+
// A link to a new window opens in this one, as the library's iOS view does.
|
|
380
|
+
if (action.targetFrame == nil) {
|
|
381
|
+
[webView loadRequest:action.request];
|
|
382
|
+
}
|
|
383
|
+
return nil;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
- (void)userContentController:(WKUserContentController *)controller didReceiveScriptMessage:(WKScriptMessage *)message {
|
|
387
|
+
if (![message.name isEqualToString:@"ReactNativeWebView"]) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
NSString *data = [message.body isKindOfClass:NSString.class] ? message.body : [NSString stringWithFormat:@"%@", message.body];
|
|
391
|
+
[self send:"message" extra:folly::dynamic::object("data", str(data))];
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
@end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# react-native-reanimated on the desktop host: its shared C++ (Common/cpp/reanimated) over
|
|
2
|
+
# react-native-worklets' (cmake/libraries/react-native-worklets.cmake), with the desktop's glue
|
|
3
|
+
# (core/src/libraries/react-native-reanimated.cpp) in place of its iOS ReanimatedModule and
|
|
4
|
+
# REANodesManager. Included by cmake/libraries.cmake.
|
|
5
|
+
if(NOT NGN_WITH_RUNTIME)
|
|
6
|
+
return()
|
|
7
|
+
endif()
|
|
8
|
+
set(_reanimated ${NGN_LIBRARY_PACKAGE_DIR})
|
|
9
|
+
file(READ ${_reanimated}/package.json _reanimated_package)
|
|
10
|
+
string(JSON _reanimated_version GET "${_reanimated_package}" version)
|
|
11
|
+
# The static feature flags, as its podspec passes them: staticFlags.json.
|
|
12
|
+
file(READ ${_reanimated}/src/featureFlags/staticFlags.json _reanimated_flags_json)
|
|
13
|
+
string(JSON _count LENGTH "${_reanimated_flags_json}")
|
|
14
|
+
set(_reanimated_flags "")
|
|
15
|
+
math(EXPR _last "${_count} - 1")
|
|
16
|
+
foreach(i RANGE ${_last})
|
|
17
|
+
string(JSON _key MEMBER "${_reanimated_flags_json}" ${i})
|
|
18
|
+
string(JSON _value GET "${_reanimated_flags_json}" ${_key})
|
|
19
|
+
if(_value)
|
|
20
|
+
string(APPEND _reanimated_flags "[${_key}:true]")
|
|
21
|
+
else()
|
|
22
|
+
string(APPEND _reanimated_flags "[${_key}:false]")
|
|
23
|
+
endif()
|
|
24
|
+
endforeach()
|
|
25
|
+
|
|
26
|
+
file(GLOB_RECURSE _reanimated_srcs CONFIGURE_DEPENDS ${_reanimated}/Common/cpp/reanimated/*.cpp)
|
|
27
|
+
# Its component's codegen (REASharedTransitionBoundary), whose props its C++ reads. The component
|
|
28
|
+
# itself is not registered.
|
|
29
|
+
file(GLOB _reanimated_codegen CONFIGURE_DEPENDS ${NGN_LIBRARY_CODEGEN}/react/renderer/components/${NGN_LIBRARY_CODEGEN_NAME}/*.cpp)
|
|
30
|
+
list(APPEND _reanimated_srcs ${_reanimated_codegen})
|
|
31
|
+
add_library(ngn_rnreanimated OBJECT ${_reanimated_srcs}
|
|
32
|
+
${CMAKE_CURRENT_SOURCE_DIR}/core/src/libraries/react-native-reanimated.cpp)
|
|
33
|
+
target_include_directories(ngn_rnreanimated SYSTEM PUBLIC ${_reanimated}/Common/cpp ${NGN_LIBRARY_CODEGEN}
|
|
34
|
+
${NGN_LIBRARY_CODEGEN}/react/renderer/components/${NGN_LIBRARY_CODEGEN_NAME})
|
|
35
|
+
target_include_directories(ngn_rnreanimated PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/core/include)
|
|
36
|
+
target_compile_definitions(ngn_rnreanimated PUBLIC
|
|
37
|
+
REANIMATED_VERSION=${_reanimated_version}
|
|
38
|
+
"REANIMATED_FEATURE_FLAGS=${_reanimated_flags}")
|
|
39
|
+
# Reanimated needs Worklets, which the app has whenever it has Reanimated: the target is
|
|
40
|
+
# react-native-worklets' recipe's, in either order of the libraries.
|
|
41
|
+
target_link_libraries(ngn_rnreanimated PUBLIC ngn_rnworklets react_native)
|
|
42
|
+
target_compile_options(ngn_rnreanimated PRIVATE -fexceptions -frtti -include cstdint -w)
|
|
43
|
+
list(APPEND _lib_targets ngn_rnreanimated)
|
|
44
|
+
string(APPEND _lib_glue_decls "void installGlue_rnreanimated();\n")
|
|
45
|
+
string(APPEND _lib_glue_calls " installGlue_rnreanimated();\n")
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# react-native-worklets on the desktop host: its shared C++ (Common/cpp/worklets), with the
|
|
2
|
+
# desktop's glue (core/src/libraries/react-native-worklets.cpp) in place of its iOS module: the
|
|
3
|
+
# WorkletsModule TurboModule, a UI scheduler on the backend's UI thread, and animation frames from
|
|
4
|
+
# the backend's display link (ngn/animation-frames.h). Included by cmake/libraries.cmake.
|
|
5
|
+
if(NOT NGN_WITH_RUNTIME)
|
|
6
|
+
return()
|
|
7
|
+
endif()
|
|
8
|
+
set(_worklets ${NGN_LIBRARY_PACKAGE_DIR})
|
|
9
|
+
file(READ ${_worklets}/package.json _worklets_package)
|
|
10
|
+
string(JSON _worklets_version GET "${_worklets_package}" version)
|
|
11
|
+
# The static feature flags, as the library's podspec passes them: its staticFlags.json.
|
|
12
|
+
file(READ ${_worklets}/src/featureFlags/staticFlags.json _worklets_flags_json)
|
|
13
|
+
string(JSON _count LENGTH "${_worklets_flags_json}")
|
|
14
|
+
set(_worklets_flags "")
|
|
15
|
+
math(EXPR _last "${_count} - 1")
|
|
16
|
+
foreach(i RANGE ${_last})
|
|
17
|
+
string(JSON _key MEMBER "${_worklets_flags_json}" ${i})
|
|
18
|
+
string(JSON _value GET "${_worklets_flags_json}" ${_key})
|
|
19
|
+
if(_value)
|
|
20
|
+
string(APPEND _worklets_flags "[${_key}:true]")
|
|
21
|
+
else()
|
|
22
|
+
string(APPEND _worklets_flags "[${_key}:false]")
|
|
23
|
+
endif()
|
|
24
|
+
endforeach()
|
|
25
|
+
|
|
26
|
+
# The script that parks the UI runtime's frame loop while it has no work, as a C++ string.
|
|
27
|
+
set(_idle_frames ${CMAKE_CURRENT_SOURCE_DIR}/core/src/libraries/worklets-idle-frames.js)
|
|
28
|
+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${_idle_frames})
|
|
29
|
+
file(READ ${_idle_frames} NGN_IDLE_FRAMES_JS)
|
|
30
|
+
file(CONFIGURE OUTPUT ${CMAKE_BINARY_DIR}/generated/worklets-idle-frames.h CONTENT
|
|
31
|
+
"// Generated by cmake/libraries/react-native-worklets.cmake from worklets-idle-frames.js.\n#pragma once\nconstexpr const char *kWorkletsIdleFrames = R\"ngn(@NGN_IDLE_FRAMES_JS@)ngn\";\n" @ONLY)
|
|
32
|
+
|
|
33
|
+
file(GLOB_RECURSE _worklets_srcs CONFIGURE_DEPENDS ${_worklets}/Common/cpp/worklets/*.cpp)
|
|
34
|
+
add_library(ngn_rnworklets OBJECT ${_worklets_srcs}
|
|
35
|
+
${CMAKE_CURRENT_SOURCE_DIR}/core/src/libraries/react-native-worklets.cpp)
|
|
36
|
+
target_include_directories(ngn_rnworklets SYSTEM PUBLIC ${_worklets}/Common/cpp)
|
|
37
|
+
target_include_directories(ngn_rnworklets PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/core/include ${CMAKE_BINARY_DIR}/generated)
|
|
38
|
+
target_compile_definitions(ngn_rnworklets PUBLIC
|
|
39
|
+
WORKLETS_VERSION=${_worklets_version}
|
|
40
|
+
"WORKLETS_FEATURE_FLAGS=${_worklets_flags}"
|
|
41
|
+
HERMES_V1_ENABLED=1)
|
|
42
|
+
target_link_libraries(ngn_rnworklets PUBLIC react_native hermes-engine::hermesvm)
|
|
43
|
+
target_compile_options(ngn_rnworklets PRIVATE -fexceptions -frtti -include cstdint -w)
|
|
44
|
+
list(APPEND _lib_targets ngn_rnworklets)
|
|
45
|
+
string(APPEND _lib_glue_decls "void installGlue_rnworklets();\n")
|
|
46
|
+
string(APPEND _lib_glue_calls " installGlue_rnworklets();\n")
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Libraries' Fabric components compiled into the host: each directory in NGN_LIBRARIES comes from
|
|
2
|
+
# scripts/codegen-library.sh and holds a library's codegen output and a library.cmake saying what
|
|
3
|
+
# to compile and register.
|
|
4
|
+
#
|
|
5
|
+
# ngn_libraries provides ngn::libraryComponents() (ngn/library-components.h): the descriptor of
|
|
6
|
+
# every component the libraries declare, which a backend adds to the core's own.
|
|
7
|
+
set(NGN_LIBRARIES "" CACHE STRING "Library directories made by scripts/codegen-library.sh")
|
|
8
|
+
|
|
9
|
+
set(_lib_includes "")
|
|
10
|
+
set(_lib_glue_decls "")
|
|
11
|
+
set(_lib_glue_calls "")
|
|
12
|
+
set(_lib_glue "")
|
|
13
|
+
set(_lib_providers "")
|
|
14
|
+
set(_lib_targets "")
|
|
15
|
+
foreach(dir ${NGN_LIBRARIES})
|
|
16
|
+
set(NGN_LIBRARY_RECIPE "")
|
|
17
|
+
include(${dir}/library.cmake)
|
|
18
|
+
set(_name ${NGN_LIBRARY_NAME})
|
|
19
|
+
# A library the host builds by its own recipe (cmake/libraries/<package>.cmake): the recipe adds
|
|
20
|
+
# its targets to _lib_targets, and its glue's install function, when it has one, to the calls.
|
|
21
|
+
if(NGN_LIBRARY_RECIPE)
|
|
22
|
+
include(${NGN_LIBRARY_RECIPE})
|
|
23
|
+
continue()
|
|
24
|
+
endif()
|
|
25
|
+
set(_codegen ${dir}/codegen/react/renderer/components/${_name})
|
|
26
|
+
file(GLOB _srcs CONFIGURE_DEPENDS ${_codegen}/*.cpp)
|
|
27
|
+
string(APPEND _lib_includes "#include <react/renderer/components/${_name}/ComponentDescriptors.h>\n")
|
|
28
|
+
set(_include_dirs ${dir}/codegen ${_codegen})
|
|
29
|
+
if(NGN_LIBRARY_COMMON_DIR)
|
|
30
|
+
set(_common ${NGN_LIBRARY_COMMON_DIR}/react/renderer/components/${_name})
|
|
31
|
+
file(GLOB _common_srcs CONFIGURE_DEPENDS ${_common}/*.cpp ${_common}/utils/*.cpp)
|
|
32
|
+
list(APPEND _srcs ${_common_srcs})
|
|
33
|
+
list(APPEND _include_dirs ${NGN_LIBRARY_COMMON_DIR})
|
|
34
|
+
endif()
|
|
35
|
+
set(_common_included "")
|
|
36
|
+
foreach(d ${NGN_LIBRARY_DESCRIPTORS})
|
|
37
|
+
# A descriptor the codegen does not make is the library's own, in a header named after it.
|
|
38
|
+
# Only the registered ones: some libraries' unregistered headers collide in one translation unit.
|
|
39
|
+
if(NGN_LIBRARY_COMMON_DIR AND EXISTS ${_common}/${d}.h)
|
|
40
|
+
string(APPEND _lib_includes "#include <react/renderer/components/${_name}/${d}.h>\n")
|
|
41
|
+
elseif(NGN_LIBRARY_COMMON_DIR)
|
|
42
|
+
# Or in a header named otherwise: one that declares several, as react-native-svg's
|
|
43
|
+
# RNSVGComponentDescriptors.h, or one with the library's prefix, as react-native-keyboard-
|
|
44
|
+
# controller's RNKCKeyboardControllerViewComponentDescriptor.h.
|
|
45
|
+
file(GLOB _shared_headers ${_common}/*ComponentDescriptor*.h)
|
|
46
|
+
foreach(h ${_shared_headers})
|
|
47
|
+
file(STRINGS ${h} _declares REGEX "(using|class) ${d}( |$)")
|
|
48
|
+
get_filename_component(_header ${h} NAME)
|
|
49
|
+
if(_declares AND NOT _header IN_LIST _common_included)
|
|
50
|
+
list(APPEND _common_included ${_header})
|
|
51
|
+
string(APPEND _lib_includes "#include <react/renderer/components/${_name}/${_header}>\n")
|
|
52
|
+
endif()
|
|
53
|
+
endforeach()
|
|
54
|
+
endif()
|
|
55
|
+
string(APPEND _lib_providers " concreteComponentDescriptorProvider<${d}>(),\n")
|
|
56
|
+
endforeach()
|
|
57
|
+
# The core's reading of the library's own props and state, where the core has any (library-glue.h).
|
|
58
|
+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/core/src/libraries/${_name}.cpp)
|
|
59
|
+
list(APPEND _lib_glue core/src/libraries/${_name}.cpp)
|
|
60
|
+
string(APPEND _lib_glue_decls "void installGlue_${_name}();\n")
|
|
61
|
+
string(APPEND _lib_glue_calls " installGlue_${_name}();\n")
|
|
62
|
+
endif()
|
|
63
|
+
add_library(ngn_library_${_name} OBJECT ${_srcs})
|
|
64
|
+
target_include_directories(ngn_library_${_name} SYSTEM PUBLIC ${_include_dirs})
|
|
65
|
+
target_link_libraries(ngn_library_${_name} PUBLIC react_native)
|
|
66
|
+
target_compile_options(ngn_library_${_name} PRIVATE -fexceptions -frtti -include cstdint -w)
|
|
67
|
+
list(APPEND _lib_targets ngn_library_${_name})
|
|
68
|
+
endforeach()
|
|
69
|
+
|
|
70
|
+
file(CONFIGURE OUTPUT ${CMAKE_BINARY_DIR}/generated/library-components.cpp CONTENT [[
|
|
71
|
+
// Generated by cmake/libraries.cmake from NGN_LIBRARIES.
|
|
72
|
+
#include "ngn/library-components.h"
|
|
73
|
+
#include "ngn/library-glue.h"
|
|
74
|
+
|
|
75
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
76
|
+
|
|
77
|
+
#include <string_view>
|
|
78
|
+
@_lib_includes@
|
|
79
|
+
using namespace facebook::react;
|
|
80
|
+
|
|
81
|
+
namespace ngn {
|
|
82
|
+
|
|
83
|
+
@_lib_glue_decls@
|
|
84
|
+
std::vector<ComponentDescriptorProvider> libraryComponents() {
|
|
85
|
+
static bool installed = false;
|
|
86
|
+
if (!installed) {
|
|
87
|
+
installed = true;
|
|
88
|
+
@_lib_glue_calls@ }
|
|
89
|
+
// The desktop's own components first: a library's of the same name is left out.
|
|
90
|
+
std::vector<ComponentDescriptorProvider> providers = libraryGlue().components;
|
|
91
|
+
for (auto &provider : std::vector<ComponentDescriptorProvider>{
|
|
92
|
+
@_lib_providers@ }) {
|
|
93
|
+
bool replaced = false;
|
|
94
|
+
for (const auto &own : providers) {
|
|
95
|
+
replaced = replaced || std::string_view(own.name) == provider.name;
|
|
96
|
+
}
|
|
97
|
+
if (!replaced) {
|
|
98
|
+
providers.push_back(std::move(provider));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return providers;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
} // namespace ngn
|
|
105
|
+
]] @ONLY)
|
|
106
|
+
|
|
107
|
+
add_library(ngn_libraries STATIC ${CMAKE_BINARY_DIR}/generated/library-components.cpp ${_lib_glue})
|
|
108
|
+
target_link_libraries(ngn_libraries PUBLIC ngn_core ${_lib_targets})
|
|
109
|
+
target_compile_options(ngn_libraries PRIVATE -fexceptions -frtti -include cstdint -w)
|