@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,111 @@
|
|
|
1
|
+
// The native controls' intrinsic sizes, measured on the UI thread and read by layout.
|
|
2
|
+
//
|
|
3
|
+
// A toolkit's controls (AppKit's cells) are UI-thread only, and layout runs on the JS thread, which
|
|
4
|
+
// never waits on the UI thread. So layout reads a cache, keyed by the inputs a control's size
|
|
5
|
+
// depends on (controlSizeKey), and never measures off the UI thread:
|
|
6
|
+
//
|
|
7
|
+
// - A hit is the size.
|
|
8
|
+
// - A miss on the UI thread is measured there at once.
|
|
9
|
+
// - A miss anywhere else lays the control out at the size it last had (nothing, for a new one),
|
|
10
|
+
// queues it and posts a settle to the UI thread. The settle measures what is queued, fills the
|
|
11
|
+
// cache and asks each queued control for a layout again with a state update, which lays it out
|
|
12
|
+
// with the size. Until the mount that carries that state, the controls are not settled, and the
|
|
13
|
+
// app window is held as it is for its safe areas: its first frame draws the controls at their
|
|
14
|
+
// size. A control added to a window already on screen draws at its last size, or not at all,
|
|
15
|
+
// for one frame.
|
|
16
|
+
//
|
|
17
|
+
// Every size belongs to the controls laid out with its inputs: one whose inputs change lets go of
|
|
18
|
+
// the old size, a deleted one lets go of its own, and a size no control holds is dropped.
|
|
19
|
+
#pragma once
|
|
20
|
+
|
|
21
|
+
#include "ngn/native-controls.h"
|
|
22
|
+
|
|
23
|
+
#include <react/renderer/core/State.h>
|
|
24
|
+
|
|
25
|
+
#include <functional>
|
|
26
|
+
#include <map>
|
|
27
|
+
#include <memory>
|
|
28
|
+
#include <mutex>
|
|
29
|
+
#include <set>
|
|
30
|
+
#include <string>
|
|
31
|
+
#include <unordered_map>
|
|
32
|
+
|
|
33
|
+
namespace ngn {
|
|
34
|
+
|
|
35
|
+
using facebook::react::Tag;
|
|
36
|
+
|
|
37
|
+
// The inputs a control's size depends on, as one string: its kind and what it draws (title,
|
|
38
|
+
// symbol, segments, date, font and so on). Props that do not change its size (enabled, value,
|
|
39
|
+
// colours) are not in it.
|
|
40
|
+
std::string controlSizeKey(ControlKind kind, const NativeControlProps &props);
|
|
41
|
+
|
|
42
|
+
// Made with std::make_shared: a posted settle holds it weakly.
|
|
43
|
+
class ControlSizes : public std::enable_shared_from_this<ControlSizes> {
|
|
44
|
+
public:
|
|
45
|
+
// Asks the control `tag`, whose state is `state`, for a layout again. The default updates its
|
|
46
|
+
// state.
|
|
47
|
+
using Relayout = std::function<void(Tag tag, const facebook::react::State &state)>;
|
|
48
|
+
|
|
49
|
+
// `runOnUiThread` runs a task on the UI thread later, and `onUiThread` says whether the caller is
|
|
50
|
+
// on it.
|
|
51
|
+
ControlSizes(
|
|
52
|
+
std::shared_ptr<const ControlMeasurer> measurer,
|
|
53
|
+
std::function<void(std::function<void()>)> runOnUiThread,
|
|
54
|
+
std::function<bool()> onUiThread,
|
|
55
|
+
Relayout relayout = nullptr);
|
|
56
|
+
|
|
57
|
+
// Layout, any thread: the size of the control `tag` with `props`. `state` is the node's.
|
|
58
|
+
facebook::react::Size layoutSize(
|
|
59
|
+
Tag tag,
|
|
60
|
+
ControlKind kind,
|
|
61
|
+
std::shared_ptr<const NativeControlProps> props,
|
|
62
|
+
const facebook::react::State::Shared &state);
|
|
63
|
+
|
|
64
|
+
// UI thread: measures every control layout queued, and asks each for a layout again.
|
|
65
|
+
void settle();
|
|
66
|
+
// UI thread: a mount gave `tag` a new state, the one a settle asked for or a later one.
|
|
67
|
+
void relaidOut(Tag tag);
|
|
68
|
+
// UI thread: the control `tag` was deleted.
|
|
69
|
+
void forget(Tag tag);
|
|
70
|
+
|
|
71
|
+
// Whether no control waits for a measurement or for the layout after one.
|
|
72
|
+
bool settled() const;
|
|
73
|
+
// How many sizes are held, for the tests.
|
|
74
|
+
size_t held() const;
|
|
75
|
+
|
|
76
|
+
private:
|
|
77
|
+
struct Control {
|
|
78
|
+
std::string key;
|
|
79
|
+
facebook::react::Size size{};
|
|
80
|
+
};
|
|
81
|
+
struct Queued {
|
|
82
|
+
ControlKind kind;
|
|
83
|
+
std::shared_ptr<const NativeControlProps> props;
|
|
84
|
+
facebook::react::State::Shared state;
|
|
85
|
+
};
|
|
86
|
+
// With mutex_ held.
|
|
87
|
+
void hold(Tag tag, const std::string &key);
|
|
88
|
+
void release(const std::string &key);
|
|
89
|
+
|
|
90
|
+
std::shared_ptr<const ControlMeasurer> measurer_;
|
|
91
|
+
std::function<void(std::function<void()>)> runOnUiThread_;
|
|
92
|
+
std::function<bool()> onUiThread_;
|
|
93
|
+
Relayout relayout_;
|
|
94
|
+
|
|
95
|
+
mutable std::mutex mutex_;
|
|
96
|
+
std::unordered_map<std::string, facebook::react::Size> sizes_;
|
|
97
|
+
// How many controls hold each key.
|
|
98
|
+
std::unordered_map<std::string, int> holders_;
|
|
99
|
+
std::unordered_map<Tag, Control> controls_;
|
|
100
|
+
std::map<Tag, Queued> queued_;
|
|
101
|
+
std::set<Tag> awaiting_;
|
|
102
|
+
bool posted_{false};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
inline constexpr const char *kControlSizesKey = "ngn.ControlSizes";
|
|
106
|
+
|
|
107
|
+
inline void installControlSizes(facebook::react::ContextContainer &context, std::shared_ptr<ControlSizes> sizes) {
|
|
108
|
+
context.insert(kControlSizesKey, std::move(sizes));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
} // namespace ngn
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// React Native's iOS-shaped modules, implemented once in the core for every desktop backend.
|
|
2
|
+
// macOS runs React Native's iOS JavaScript, so each module answers under its iOS name with the
|
|
3
|
+
// iOS shapes. Each is a NativeModule: plain C++ over the System and HostState interfaces.
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#include "ngn/bytes.h"
|
|
7
|
+
#include "ngn/file-system.h"
|
|
8
|
+
#include "ngn/host-state.h"
|
|
9
|
+
#include "ngn/key-value-store.h"
|
|
10
|
+
#include "ngn/module-registry.h"
|
|
11
|
+
#include "ngn/native-module.h"
|
|
12
|
+
#include "ngn/network.h"
|
|
13
|
+
#include "ngn/system.h"
|
|
14
|
+
|
|
15
|
+
#include <functional>
|
|
16
|
+
#include <memory>
|
|
17
|
+
#include <string>
|
|
18
|
+
|
|
19
|
+
namespace ngn {
|
|
20
|
+
|
|
21
|
+
class Gestures;
|
|
22
|
+
|
|
23
|
+
struct CoreModuleServices {
|
|
24
|
+
std::shared_ptr<System> system;
|
|
25
|
+
std::shared_ptr<HostState> state;
|
|
26
|
+
std::shared_ptr<Http> http;
|
|
27
|
+
std::shared_ptr<WebSockets> webSockets;
|
|
28
|
+
// Made by addCoreModules when not given: one for every runtime, shared by its modules.
|
|
29
|
+
std::shared_ptr<BlobStore> blobs;
|
|
30
|
+
// What a request's file url, a body's `{uri}` and Image.getSize's file source may read
|
|
31
|
+
// (FileAccess::readFor); without it, no file is read.
|
|
32
|
+
std::shared_ptr<FileAccess> files;
|
|
33
|
+
// AsyncStorage's files. Made by addCoreModules when not given, in the app's data directory.
|
|
34
|
+
std::shared_ptr<KeyValueStore> storage;
|
|
35
|
+
// "0.88.0", the React Native the host was built from, which its JavaScript checks.
|
|
36
|
+
std::string reactNativeVersion;
|
|
37
|
+
// The bundle the runtime runs now: a path, or a dev server's URL. SourceCode is registered only
|
|
38
|
+
// with it.
|
|
39
|
+
std::function<std::string()> bundle;
|
|
40
|
+
// Moves the screen reader to the view with this tag (AccessibilityInfo.setAccessibilityFocus).
|
|
41
|
+
// Any thread; nothing when absent.
|
|
42
|
+
std::function<void(int tag)> focusAccessibility;
|
|
43
|
+
// A test launch's fake system UI: an alert is never shown and answers at once with its cancel
|
|
44
|
+
// button, or not at all when it has none, as a person must pick one of its buttons.
|
|
45
|
+
bool fakeSystemUI{false};
|
|
46
|
+
// The gesture handler's recognisers (gestures.h), which RNGestureHandlerModule drives, and the
|
|
47
|
+
// UI thread they live on. Without them the module recognises nothing.
|
|
48
|
+
std::shared_ptr<Gestures> gestures;
|
|
49
|
+
std::function<void(std::function<void()>)> runOnUiThread;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Registers every core module.
|
|
53
|
+
void addCoreModules(ModuleRegistry ®istry, const CoreModuleServices &services);
|
|
54
|
+
|
|
55
|
+
// The modules one at a time, for tests.
|
|
56
|
+
std::shared_ptr<NativeModule> makePlatformConstants(const CoreModuleServices &services);
|
|
57
|
+
std::shared_ptr<NativeModule> makeDeviceInfo(const CoreModuleServices &services);
|
|
58
|
+
std::shared_ptr<NativeModule> makeAppState(const CoreModuleServices &services);
|
|
59
|
+
std::shared_ptr<NativeModule> makeAppearance(const CoreModuleServices &services);
|
|
60
|
+
// AccessibilityInfo's iOS module: the settings in the host state and their change events.
|
|
61
|
+
std::shared_ptr<NativeModule> makeAccessibilityManager(const CoreModuleServices &services);
|
|
62
|
+
std::shared_ptr<NativeModule> makeLinking(const CoreModuleServices &services);
|
|
63
|
+
std::shared_ptr<NativeModule> makeI18n(const CoreModuleServices &services);
|
|
64
|
+
std::shared_ptr<NativeModule> makeAlertManager(const CoreModuleServices &services);
|
|
65
|
+
std::shared_ptr<NativeModule> makeClipboard(const CoreModuleServices &services);
|
|
66
|
+
std::shared_ptr<NativeModule> makeSettingsManager(const CoreModuleServices &services);
|
|
67
|
+
std::shared_ptr<NativeModule> makeStatusBarManager(const CoreModuleServices &services);
|
|
68
|
+
std::shared_ptr<NativeModule> makeVibration(const CoreModuleServices &services);
|
|
69
|
+
std::shared_ptr<NativeModule> makeKeyboardObserver(const CoreModuleServices &services);
|
|
70
|
+
std::shared_ptr<NativeModule> makeScreensModule(const CoreModuleServices &services);
|
|
71
|
+
// react-native-gesture-handler's module, which its JavaScript requires as it loads. The host has
|
|
72
|
+
// no recognisers: every method is there and does nothing, so a gesture attached to a view never
|
|
73
|
+
// fires and the app draws as it does without one.
|
|
74
|
+
std::shared_ptr<NativeModule> makeGestureHandlerModule(const CoreModuleServices &services);
|
|
75
|
+
std::shared_ptr<NativeModule> makeNetworking(const CoreModuleServices &services);
|
|
76
|
+
std::shared_ptr<NativeModule> makeImageLoader(const CoreModuleServices &services);
|
|
77
|
+
std::shared_ptr<NativeModule> makeWebSocket(const CoreModuleServices &services);
|
|
78
|
+
std::shared_ptr<NativeModule> makeBlobModule(const CoreModuleServices &services);
|
|
79
|
+
std::shared_ptr<NativeModule> makeFileReader(const CoreModuleServices &services);
|
|
80
|
+
// @react-native-async-storage: RNCAsyncStorage for 2.x, RNAsyncStorage for 3.x, over one store.
|
|
81
|
+
std::shared_ptr<NativeModule> makeLegacyAsyncStorage(const CoreModuleServices &services);
|
|
82
|
+
std::shared_ptr<NativeModule> makeAsyncStorage(const CoreModuleServices &services);
|
|
83
|
+
// SourceCode's scriptURL, which React Native's asset resolver finds a bundle's assets beside, as
|
|
84
|
+
// iOS's RCTSourceCode gives it. React Native's own answers nothing for a bundle on disk.
|
|
85
|
+
std::shared_ptr<NativeModule> makeSourceCode(const CoreModuleServices &services);
|
|
86
|
+
|
|
87
|
+
// The body of a request JavaScript sent (Networking.sendRequest's `data`), and the content type
|
|
88
|
+
// it implies when the request has none. A file (`{uri}`, or a form part's) is read only where
|
|
89
|
+
// `files` lets it, and the request fails otherwise.
|
|
90
|
+
struct RequestBody {
|
|
91
|
+
std::string bytes;
|
|
92
|
+
std::string contentType;
|
|
93
|
+
std::string error;
|
|
94
|
+
};
|
|
95
|
+
RequestBody requestBody(const folly::dynamic &data, const BlobStore &blobs, const std::string &boundary, const FileAccess *files);
|
|
96
|
+
|
|
97
|
+
// The alert JavaScript asked for (AlertManager.alertWithArgs) as the backend shows it, and the
|
|
98
|
+
// button keys in the request's order, so a pressed index maps back to the key JavaScript gave.
|
|
99
|
+
struct PreparedAlert {
|
|
100
|
+
AlertRequest request;
|
|
101
|
+
std::vector<std::string> keys;
|
|
102
|
+
};
|
|
103
|
+
PreparedAlert prepareAlert(const folly::dynamic &args);
|
|
104
|
+
|
|
105
|
+
} // namespace ngn
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// NgNativeCrypto: what @ng-native/expo's Crypto calls on expo-crypto, over a CryptoSource, which the
|
|
2
|
+
// AppKit backend implements with CommonCrypto and the system's secure random source.
|
|
3
|
+
//
|
|
4
|
+
// - randomUUID(): a version 4 UUID, lowercase, as expo-crypto's.
|
|
5
|
+
// - getRandomBytes(count): {base64} of `count` secure random bytes, 0 to 1024 of them.
|
|
6
|
+
// - digestStringAsync(algorithm, text, {encoding}): the hash of the text's UTF-8, as hex
|
|
7
|
+
// (the default) or base64.
|
|
8
|
+
// - digestAsync(algorithm, {base64}): the hash of the bytes, as {base64}.
|
|
9
|
+
// The algorithms are expo-crypto's names: SHA-1, SHA-256, SHA-384, SHA-512, MD2, MD4 and MD5. A
|
|
10
|
+
// sync call that cannot answer throws; an async one rejects. Bytes cross as {base64}; the JS
|
|
11
|
+
// adapter (desktop-crypto.ts) turns them into the Uint8Array and ArrayBuffer expo-crypto answers.
|
|
12
|
+
#pragma once
|
|
13
|
+
|
|
14
|
+
#include "ngn/native-module.h"
|
|
15
|
+
|
|
16
|
+
#include <memory>
|
|
17
|
+
#include <optional>
|
|
18
|
+
#include <string>
|
|
19
|
+
|
|
20
|
+
namespace ngn {
|
|
21
|
+
|
|
22
|
+
class CryptoSource {
|
|
23
|
+
public:
|
|
24
|
+
virtual ~CryptoSource() = default;
|
|
25
|
+
// The raw digest of `bytes` by `algorithm` (expo-crypto's name), or nothing for a name it does
|
|
26
|
+
// not know.
|
|
27
|
+
virtual std::optional<std::string> digest(const std::string &algorithm, const std::string &bytes) = 0;
|
|
28
|
+
// `count` bytes from the OS's secure random source. Throws std::runtime_error when it fails.
|
|
29
|
+
virtual std::string randomBytes(size_t count) = 0;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Sixteen random bytes as a version 4 UUID: the version and variant bits set, lowercase hex.
|
|
33
|
+
std::string uuidV4(std::string bytes);
|
|
34
|
+
std::string hexOf(const std::string &bytes);
|
|
35
|
+
|
|
36
|
+
std::shared_ptr<NativeModule> makeCryptoModule(std::shared_ptr<CryptoSource> source);
|
|
37
|
+
|
|
38
|
+
} // namespace ngn
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// The menu bar every desktop app gets at launch, before any JavaScript runs: the app menu with
|
|
2
|
+
// Quit, File's Close Window and Print... (which prints the key window), the standard text editing commands, View's Back, Forward and Show Sidebar, the window commands and, for
|
|
3
|
+
// a bundle from a dev server, the developer commands. A backend draws it and maps each command to
|
|
4
|
+
// the toolkit's own. The app's own bar replaces it once the app sets one (app-menus.h).
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include <string>
|
|
8
|
+
#include <vector>
|
|
9
|
+
|
|
10
|
+
namespace ngn {
|
|
11
|
+
|
|
12
|
+
enum class MenuCommand {
|
|
13
|
+
None,
|
|
14
|
+
About,
|
|
15
|
+
Hide,
|
|
16
|
+
HideOthers,
|
|
17
|
+
ShowAll,
|
|
18
|
+
Quit,
|
|
19
|
+
CloseWindow,
|
|
20
|
+
Undo,
|
|
21
|
+
Redo,
|
|
22
|
+
Cut,
|
|
23
|
+
Copy,
|
|
24
|
+
Paste,
|
|
25
|
+
PasteAndMatchStyle,
|
|
26
|
+
Delete,
|
|
27
|
+
SelectAll,
|
|
28
|
+
ToggleFullScreen,
|
|
29
|
+
Minimize,
|
|
30
|
+
Zoom,
|
|
31
|
+
BringAllToFront,
|
|
32
|
+
Reload,
|
|
33
|
+
// React Native DevTools, through the dev server's inspector proxy (Developer menu).
|
|
34
|
+
OpenDevTools,
|
|
35
|
+
Find,
|
|
36
|
+
ToggleSidebar,
|
|
37
|
+
Print,
|
|
38
|
+
// Back and forward through the window's history: the app hears them as `navigate`.
|
|
39
|
+
Back,
|
|
40
|
+
Forward,
|
|
41
|
+
// An app's own item: the app hears it as `menuSelect` with the item's id.
|
|
42
|
+
AppItem,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// The key equivalent's modifiers, as a bitmask. Command is the platform's primary modifier
|
|
46
|
+
// (Control off macOS).
|
|
47
|
+
enum MenuModifier : unsigned {
|
|
48
|
+
Command = 1 << 0,
|
|
49
|
+
Shift = 1 << 1,
|
|
50
|
+
Option = 1 << 2,
|
|
51
|
+
Control = 1 << 3,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// What the toolkit's own menus add to a menu: AppKit fills the Services and Window menus.
|
|
55
|
+
enum class MenuRole { None, App, Services, Window, Help };
|
|
56
|
+
|
|
57
|
+
struct MenuItem {
|
|
58
|
+
std::string title;
|
|
59
|
+
MenuCommand command{MenuCommand::None};
|
|
60
|
+
// A key equivalent: a character such as "q", a key named as the web names it ("ArrowLeft",
|
|
61
|
+
// "Enter", "F5"), or empty for none.
|
|
62
|
+
std::string key;
|
|
63
|
+
unsigned modifiers{0};
|
|
64
|
+
bool separator{false};
|
|
65
|
+
MenuRole role{MenuRole::None};
|
|
66
|
+
std::vector<MenuItem> items;
|
|
67
|
+
// An app's item: the id the app knows it by, and how it is drawn.
|
|
68
|
+
std::string id;
|
|
69
|
+
bool disabled{false};
|
|
70
|
+
bool checked{false};
|
|
71
|
+
bool destructive{false};
|
|
72
|
+
std::string subtitle;
|
|
73
|
+
std::string sfSymbol;
|
|
74
|
+
// Its items are drawn in place, between separators, rather than as a submenu.
|
|
75
|
+
bool inlineItems{false};
|
|
76
|
+
|
|
77
|
+
bool operator==(const MenuItem &) const = default;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
struct DefaultMenuOptions {
|
|
81
|
+
std::string appName;
|
|
82
|
+
// Adds the Developer menu (Reload) for a bundle from a dev server.
|
|
83
|
+
bool developer{false};
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
std::vector<MenuItem> defaultMenuBar(const DefaultMenuOptions &options);
|
|
87
|
+
|
|
88
|
+
// The item with this command anywhere in `menus`, or null.
|
|
89
|
+
const MenuItem *findMenuItem(const std::vector<MenuItem> &menus, MenuCommand command);
|
|
90
|
+
|
|
91
|
+
} // namespace ngn
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// The desktop host's Expo modules (@ng-native/expo's DESKTOP_MODULES): each is `NgNative` and the
|
|
2
|
+
// package's name after `expo-`, answering the methods @ng-native/expo calls on the Expo package,
|
|
3
|
+
// so a service works unchanged. The OS is reached through narrow interfaces, which the AppKit
|
|
4
|
+
// backend implements (the Keychain, the pasteboard, IOKit's power assertions, the trackpad).
|
|
5
|
+
//
|
|
6
|
+
// - NgNativeSecureStore: getItemAsync, setItemAsync, deleteItemAsync, getItem, setItem and
|
|
7
|
+
// canUseBiometricAuthentication, over a SecretStore. Keys follow expo-secure-store's rule
|
|
8
|
+
// (letters, digits, `.`, `-` and `_`), and the `keychainService` option picks the service.
|
|
9
|
+
// - NgNativeClipboard: getStringAsync, setStringAsync and hasStringAsync, over System's pasteboard,
|
|
10
|
+
// and `ngNativeClipboard` on DeviceEventEmitter each time HostState's clipboard change count moves.
|
|
11
|
+
// - NgNativeKeepAwake: activateKeepAwakeAsync and deactivateKeepAwake by tag; the display stays
|
|
12
|
+
// awake while any tag holds it.
|
|
13
|
+
// - NgNativeHaptics: impactAsync, notificationAsync and selectionAsync, as the trackpad's feedback.
|
|
14
|
+
// - NgNativeDocumentPicker: getDocumentAsync in expo-document-picker's shape (copied into the
|
|
15
|
+
// cache unless copyToCacheDirectory is false), saveDocumentAsync (text, or bytes as {base64},
|
|
16
|
+
// written where the save panel says; null when dismissed) and pickDirectoryAsync ({uri} or null),
|
|
17
|
+
// over FileDialogs, with uris percent-encoded.
|
|
18
|
+
// - NgNativeLocalization: getLocales and getCalendars, in expo-localization's shapes, over a
|
|
19
|
+
// LocaleSource (the user's preferred languages and the region's formats).
|
|
20
|
+
#pragma once
|
|
21
|
+
|
|
22
|
+
#include "ngn/file-system.h"
|
|
23
|
+
#include "ngn/host-state.h"
|
|
24
|
+
#include "ngn/native-module.h"
|
|
25
|
+
#include "ngn/system.h"
|
|
26
|
+
|
|
27
|
+
#include <functional>
|
|
28
|
+
#include <memory>
|
|
29
|
+
#include <mutex>
|
|
30
|
+
#include <optional>
|
|
31
|
+
#include <set>
|
|
32
|
+
#include <string>
|
|
33
|
+
#include <vector>
|
|
34
|
+
|
|
35
|
+
namespace ngn {
|
|
36
|
+
|
|
37
|
+
class SecretStore {
|
|
38
|
+
public:
|
|
39
|
+
virtual ~SecretStore() = default;
|
|
40
|
+
// Nothing when there is no such item. Throws std::runtime_error when the store fails.
|
|
41
|
+
virtual std::optional<std::string> get(const std::string &service, const std::string &key) = 0;
|
|
42
|
+
virtual void set(const std::string &service, const std::string &key, const std::string &value) = 0;
|
|
43
|
+
virtual void remove(const std::string &service, const std::string &key) = 0;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// Items in `now`, with what `old` still has moved over as it is read: the Data Protection keychain
|
|
47
|
+
// over the file keychain an app used before it was signed with a Team ID. A write or a removal
|
|
48
|
+
// takes the old copy away too, so it never comes back; a removal that cannot tell the old store
|
|
49
|
+
// has none fails.
|
|
50
|
+
class MovingSecretStore final : public SecretStore {
|
|
51
|
+
public:
|
|
52
|
+
MovingSecretStore(std::shared_ptr<SecretStore> now, std::shared_ptr<SecretStore> old)
|
|
53
|
+
: now_(std::move(now)), old_(std::move(old)) {}
|
|
54
|
+
std::optional<std::string> get(const std::string &service, const std::string &key) override;
|
|
55
|
+
void set(const std::string &service, const std::string &key, const std::string &value) override;
|
|
56
|
+
void remove(const std::string &service, const std::string &key) override;
|
|
57
|
+
|
|
58
|
+
private:
|
|
59
|
+
void removeOld(const std::string &service, const std::string &key);
|
|
60
|
+
std::shared_ptr<SecretStore> now_;
|
|
61
|
+
std::shared_ptr<SecretStore> old_;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// A test launch's store: each service is `prefix` and the service asked for, so a run's items
|
|
65
|
+
// never meet the app's own or another run's. `clear()` removes every item this store wrote.
|
|
66
|
+
class PrefixedSecretStore final : public SecretStore {
|
|
67
|
+
public:
|
|
68
|
+
PrefixedSecretStore(std::shared_ptr<SecretStore> inner, std::string prefix) : inner_(std::move(inner)), prefix_(std::move(prefix)) {}
|
|
69
|
+
std::optional<std::string> get(const std::string &service, const std::string &key) override;
|
|
70
|
+
void set(const std::string &service, const std::string &key, const std::string &value) override;
|
|
71
|
+
void remove(const std::string &service, const std::string &key) override;
|
|
72
|
+
void clear();
|
|
73
|
+
|
|
74
|
+
private:
|
|
75
|
+
std::shared_ptr<SecretStore> inner_;
|
|
76
|
+
std::string prefix_;
|
|
77
|
+
std::mutex mutex_;
|
|
78
|
+
std::set<std::pair<std::string, std::string>> written_;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// Whether the app can use the Data Protection keychain: its signature has a Team ID, and an
|
|
82
|
+
// entitlement that gives it a keychain access group (an application identifier, as a Mac App Store
|
|
83
|
+
// build has, or keychain-access-groups). Without one the keychain refuses it (errSecMissingEntitlement).
|
|
84
|
+
bool usesDataProtectionKeychain(const std::string &teamId, const std::set<std::string> &entitlements);
|
|
85
|
+
|
|
86
|
+
// The service items go under when the call names none: the app's own.
|
|
87
|
+
std::shared_ptr<NativeModule> makeSecureStoreModule(std::shared_ptr<SecretStore> store, std::string defaultService);
|
|
88
|
+
bool secureStoreKeyValid(const std::string &key);
|
|
89
|
+
|
|
90
|
+
std::shared_ptr<NativeModule> makeDesktopClipboardModule(std::shared_ptr<System> system, std::shared_ptr<HostState> state);
|
|
91
|
+
|
|
92
|
+
class SleepPreventer {
|
|
93
|
+
public:
|
|
94
|
+
virtual ~SleepPreventer() = default;
|
|
95
|
+
// Keep the display awake, or let it sleep again.
|
|
96
|
+
virtual void hold(bool awake) = 0;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// The tags holding the display awake: it is held while there is any.
|
|
100
|
+
class KeepAwakeTags {
|
|
101
|
+
public:
|
|
102
|
+
explicit KeepAwakeTags(std::shared_ptr<SleepPreventer> preventer) : preventer_(std::move(preventer)) {}
|
|
103
|
+
void activate(const std::string &tag);
|
|
104
|
+
void deactivate(const std::string &tag);
|
|
105
|
+
|
|
106
|
+
private:
|
|
107
|
+
std::shared_ptr<SleepPreventer> preventer_;
|
|
108
|
+
std::set<std::string> tags_;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
std::shared_ptr<NativeModule> makeKeepAwakeModule(std::shared_ptr<KeepAwakeTags> tags);
|
|
112
|
+
|
|
113
|
+
class HapticPlayer {
|
|
114
|
+
public:
|
|
115
|
+
enum class Pattern { Generic, Alignment, LevelChange };
|
|
116
|
+
virtual ~HapticPlayer() = default;
|
|
117
|
+
virtual void play(Pattern pattern) = 0;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// The pattern each of expo-haptics' calls plays: an impact is generic, a selection an alignment,
|
|
121
|
+
// a notification a level change.
|
|
122
|
+
std::optional<HapticPlayer::Pattern> hapticPattern(const std::string &method);
|
|
123
|
+
|
|
124
|
+
std::shared_ptr<NativeModule> makeHapticsModule(std::shared_ptr<HapticPlayer> player);
|
|
125
|
+
|
|
126
|
+
// The OS's open and save panels. Each answers on any thread, with nothing when dismissed.
|
|
127
|
+
class FileDialogs {
|
|
128
|
+
public:
|
|
129
|
+
struct OpenRequest {
|
|
130
|
+
// MIME types ("text/plain", "image/*"); empty for any file.
|
|
131
|
+
std::vector<std::string> types;
|
|
132
|
+
bool multiple{false};
|
|
133
|
+
};
|
|
134
|
+
struct SaveRequest {
|
|
135
|
+
std::string suggestedName;
|
|
136
|
+
// MIME types the file may be saved as, the first the default.
|
|
137
|
+
std::vector<std::string> types;
|
|
138
|
+
};
|
|
139
|
+
virtual ~FileDialogs() = default;
|
|
140
|
+
virtual void openFiles(const OpenRequest &request, std::function<void(std::optional<std::vector<std::string>>)> done) = 0;
|
|
141
|
+
virtual void saveFile(const SaveRequest &request, std::function<void(std::optional<std::string>)> done) = 0;
|
|
142
|
+
virtual void chooseFolder(std::function<void(std::optional<std::string>)> done) = 0;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// Panels that answer as dismissed at once, never shown: a test launch's fake system UI.
|
|
146
|
+
std::shared_ptr<FileDialogs> makeDismissedFileDialogs();
|
|
147
|
+
|
|
148
|
+
// The MIME type of a file name's extension, or application/octet-stream.
|
|
149
|
+
std::string mimeTypeOf(const std::string &name);
|
|
150
|
+
|
|
151
|
+
// `cacheDirectory` is where picked files are copied. What the user picks or saves becomes
|
|
152
|
+
// reachable through `access`, NgNativeFileSystem's, when there is one.
|
|
153
|
+
std::shared_ptr<NativeModule> makeDocumentPickerModule(
|
|
154
|
+
std::shared_ptr<FileDialogs> dialogs,
|
|
155
|
+
std::string cacheDirectory,
|
|
156
|
+
std::shared_ptr<FileAccess> access = nullptr);
|
|
157
|
+
|
|
158
|
+
// One of the user's preferred languages, with the formats of the region the system is set to.
|
|
159
|
+
struct LocaleFacts {
|
|
160
|
+
// BCP 47: "en-GB", "zh-Hant-TW", "ar".
|
|
161
|
+
std::string languageTag;
|
|
162
|
+
bool rightToLeft{false};
|
|
163
|
+
std::string decimalSeparator;
|
|
164
|
+
std::string groupingSeparator;
|
|
165
|
+
// As NSLocale says it: "Metric", "U.S." or "U.K.".
|
|
166
|
+
std::string measurementSystem;
|
|
167
|
+
std::string currencyCode;
|
|
168
|
+
std::string currencySymbol;
|
|
169
|
+
// "celsius" or "fahrenheit".
|
|
170
|
+
std::string temperatureUnit;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
struct CalendarFacts {
|
|
174
|
+
// expo-localization's names: "gregorian", "buddhist", "japanese" and the rest.
|
|
175
|
+
std::string calendar;
|
|
176
|
+
std::string timeZone;
|
|
177
|
+
bool uses24hourClock{false};
|
|
178
|
+
// 1 is Sunday.
|
|
179
|
+
int firstWeekday{1};
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
class LocaleSource {
|
|
183
|
+
public:
|
|
184
|
+
virtual ~LocaleSource() = default;
|
|
185
|
+
// Most preferred first.
|
|
186
|
+
virtual std::vector<LocaleFacts> locales() = 0;
|
|
187
|
+
virtual CalendarFacts calendars() = 0;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// `regionCode` is the system's region ("GB"), which a language tag with no region of its own takes.
|
|
191
|
+
std::shared_ptr<NativeModule> makeLocalizationModule(std::shared_ptr<LocaleSource> source, std::string regionCode);
|
|
192
|
+
|
|
193
|
+
} // namespace ngn
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// ModalHostView with the props the desktop reads: `presentationStyle` and `transparent`, which
|
|
2
|
+
// choose a sheet or an in-window cover, and the one prop the desktop adds, `anchor`, the tag of the
|
|
3
|
+
// view a modal is anchored to, which presents it as a popover at that view (an NSPopover on macOS).
|
|
4
|
+
// React Native's own ModalHostViewProps are final and drop any key they do not declare, so the core
|
|
5
|
+
// registers ModalHostView with props of its own; the shadow node, its state (the size the host
|
|
6
|
+
// sets) and its event emitter are React Native's.
|
|
7
|
+
//
|
|
8
|
+
// `pageSheet`, `formSheet` or no style is a sheet on the window; `fullScreen`, `overFullScreen` or
|
|
9
|
+
// `transparent` is a cover in the window, below its title bar. The presentation and the anchor
|
|
10
|
+
// reach the backend through DesktopPropsSink, with focusable and tabIndex.
|
|
11
|
+
//
|
|
12
|
+
// A sheet takes the size of its content's root: the root's definite CSS width and height where it
|
|
13
|
+
// has them, and otherwise a default width and the height its content lays out to, which takes a
|
|
14
|
+
// second commit. Either way it stays between 320x200 and the window.
|
|
15
|
+
#pragma once
|
|
16
|
+
|
|
17
|
+
#include "ngn/desktop-view-props.h"
|
|
18
|
+
|
|
19
|
+
#include <react/renderer/components/FBReactNativeSpec/EventEmitters.h>
|
|
20
|
+
#include <react/renderer/components/modal/ModalHostViewState.h>
|
|
21
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
22
|
+
|
|
23
|
+
#include <string>
|
|
24
|
+
#include <string_view>
|
|
25
|
+
|
|
26
|
+
namespace facebook::react {
|
|
27
|
+
extern const char ModalHostViewComponentName[];
|
|
28
|
+
} // namespace facebook::react
|
|
29
|
+
|
|
30
|
+
namespace ngn {
|
|
31
|
+
|
|
32
|
+
class DesktopModalProps final : public facebook::react::ViewProps {
|
|
33
|
+
public:
|
|
34
|
+
DesktopModalProps() = default;
|
|
35
|
+
DesktopModalProps(
|
|
36
|
+
const facebook::react::PropsParserContext &context,
|
|
37
|
+
const DesktopModalProps &sourceProps,
|
|
38
|
+
const facebook::react::RawProps &rawProps);
|
|
39
|
+
|
|
40
|
+
// 0 for none.
|
|
41
|
+
int anchor{0};
|
|
42
|
+
std::string presentationStyle;
|
|
43
|
+
bool transparent{false};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
ModalPresentation modalPresentation(const DesktopModalProps &props);
|
|
47
|
+
|
|
48
|
+
// The name a sheet, cover or popover is announced by: the presented view's own accessibility
|
|
49
|
+
// label, or without one its title (a presented screen's header title; a <modal> has none). Empty
|
|
50
|
+
// for no name. The host names the presentation's container with it, and again whenever either
|
|
51
|
+
// changes.
|
|
52
|
+
std::string presentationLabel(std::string_view label, std::string_view title);
|
|
53
|
+
|
|
54
|
+
constexpr facebook::react::Size kMinimumSheetSize{320, 200};
|
|
55
|
+
// A sheet's width when its root has no definite one.
|
|
56
|
+
constexpr facebook::react::Float kDefaultSheetWidth = 480;
|
|
57
|
+
|
|
58
|
+
// A view of a sheet's content as Yoga laid it out, read from the shadow tree rather than the
|
|
59
|
+
// mounted views, which Fabric flattens: a layout-only root with a CSS size is not mounted at all.
|
|
60
|
+
struct SheetNode {
|
|
61
|
+
facebook::react::Rect frame;
|
|
62
|
+
// The definite CSS width and height, in points, where the view has them.
|
|
63
|
+
std::optional<facebook::react::Float> width;
|
|
64
|
+
std::optional<facebook::react::Float> height;
|
|
65
|
+
// Its padding and border, which its content's extent leaves out.
|
|
66
|
+
facebook::react::EdgeInsets insets;
|
|
67
|
+
std::vector<SheetNode> children;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// Whether a child takes room in its sheet's content: not a modal inside, presented on its own, nor
|
|
71
|
+
// a presented screen's header config, which the sheet draws around its content.
|
|
72
|
+
bool takesRoomInSheet(std::string_view componentName);
|
|
73
|
+
|
|
74
|
+
// A laid out shadow node and those under it, leaving out what takes no room in it.
|
|
75
|
+
SheetNode sheetNode(const facebook::react::ShadowNode &node);
|
|
76
|
+
|
|
77
|
+
// The size a sheet takes for `modal`, laid out at the size it has now, on a window whose content
|
|
78
|
+
// is `window`.
|
|
79
|
+
facebook::react::Size sheetSize(const SheetNode &modal, facebook::react::Size window);
|
|
80
|
+
|
|
81
|
+
// The most a popover measures its content against, before it fits.
|
|
82
|
+
constexpr facebook::react::Float kPopoverMax = 640;
|
|
83
|
+
|
|
84
|
+
// The size a popover takes for `presented` (a <modal> or a presented screen), laid out at the size
|
|
85
|
+
// it has now: its root's definite CSS size where it has one, or what its content laid out to, no
|
|
86
|
+
// larger than the window or kPopoverMax. Zero before the content lays out.
|
|
87
|
+
facebook::react::Size popoverSize(const SheetNode &presented, facebook::react::Size window);
|
|
88
|
+
|
|
89
|
+
class DesktopModalShadowNode final : public facebook::react::ConcreteViewShadowNode<
|
|
90
|
+
facebook::react::ModalHostViewComponentName,
|
|
91
|
+
DesktopModalProps,
|
|
92
|
+
facebook::react::ModalHostViewEventEmitter,
|
|
93
|
+
facebook::react::ModalHostViewState> {
|
|
94
|
+
public:
|
|
95
|
+
using ConcreteViewShadowNode::ConcreteViewShadowNode;
|
|
96
|
+
// React Native's ModalHostViewShadowNode's: a root of its own, and never culled.
|
|
97
|
+
static facebook::react::ShadowNodeTraits BaseTraits();
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// React Native's ModalHostViewComponentDescriptor's adoption: the modal takes the size its state
|
|
101
|
+
// says, positioned absolutely.
|
|
102
|
+
class DesktopModalComponentDescriptor final
|
|
103
|
+
: public facebook::react::ConcreteComponentDescriptor<DesktopModalShadowNode> {
|
|
104
|
+
public:
|
|
105
|
+
using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
|
|
106
|
+
void adopt(facebook::react::ShadowNode &shadowNode) const override;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
} // namespace ngn
|