@ng-native/desktop 0.0.0-stage → 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 +51 -2
- 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 +70 -3
- package/prebuilt.json +33 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// The desktop props as plain values (desktop-view-props.h parses them), in a header of their own
|
|
2
|
+
// because React Native's view traits read them too: the shim's HostPlatformViewTraitsInitializer.h
|
|
3
|
+
// keeps a view that has any of them from being flattened away, as React Native does for a view
|
|
4
|
+
// with an event listener or a cursor.
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include <folly/dynamic.h>
|
|
8
|
+
#include <react/renderer/components/view/primitives.h>
|
|
9
|
+
#include <react/renderer/core/ReactPrimitives.h>
|
|
10
|
+
|
|
11
|
+
#include <optional>
|
|
12
|
+
#include <string>
|
|
13
|
+
|
|
14
|
+
namespace ngn {
|
|
15
|
+
|
|
16
|
+
using facebook::react::SurfaceId;
|
|
17
|
+
using facebook::react::Tag;
|
|
18
|
+
|
|
19
|
+
// CSS's `scrollbar-width` and `scrollbar-gutter`.
|
|
20
|
+
enum class ScrollbarWidth { Auto, Thin, None };
|
|
21
|
+
enum class ScrollbarGutter { Auto, Stable };
|
|
22
|
+
|
|
23
|
+
// How a ModalHostView shows (desktop-modal.h): a sheet on its window, a cover in the window, or a
|
|
24
|
+
// popover at its anchor.
|
|
25
|
+
enum class ModalPresentation { Sheet, Cover, Popover };
|
|
26
|
+
|
|
27
|
+
struct DesktopProps {
|
|
28
|
+
// Unset means the toolkit's default for the component.
|
|
29
|
+
std::optional<bool> focusable;
|
|
30
|
+
// Unset means no explicit place in Tab order. Negative leaves the view out of it.
|
|
31
|
+
std::optional<int> tabIndex;
|
|
32
|
+
// ModalHostView only: the view it is anchored to, as a popover (desktop-modal.h).
|
|
33
|
+
std::optional<Tag> anchor;
|
|
34
|
+
// The CSS cursor as written, when React Native's `cursor` cannot say it. Unset defers to
|
|
35
|
+
// `cursor`, then to the nearest ancestor's (input-dispatcher.h).
|
|
36
|
+
std::optional<facebook::react::Cursor> cursor;
|
|
37
|
+
// ScrollView only.
|
|
38
|
+
ScrollbarWidth scrollbarWidth{ScrollbarWidth::Auto};
|
|
39
|
+
ScrollbarGutter scrollbarGutter{ScrollbarGutter::Auto};
|
|
40
|
+
// Whether a binding listens for the element event, which is then sent to the view.
|
|
41
|
+
bool onDoubleClick{false};
|
|
42
|
+
bool onContextMenu{false};
|
|
43
|
+
bool onWheel{false};
|
|
44
|
+
// Whether the view takes files, text and urls dragged onto it (input-dispatcher.h).
|
|
45
|
+
bool fileDrop{false};
|
|
46
|
+
// The `dragItem` prop: `{ files, text, url }` the view offers when dragged out, or null for none.
|
|
47
|
+
folly::dynamic dragItem{nullptr};
|
|
48
|
+
// The `contextMenu` prop: the entries of the menu a secondary click shows, as the app sends them
|
|
49
|
+
// (app-menus.h), or null for none.
|
|
50
|
+
folly::dynamic contextMenu{nullptr};
|
|
51
|
+
// `role` as written. React Native's Role has no `listbox`, `gridcell`, `menuitemcheckbox` or
|
|
52
|
+
// `menuitemradio` and drops them; the core reads them from here (accessibility.h roleName).
|
|
53
|
+
std::string role;
|
|
54
|
+
// `accessibilityLevel` (`aria-level`): a heading's level, from 1.
|
|
55
|
+
std::optional<int> accessibilityLevel;
|
|
56
|
+
// ModalHostView only.
|
|
57
|
+
ModalPresentation presentation{ModalPresentation::Sheet};
|
|
58
|
+
|
|
59
|
+
bool operator==(const DesktopProps &other) const = default;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// What a props class with desktop props carries beside its React Native base.
|
|
63
|
+
struct HasDesktopProps {
|
|
64
|
+
DesktopProps desktop;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// Whether a view with these props must be a view of its own, with its children under it: the
|
|
68
|
+
// hit test, the cursor and Tab order all read it, and a flattened view is not mounted.
|
|
69
|
+
inline bool formsStackingContext(const DesktopProps &props) {
|
|
70
|
+
return props.focusable.value_or(false) || props.tabIndex.has_value() || props.cursor.has_value() ||
|
|
71
|
+
!props.role.empty() || props.onDoubleClick || props.onContextMenu || props.onWheel || props.fileDrop || !props.dragItem.isNull() ||
|
|
72
|
+
!props.contextMenu.isNull();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
} // namespace ngn
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// The desktop view props interface: the View props React Native's cross-platform ViewProps drop
|
|
2
|
+
// and the desktop needs. `focusable` and `tabIndex`, which Tab order reads; `desktopCursor`, the
|
|
3
|
+
// CSS cursors React Native's `cursor` (auto and pointer) lacks; `scrollbarWidth` and
|
|
4
|
+
// `scrollbarGutter` on a scroll view; and the opt-ins for the desktop's element events,
|
|
5
|
+
// `onDoubleClick`, `onContextMenu` and `onWheel` (input-dispatcher.h).
|
|
6
|
+
//
|
|
7
|
+
// The core registers View and ScrollView with descriptors whose props carry them, and reports them
|
|
8
|
+
// to the backend as plain values through DesktopPropsSink when a view is created and whenever they
|
|
9
|
+
// change.
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include "ngn/desktop-props.h"
|
|
13
|
+
#include "ngn/scrollers.h"
|
|
14
|
+
|
|
15
|
+
#include <react/renderer/components/scrollview/ScrollViewProps.h>
|
|
16
|
+
#include <react/renderer/components/scrollview/ScrollViewShadowNode.h>
|
|
17
|
+
#include <react/renderer/components/view/ViewProps.h>
|
|
18
|
+
#include <react/renderer/components/view/ViewShadowNode.h>
|
|
19
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
20
|
+
|
|
21
|
+
#include <optional>
|
|
22
|
+
|
|
23
|
+
namespace ngn {
|
|
24
|
+
|
|
25
|
+
// The desktop props an update sets, on top of `source`'s.
|
|
26
|
+
DesktopProps parseDesktopProps(
|
|
27
|
+
const facebook::react::PropsParserContext &context,
|
|
28
|
+
const DesktopProps &source,
|
|
29
|
+
const facebook::react::RawProps &rawProps);
|
|
30
|
+
|
|
31
|
+
class DesktopViewProps final : public facebook::react::ViewProps, public HasDesktopProps {
|
|
32
|
+
public:
|
|
33
|
+
DesktopViewProps() = default;
|
|
34
|
+
DesktopViewProps(
|
|
35
|
+
const facebook::react::PropsParserContext &context,
|
|
36
|
+
const DesktopViewProps &sourceProps,
|
|
37
|
+
const facebook::react::RawProps &rawProps);
|
|
38
|
+
// A View's props with the desktop props unset.
|
|
39
|
+
explicit DesktopViewProps(const facebook::react::ViewProps &viewProps) : facebook::react::ViewProps(viewProps) {}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
class DesktopScrollViewProps final : public facebook::react::ScrollViewProps, public HasDesktopProps {
|
|
43
|
+
public:
|
|
44
|
+
DesktopScrollViewProps() = default;
|
|
45
|
+
DesktopScrollViewProps(
|
|
46
|
+
const facebook::react::PropsParserContext &context,
|
|
47
|
+
const DesktopScrollViewProps &sourceProps,
|
|
48
|
+
const facebook::react::RawProps &rawProps);
|
|
49
|
+
explicit DesktopScrollViewProps(const facebook::react::ScrollViewProps &props)
|
|
50
|
+
: facebook::react::ScrollViewProps(props) {}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// The desktop props of any props object: a View's own, or the defaults for anything else.
|
|
54
|
+
DesktopProps desktopProps(const facebook::react::Props &props);
|
|
55
|
+
|
|
56
|
+
// React Native's component with `DesktopPropsT`, which derives from the props its shadow node
|
|
57
|
+
// reads. Everything else (traits, flattening, state, measuring) is the shadow node's own.
|
|
58
|
+
template <class ShadowNodeT, class DesktopPropsT>
|
|
59
|
+
class DesktopPropsComponentDescriptor final : public facebook::react::ConcreteComponentDescriptor<ShadowNodeT> {
|
|
60
|
+
using Base = facebook::react::ConcreteComponentDescriptor<ShadowNodeT>;
|
|
61
|
+
using BaseProps = typename ShadowNodeT::ConcreteProps;
|
|
62
|
+
|
|
63
|
+
public:
|
|
64
|
+
explicit DesktopPropsComponentDescriptor(const facebook::react::ComponentDescriptorParameters ¶meters)
|
|
65
|
+
: Base(parameters, preparedParser()) {}
|
|
66
|
+
|
|
67
|
+
// ConcreteComponentDescriptor::cloneProps's classic path, constructing DesktopPropsT.
|
|
68
|
+
facebook::react::Props::Shared cloneProps(
|
|
69
|
+
const facebook::react::PropsParserContext &context,
|
|
70
|
+
const facebook::react::Props::Shared &props,
|
|
71
|
+
facebook::react::RawProps rawProps) const override {
|
|
72
|
+
if (!props && rawProps.isEmpty()) {
|
|
73
|
+
return ShadowNodeT::defaultSharedProps();
|
|
74
|
+
}
|
|
75
|
+
rawProps.parse(this->rawPropsParser_);
|
|
76
|
+
static const DesktopPropsT defaults;
|
|
77
|
+
const auto *source = props ? dynamic_cast<const DesktopPropsT *>(props.get()) : &defaults;
|
|
78
|
+
if (source == nullptr) {
|
|
79
|
+
// Props made before this descriptor (Fabric's shared defaults): start from them.
|
|
80
|
+
DesktopPropsT upgraded{static_cast<const BaseProps &>(*props)};
|
|
81
|
+
return std::make_shared<const DesktopPropsT>(context, upgraded, rawProps);
|
|
82
|
+
}
|
|
83
|
+
return std::make_shared<const DesktopPropsT>(context, *source, rawProps);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private:
|
|
87
|
+
// The parser records the keys a props class reads the first time it is prepared, so it has to
|
|
88
|
+
// be prepared for DesktopPropsT before ConcreteComponentDescriptor prepares it for the base
|
|
89
|
+
// props, whose keys are a subset and add nothing once the parser is ready.
|
|
90
|
+
static facebook::react::RawPropsParser preparedParser() {
|
|
91
|
+
facebook::react::RawPropsParser parser;
|
|
92
|
+
parser.template prepare<DesktopPropsT>();
|
|
93
|
+
return parser;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
using DesktopViewComponentDescriptor =
|
|
98
|
+
DesktopPropsComponentDescriptor<facebook::react::ViewShadowNode, DesktopViewProps>;
|
|
99
|
+
// The scroll view pads its content by its scrollers' gutter (scrollers.h).
|
|
100
|
+
using DesktopScrollViewComponentDescriptor =
|
|
101
|
+
DesktopPropsComponentDescriptor<DesktopScrollViewShadowNode, DesktopScrollViewProps>;
|
|
102
|
+
|
|
103
|
+
// Implemented by a backend that maps desktop props onto its toolkit (key-view loop, Tab order).
|
|
104
|
+
class DesktopPropsSink {
|
|
105
|
+
public:
|
|
106
|
+
virtual ~DesktopPropsSink() = default;
|
|
107
|
+
virtual void updateDesktopProps(SurfaceId surfaceId, Tag tag, const DesktopProps &props) = 0;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
} // namespace ngn
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// The Metro dev server a bundle URL points at. The desktop host loads the bundle URL directly
|
|
2
|
+
// (never the Expo manifest, which the Expo dev server refuses for macos), then keeps a connection
|
|
3
|
+
// to the same server for reload (/message) and Fast Refresh (the HMR client, over /hot).
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#include <folly/dynamic.h>
|
|
7
|
+
|
|
8
|
+
#include <cstdint>
|
|
9
|
+
#include <optional>
|
|
10
|
+
#include <string>
|
|
11
|
+
|
|
12
|
+
namespace ngn {
|
|
13
|
+
|
|
14
|
+
struct DevServer {
|
|
15
|
+
// `url` when it is an http or https URL with a host, otherwise nothing (a bundle on disk).
|
|
16
|
+
static std::optional<DevServer> fromBundleUrl(const std::string &url);
|
|
17
|
+
|
|
18
|
+
std::string bundleUrl;
|
|
19
|
+
std::string scheme;
|
|
20
|
+
std::string host;
|
|
21
|
+
uint32_t port{0};
|
|
22
|
+
// The bundle's path without its leading slash and `.bundle`, as HMRClient.setup takes it.
|
|
23
|
+
std::string entry;
|
|
24
|
+
// The `platform` query parameter; `macos` when the URL has none.
|
|
25
|
+
std::string platform;
|
|
26
|
+
|
|
27
|
+
// Where Metro sends reload and dev menu messages.
|
|
28
|
+
std::string packagerConnectionUrl() const;
|
|
29
|
+
// HMRClient.setup(platform, bundleEntry, host, port, isEnabled, scheme).
|
|
30
|
+
folly::dynamic hmrSetupArgs() const;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
} // namespace ngn
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// A file fetched over the backend's HTTP client: an asset or a font the dev server serves, saved
|
|
2
|
+
// before the OS opens it.
|
|
3
|
+
#pragma once
|
|
4
|
+
|
|
5
|
+
#include "ngn/network.h"
|
|
6
|
+
|
|
7
|
+
#include <functional>
|
|
8
|
+
#include <memory>
|
|
9
|
+
#include <string>
|
|
10
|
+
|
|
11
|
+
namespace ngn {
|
|
12
|
+
|
|
13
|
+
// Reads the whole body of `url` (a `file:`, `data:` or `http(s):` url). Answers once, on any thread:
|
|
14
|
+
// the body and an empty error, or no body and why: "HTTP <status>" or the client's error.
|
|
15
|
+
void fetchBytes(const std::shared_ptr<Http> &http, const std::string &url, std::function<void(std::string body, const std::string &error)> done);
|
|
16
|
+
// The same for a request of its own, with its method and headers.
|
|
17
|
+
void fetchBytes(const std::shared_ptr<Http> &http, HttpRequest request, std::function<void(std::string body, const std::string &error)> done);
|
|
18
|
+
|
|
19
|
+
// Downloads `url` into the file `target`, making its folder first. Answers once, on any thread:
|
|
20
|
+
// an empty error once the file is written, else why not: "HTTP <status>", the client's error, or
|
|
21
|
+
// "could not be saved to <target>".
|
|
22
|
+
void downloadFile(const std::shared_ptr<Http> &http, const std::string &url, const std::string &target, std::function<void(const std::string &error)> done);
|
|
23
|
+
|
|
24
|
+
} // namespace ngn
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// `<expo-image>` on a desktop host: expo-image's view (ViewManagerAdapter_ExpoImage, the component
|
|
2
|
+
// `registerExpoViews('expo-image')` commits) as a Fabric component of the desktop's own.
|
|
3
|
+
//
|
|
4
|
+
// The core reads the props and decides what the backend draws: which `source` fits the view
|
|
5
|
+
// (expo-image's getBestSource), where the image goes in the view (`contentFit` and
|
|
6
|
+
// `contentPosition`, CSS's object-fit and object-position as expo-image's iOS view applies them),
|
|
7
|
+
// the transition, and the placeholder, decoding a blurhash or a thumbhash to pixels. It fetches an
|
|
8
|
+
// image's bytes through the backend's HTTP client and keeps them in an ImageCache, in memory and on
|
|
9
|
+
// disk by `cachePolicy`, so the backend only decodes and draws. The view sends expo-image's
|
|
10
|
+
// events: loadStart, progress, load ({cacheType, source: {url, width, height, mediaType,
|
|
11
|
+
// isAnimated}}), error ({error}) and display.
|
|
12
|
+
#pragma once
|
|
13
|
+
|
|
14
|
+
#include "ngn/desktop-props.h"
|
|
15
|
+
#include "ngn/file-system.h"
|
|
16
|
+
#include "ngn/network.h"
|
|
17
|
+
|
|
18
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
19
|
+
#include <react/renderer/components/view/ViewEventEmitter.h>
|
|
20
|
+
#include <react/renderer/components/view/ViewProps.h>
|
|
21
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
22
|
+
#include <react/renderer/graphics/Color.h>
|
|
23
|
+
|
|
24
|
+
#include <folly/dynamic.h>
|
|
25
|
+
|
|
26
|
+
#include <cstdint>
|
|
27
|
+
#include <functional>
|
|
28
|
+
#include <list>
|
|
29
|
+
#include <map>
|
|
30
|
+
#include <memory>
|
|
31
|
+
#include <mutex>
|
|
32
|
+
#include <optional>
|
|
33
|
+
#include <string>
|
|
34
|
+
#include <vector>
|
|
35
|
+
|
|
36
|
+
namespace ngn {
|
|
37
|
+
|
|
38
|
+
extern const char ExpoImageComponentName[];
|
|
39
|
+
|
|
40
|
+
class ExpoImageProps final : public facebook::react::ViewProps, public HasDesktopProps {
|
|
41
|
+
public:
|
|
42
|
+
ExpoImageProps() = default;
|
|
43
|
+
ExpoImageProps(
|
|
44
|
+
const facebook::react::PropsParserContext &context,
|
|
45
|
+
const ExpoImageProps &sourceProps,
|
|
46
|
+
const facebook::react::RawProps &rawProps);
|
|
47
|
+
// Lists of {uri, width, height, headers, cacheKey}, as expo-image's JavaScript hands them down.
|
|
48
|
+
folly::dynamic source;
|
|
49
|
+
folly::dynamic placeholder;
|
|
50
|
+
std::string contentFit{"cover"};
|
|
51
|
+
std::string placeholderContentFit{"scale-down"};
|
|
52
|
+
// {top, right, bottom, left}, each points or a percentage string; null for the centre.
|
|
53
|
+
folly::dynamic contentPosition;
|
|
54
|
+
// A duration in milliseconds, or {duration, effect, timing}.
|
|
55
|
+
folly::dynamic transition;
|
|
56
|
+
double blurRadius{0};
|
|
57
|
+
facebook::react::SharedColor tintColor;
|
|
58
|
+
// none, disk, memory or memory-disk.
|
|
59
|
+
std::string cachePolicy{"disk"};
|
|
60
|
+
std::string recyclingKey;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
using ExpoImageShadowNode =
|
|
64
|
+
facebook::react::ConcreteViewShadowNode<ExpoImageComponentName, ExpoImageProps, facebook::react::ViewEventEmitter>;
|
|
65
|
+
using ExpoImageComponentDescriptor = facebook::react::ConcreteComponentDescriptor<ExpoImageShadowNode>;
|
|
66
|
+
|
|
67
|
+
struct ImageSourceRef {
|
|
68
|
+
std::string uri;
|
|
69
|
+
double width{0};
|
|
70
|
+
double height{0};
|
|
71
|
+
std::vector<std::pair<std::string, std::string>> headers;
|
|
72
|
+
std::string cacheKey;
|
|
73
|
+
bool operator==(const ImageSourceRef &) const = default;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// Each entry of a `source` list (or a lone object), in order; entries with no uri are left out.
|
|
77
|
+
std::vector<ImageSourceRef> imageSources(const folly::dynamic &list);
|
|
78
|
+
|
|
79
|
+
// The source whose pixel count is nearest the view's at `scale`, as expo-image picks: the only
|
|
80
|
+
// one when there is one, and nothing for a view with no size.
|
|
81
|
+
std::optional<ImageSourceRef> bestImageSource(const std::vector<ImageSourceRef> &sources, double width, double height, double scale);
|
|
82
|
+
|
|
83
|
+
struct ImageRect {
|
|
84
|
+
double x{0}, y{0}, width{0}, height{0};
|
|
85
|
+
bool operator==(const ImageRect &) const = default;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// Where an image of `image` size draws in a box of `box` size, from its top left, by `contentFit`
|
|
89
|
+
// (cover, contain, fill, none, scale-down) and `contentPosition`.
|
|
90
|
+
ImageRect placeImage(
|
|
91
|
+
const std::string &contentFit, const folly::dynamic &contentPosition, std::pair<double, double> image, std::pair<double, double> box);
|
|
92
|
+
|
|
93
|
+
struct ImageTransition {
|
|
94
|
+
double duration{0};
|
|
95
|
+
// cross-dissolve, flip-from-left, flip-from-right, flip-from-top, flip-from-bottom,
|
|
96
|
+
// curl-up, curl-down, or none.
|
|
97
|
+
std::string effect{"cross-dissolve"};
|
|
98
|
+
std::string timing{"ease-in-out"};
|
|
99
|
+
bool operator==(const ImageTransition &) const = default;
|
|
100
|
+
};
|
|
101
|
+
// expo-image's transition from its prop: a number is the duration in milliseconds.
|
|
102
|
+
ImageTransition imageTransition(const folly::dynamic &transition);
|
|
103
|
+
// Whether a recycling key going from `before` to `after` clears the image shown, so a reused view
|
|
104
|
+
// never shows the last item's image while its own loads: a key changed from one that was set.
|
|
105
|
+
bool recyclingKeyClears(const std::string &before, const std::string &after);
|
|
106
|
+
|
|
107
|
+
// Which of an image view's loads is current. A new source, no source, or a recycled view
|
|
108
|
+
// supersedes the load running, whose late answer then shows nothing. Main thread.
|
|
109
|
+
class ImageLoads {
|
|
110
|
+
public:
|
|
111
|
+
// The source that fits the view now: the turn of the load it needs when it changed, the turn
|
|
112
|
+
// that shows nothing when it went away.
|
|
113
|
+
std::optional<uint64_t> fit(const std::optional<ImageSourceRef> &source) {
|
|
114
|
+
if (source == source_) {
|
|
115
|
+
return std::nullopt;
|
|
116
|
+
}
|
|
117
|
+
source_ = source;
|
|
118
|
+
return ++turn_;
|
|
119
|
+
}
|
|
120
|
+
// The view was recycled: the same source loads again, and the load running shows nothing.
|
|
121
|
+
void recycle() {
|
|
122
|
+
source_.reset();
|
|
123
|
+
++turn_;
|
|
124
|
+
}
|
|
125
|
+
bool current(uint64_t turn) const {
|
|
126
|
+
return turn == turn_;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private:
|
|
130
|
+
std::optional<ImageSourceRef> source_;
|
|
131
|
+
uint64_t turn_{0};
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
struct DecodedPixels {
|
|
135
|
+
int width{0};
|
|
136
|
+
int height{0};
|
|
137
|
+
// RGBA, 8 bits a channel, unpremultiplied, rows from the top.
|
|
138
|
+
std::vector<uint8_t> rgba;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// A blurhash decoded to `width` by `height` pixels, as the reference decoder does. Nothing for a
|
|
142
|
+
// hash that is not one.
|
|
143
|
+
std::optional<DecodedPixels> decodeBlurhash(const std::string &hash, int width, int height, double punch = 1);
|
|
144
|
+
// A thumbhash's bytes decoded to its own small size (32 points on its longer side), as the
|
|
145
|
+
// reference decoder does. Nothing for bytes too short to be one.
|
|
146
|
+
std::optional<DecodedPixels> decodeThumbhash(const std::string &bytes);
|
|
147
|
+
|
|
148
|
+
// A placeholder's uri decoded, when it is a `blurhash:/<hash>/<w>/<h>` or `thumbhash:/<base64>`
|
|
149
|
+
// uri, as expo-image's JavaScript writes them.
|
|
150
|
+
std::optional<DecodedPixels> decodeHashUri(const std::string &uri, double width = 0, double height = 0);
|
|
151
|
+
|
|
152
|
+
// Images' bytes by key, in memory (least recently used dropped past `memoryLimit` bytes) and on
|
|
153
|
+
// disk in `folder`, each by `cachePolicy`. Any thread.
|
|
154
|
+
class ImageCache {
|
|
155
|
+
public:
|
|
156
|
+
enum class Hit { None, Memory, Disk };
|
|
157
|
+
ImageCache(std::string folder, size_t memoryLimit);
|
|
158
|
+
// The bytes kept for `key` where `policy` looks (memory first), or nothing.
|
|
159
|
+
std::optional<std::pair<std::string, Hit>> find(const std::string &key, const std::string &policy);
|
|
160
|
+
void store(const std::string &key, const std::string &bytes, const std::string &policy);
|
|
161
|
+
void clearMemory();
|
|
162
|
+
bool clearDisk();
|
|
163
|
+
// The file `key`'s bytes are kept in on disk.
|
|
164
|
+
std::string diskPath(const std::string &key) const;
|
|
165
|
+
size_t memoryBytes() const;
|
|
166
|
+
|
|
167
|
+
private:
|
|
168
|
+
void remember(const std::string &key, const std::string &bytes);
|
|
169
|
+
std::string folder_;
|
|
170
|
+
size_t limit_;
|
|
171
|
+
mutable std::mutex mutex_;
|
|
172
|
+
std::list<std::pair<std::string, std::string>> recent_;
|
|
173
|
+
std::map<std::string, std::list<std::pair<std::string, std::string>>::iterator> byKey_;
|
|
174
|
+
size_t bytes_{0};
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// expo-image's name for a cache hit: none, memory or disk.
|
|
178
|
+
const char *cacheTypeName(ImageCache::Hit hit);
|
|
179
|
+
|
|
180
|
+
// Reads `source`'s bytes: from the cache by its cacheKey (or uri) when `policy` keeps it, else
|
|
181
|
+
// through `http` with its headers, then into the cache. `file:` and `data:` sources are read and
|
|
182
|
+
// never cached, a file only inside the file boundary `files` draws (readableSource). Answers once,
|
|
183
|
+
// on any thread: the bytes and the hit, or an error.
|
|
184
|
+
void loadImageBytes(
|
|
185
|
+
const std::shared_ptr<Http> &http,
|
|
186
|
+
const std::shared_ptr<ImageCache> &cache,
|
|
187
|
+
const FileAccess *files,
|
|
188
|
+
const ImageSourceRef &source,
|
|
189
|
+
const std::string &policy,
|
|
190
|
+
std::function<void(std::string bytes, ImageCache::Hit hit, const std::string &error)> done);
|
|
191
|
+
|
|
192
|
+
} // namespace ngn
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// `@expo/ui` on a desktop host: its SwiftUI views as Fabric components, under the names
|
|
2
|
+
// `registerExpoUiViews` commits on iOS (ViewManagerAdapter_ExpoUI_<view>), with iOS's props.
|
|
3
|
+
//
|
|
4
|
+
// Every one of them is one component class, told apart by its name (the descriptor's flavor), whose
|
|
5
|
+
// props are kept as they arrive: expo/ui's views take an untyped map of props, and each SwiftUI view
|
|
6
|
+
// reads its own. The core keeps the views under each HostView as one tree (ExpoUITrees, below),
|
|
7
|
+
// which the backend's view for the HostView draws in SwiftUI, as expo/ui's HostView does with its
|
|
8
|
+
// children on iOS. Their own views draw nothing. An RNHostView in the tree is the app's own views
|
|
9
|
+
// inside the SwiftUI content: they lay out in Yoga as usual and the toolkit puts its view there.
|
|
10
|
+
//
|
|
11
|
+
// A HostView with `matchContentsHorizontal` or `matchContentsVertical` is sized by its content: the
|
|
12
|
+
// toolkit reports the SwiftUI content's fitting size as the HostView's state, and the HostView takes
|
|
13
|
+
// it on the axes it matches, as expo/ui's `setViewSize` does on iOS.
|
|
14
|
+
#pragma once
|
|
15
|
+
|
|
16
|
+
#include "ngn/view-tree.h"
|
|
17
|
+
|
|
18
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
19
|
+
#include <react/renderer/components/view/ViewEventEmitter.h>
|
|
20
|
+
#include <react/renderer/components/view/ViewProps.h>
|
|
21
|
+
#include <react/renderer/componentregistry/ComponentDescriptorProvider.h>
|
|
22
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
23
|
+
#include <react/renderer/core/EventEmitter.h>
|
|
24
|
+
|
|
25
|
+
#include <folly/dynamic.h>
|
|
26
|
+
|
|
27
|
+
#include <memory>
|
|
28
|
+
#include <optional>
|
|
29
|
+
#include <string>
|
|
30
|
+
#include <string_view>
|
|
31
|
+
#include <unordered_map>
|
|
32
|
+
#include <unordered_set>
|
|
33
|
+
#include <vector>
|
|
34
|
+
|
|
35
|
+
namespace ngn {
|
|
36
|
+
|
|
37
|
+
// The prefix every expo/ui view's component name has: the module's view adapter for `ExpoUI`.
|
|
38
|
+
inline constexpr std::string_view kExpoUIPrefix = "ViewManagerAdapter_ExpoUI_";
|
|
39
|
+
|
|
40
|
+
// The iOS view names the desktop host draws (`EXPO_UI_MACOS` in @ng-native/expo, which a test
|
|
41
|
+
// holds to this list), in no order.
|
|
42
|
+
const std::vector<std::string> &expoUIViews();
|
|
43
|
+
|
|
44
|
+
// `HostView` for `ViewManagerAdapter_ExpoUI_HostView`; nothing for a name that is not one of the
|
|
45
|
+
// expo/ui views the host draws.
|
|
46
|
+
std::optional<std::string> expoUIViewName(std::string_view componentName);
|
|
47
|
+
|
|
48
|
+
class ExpoUIProps final : public facebook::react::ViewProps {
|
|
49
|
+
public:
|
|
50
|
+
ExpoUIProps() = default;
|
|
51
|
+
ExpoUIProps(
|
|
52
|
+
const facebook::react::PropsParserContext &context,
|
|
53
|
+
const ExpoUIProps &sourceProps,
|
|
54
|
+
const facebook::react::RawProps &rawProps);
|
|
55
|
+
|
|
56
|
+
// Every prop as committed, the last value of each: a `null` removes one. Yoga's and the view's
|
|
57
|
+
// own style props are here too, and the SwiftUI views read only their own names.
|
|
58
|
+
folly::dynamic values = folly::dynamic::object();
|
|
59
|
+
|
|
60
|
+
// The HostView's, read here for layout.
|
|
61
|
+
bool matchContentsHorizontal{false};
|
|
62
|
+
bool matchContentsVertical{false};
|
|
63
|
+
// An RNHostView sized from the app's views it holds (`expoInternalSizeFromChildren`, which
|
|
64
|
+
// `matchContents` sets), as iOS measures it, rather than stretched across its container.
|
|
65
|
+
bool sizeFromChildren{false};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// The size of a HostView's SwiftUI content, as the toolkit measured it. Zero until it reports.
|
|
69
|
+
struct ExpoUIState {
|
|
70
|
+
facebook::react::Size contentSize{};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
extern const char ExpoUIComponentName[];
|
|
74
|
+
|
|
75
|
+
class ExpoUIShadowNode final : public facebook::react::ConcreteViewShadowNode<
|
|
76
|
+
ExpoUIComponentName,
|
|
77
|
+
ExpoUIProps,
|
|
78
|
+
facebook::react::ViewEventEmitter,
|
|
79
|
+
ExpoUIState> {
|
|
80
|
+
public:
|
|
81
|
+
using ConcreteViewShadowNode::ConcreteViewShadowNode;
|
|
82
|
+
|
|
83
|
+
// Takes the content size the state holds on each axis the props match, over the style's, and
|
|
84
|
+
// fits a view sized from its children to them.
|
|
85
|
+
void applyContentSize();
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// One descriptor per expo/ui view name, as its flavor.
|
|
89
|
+
class ExpoUIComponentDescriptor final : public facebook::react::ConcreteComponentDescriptor<ExpoUIShadowNode> {
|
|
90
|
+
public:
|
|
91
|
+
using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
|
|
92
|
+
facebook::react::ComponentHandle getComponentHandle() const override;
|
|
93
|
+
facebook::react::ComponentName getComponentName() const override;
|
|
94
|
+
void adopt(facebook::react::ShadowNode &shadowNode) const override;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// A provider for each of expoUIViews(), by its full component name.
|
|
98
|
+
std::vector<facebook::react::ComponentDescriptorProvider> expoUIComponentProviders();
|
|
99
|
+
|
|
100
|
+
// One expo/ui view in a HostView's tree: its iOS name, its props, where its events go, and the
|
|
101
|
+
// expo/ui views under it. An RNHostView has none: what is under it is the app's own.
|
|
102
|
+
struct ExpoUINode {
|
|
103
|
+
facebook::react::Tag tag{-1};
|
|
104
|
+
std::string name;
|
|
105
|
+
folly::dynamic props = folly::dynamic::object();
|
|
106
|
+
facebook::react::SharedEventEmitter eventEmitter;
|
|
107
|
+
std::vector<ExpoUINode> children;
|
|
108
|
+
bool operator==(const ExpoUINode &) const = default;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// The HostViews of a surface's views, kept by the mounting manager as it mounts them: which
|
|
112
|
+
// HostView each change belongs to, and each HostView's tree when it changed.
|
|
113
|
+
class ExpoUITrees {
|
|
114
|
+
public:
|
|
115
|
+
// A view was made or its props or event emitter changed, or `tag`'s children changed.
|
|
116
|
+
void changed(const ViewTree &tree, facebook::react::Tag tag);
|
|
117
|
+
void deleted(facebook::react::Tag tag);
|
|
118
|
+
|
|
119
|
+
struct Changed {
|
|
120
|
+
facebook::react::Tag host{-1};
|
|
121
|
+
std::shared_ptr<const ExpoUINode> root;
|
|
122
|
+
};
|
|
123
|
+
// The HostViews whose trees changed since the last call.
|
|
124
|
+
std::vector<Changed> settle(const ViewTree &tree);
|
|
125
|
+
|
|
126
|
+
private:
|
|
127
|
+
std::optional<ExpoUINode> node(const ViewTree &tree, facebook::react::Tag tag) const;
|
|
128
|
+
|
|
129
|
+
std::unordered_set<facebook::react::Tag> dirty_;
|
|
130
|
+
std::unordered_map<facebook::react::Tag, std::shared_ptr<const ExpoUINode>> drawn_;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
} // namespace ngn
|