@ng-native/desktop 0.0.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +52 -0
- package/app.plugin.cjs +17 -0
- package/bin/app-config.mjs +168 -0
- package/bin/autolink.mjs +224 -0
- package/bin/cli.mjs +158 -0
- package/bin/host.mjs +427 -0
- package/bin/ng-native-desktop.mjs +4 -0
- package/bin/package.mjs +971 -0
- package/bin/plist.mjs +68 -0
- package/bin/prebuilt.mjs +328 -0
- package/bin/toolchain.mjs +192 -0
- package/native/CMakeLists.txt +276 -0
- package/native/appkit/CMakeLists.txt +109 -0
- package/native/appkit/address-search.h +26 -0
- package/native/appkit/address-search.mm +277 -0
- package/native/appkit/animation-frames.h +14 -0
- package/native/appkit/animation-frames.mm +106 -0
- package/native/appkit/app-info.h +12 -0
- package/native/appkit/app-info.mm +98 -0
- package/native/appkit/app-updater.mm +128 -0
- package/native/appkit/app-windows.h +81 -0
- package/native/appkit/app-windows.mm +318 -0
- package/native/appkit/appkit-backend.h +73 -0
- package/native/appkit/appkit-backend.mm +276 -0
- package/native/appkit/apple-authentication.h +19 -0
- package/native/appkit/apple-authentication.mm +248 -0
- package/native/appkit/apple-button-view.h +10 -0
- package/native/appkit/apple-button-view.mm +37 -0
- package/native/appkit/apple-id-button.h +16 -0
- package/native/appkit/apple-id-button.mm +50 -0
- package/native/appkit/audio.h +16 -0
- package/native/appkit/audio.mm +275 -0
- package/native/appkit/battery.h +13 -0
- package/native/appkit/battery.mm +92 -0
- package/native/appkit/bookmarks.h +17 -0
- package/native/appkit/bookmarks.mm +145 -0
- package/native/appkit/calendar.h +25 -0
- package/native/appkit/calendar.mm +660 -0
- package/native/appkit/camera-view.h +15 -0
- package/native/appkit/camera-view.mm +130 -0
- package/native/appkit/camera.h +39 -0
- package/native/appkit/camera.mm +362 -0
- package/native/appkit/cg-canvas.h +17 -0
- package/native/appkit/cg-canvas.mm +518 -0
- package/native/appkit/component-view.h +17 -0
- package/native/appkit/crypto.h +19 -0
- package/native/appkit/crypto.mm +78 -0
- package/native/appkit/desktop-expo.h +29 -0
- package/native/appkit/desktop-expo.mm +385 -0
- package/native/appkit/expo-image-drawing.h +46 -0
- package/native/appkit/expo-image-drawing.mm +131 -0
- package/native/appkit/expo-image-view.h +15 -0
- package/native/appkit/expo-image-view.mm +182 -0
- package/native/appkit/expo-ui-renderer.h +68 -0
- package/native/appkit/expo-ui-renderer.mm +101 -0
- package/native/appkit/expo-ui-view.h +26 -0
- package/native/appkit/expo-ui-view.mm +134 -0
- package/native/appkit/expo-ui.swift +1284 -0
- package/native/appkit/file-system.h +16 -0
- package/native/appkit/file-system.mm +140 -0
- package/native/appkit/fonts.h +12 -0
- package/native/appkit/fonts.mm +48 -0
- package/native/appkit/geocoder.h +19 -0
- package/native/appkit/geocoder.mm +101 -0
- package/native/appkit/glass-effect.h +22 -0
- package/native/appkit/glass-effect.mm +63 -0
- package/native/appkit/glass-view.h +8 -0
- package/native/appkit/glass-view.mm +65 -0
- package/native/appkit/header-toolbar.h +60 -0
- package/native/appkit/header-toolbar.mm +629 -0
- package/native/appkit/host-view.h +54 -0
- package/native/appkit/host-view.mm +1200 -0
- package/native/appkit/image-manipulator.h +14 -0
- package/native/appkit/image-manipulator.mm +191 -0
- package/native/appkit/image-request.h +22 -0
- package/native/appkit/image-request.mm +62 -0
- package/native/appkit/image-view.h +8 -0
- package/native/appkit/image-view.mm +142 -0
- package/native/appkit/input-replay.h +25 -0
- package/native/appkit/input-replay.mm +418 -0
- package/native/appkit/language-model.h +14 -0
- package/native/appkit/language-model.mm +99 -0
- package/native/appkit/language-model.swift +472 -0
- package/native/appkit/local-authentication.h +15 -0
- package/native/appkit/local-authentication.mm +133 -0
- package/native/appkit/location.h +16 -0
- package/native/appkit/location.mm +214 -0
- package/native/appkit/main.mm +1515 -0
- package/native/appkit/map-view.h +15 -0
- package/native/appkit/map-view.mm +109 -0
- package/native/appkit/maps.h +35 -0
- package/native/appkit/maps.mm +343 -0
- package/native/appkit/menu-bar.h +22 -0
- package/native/appkit/menu-bar.mm +208 -0
- package/native/appkit/modal-focus.h +16 -0
- package/native/appkit/modal-focus.mm +26 -0
- package/native/appkit/modal-host-view.h +79 -0
- package/native/appkit/modal-host-view.mm +442 -0
- package/native/appkit/native-controls.h +22 -0
- package/native/appkit/native-controls.mm +431 -0
- package/native/appkit/network-state.h +12 -0
- package/native/appkit/network-state.mm +64 -0
- package/native/appkit/network.h +14 -0
- package/native/appkit/network.mm +396 -0
- package/native/appkit/notifications.h +19 -0
- package/native/appkit/notifications.mm +309 -0
- package/native/appkit/photo-library.h +33 -0
- package/native/appkit/photo-library.mm +548 -0
- package/native/appkit/pointer-buttons.h +32 -0
- package/native/appkit/presentation-label.h +15 -0
- package/native/appkit/presentation-label.mm +12 -0
- package/native/appkit/presented-screen.h +19 -0
- package/native/appkit/presented-screen.mm +181 -0
- package/native/appkit/printing.h +42 -0
- package/native/appkit/printing.mm +393 -0
- package/native/appkit/push.h +19 -0
- package/native/appkit/push.mm +81 -0
- package/native/appkit/red-box.h +26 -0
- package/native/appkit/red-box.mm +387 -0
- package/native/appkit/screen-capture.h +21 -0
- package/native/appkit/screen-capture.mm +92 -0
- package/native/appkit/scroll-view.h +13 -0
- package/native/appkit/scroll-view.mm +251 -0
- package/native/appkit/scrollers.h +25 -0
- package/native/appkit/scrollers.mm +43 -0
- package/native/appkit/search-field.h +34 -0
- package/native/appkit/search-field.mm +291 -0
- package/native/appkit/search-toolbar-item.h +19 -0
- package/native/appkit/search-toolbar-item.mm +269 -0
- package/native/appkit/share-picker.h +34 -0
- package/native/appkit/share-picker.mm +121 -0
- package/native/appkit/split-view.h +77 -0
- package/native/appkit/split-view.mm +1206 -0
- package/native/appkit/store-review.h +13 -0
- package/native/appkit/store-review.mm +28 -0
- package/native/appkit/surface-view.h +45 -0
- package/native/appkit/surface-view.mm +558 -0
- package/native/appkit/svg-view.h +17 -0
- package/native/appkit/svg-view.mm +57 -0
- package/native/appkit/symbol-drawing.h +24 -0
- package/native/appkit/symbol-drawing.mm +117 -0
- package/native/appkit/symbol-view.h +8 -0
- package/native/appkit/symbol-view.mm +33 -0
- package/native/appkit/system-access.h +34 -0
- package/native/appkit/system-access.mm +210 -0
- package/native/appkit/system.h +24 -0
- package/native/appkit/system.mm +403 -0
- package/native/appkit/test-launch.h +36 -0
- package/native/appkit/test-launch.mm +115 -0
- package/native/appkit/text-input-field.h +76 -0
- package/native/appkit/text-input-field.mm +444 -0
- package/native/appkit/text-layout.h +58 -0
- package/native/appkit/text-layout.mm +477 -0
- package/native/appkit/text-recognition.h +13 -0
- package/native/appkit/text-recognition.mm +102 -0
- package/native/appkit/tracking.h +13 -0
- package/native/appkit/tracking.mm +51 -0
- package/native/appkit/tray-and-dock.h +45 -0
- package/native/appkit/tray-and-dock.mm +130 -0
- package/native/appkit/undo.h +23 -0
- package/native/appkit/undo.mm +125 -0
- package/native/appkit/updates.h +17 -0
- package/native/appkit/updates.mm +71 -0
- package/native/appkit/video-view.h +10 -0
- package/native/appkit/video-view.mm +42 -0
- package/native/appkit/video.h +38 -0
- package/native/appkit/video.mm +404 -0
- package/native/appkit/web-browser.h +12 -0
- package/native/appkit/web-browser.mm +97 -0
- package/native/appkit/web-view-component.h +9 -0
- package/native/appkit/web-view-component.mm +56 -0
- package/native/appkit/web-view.h +31 -0
- package/native/appkit/web-view.mm +394 -0
- package/native/cmake/libraries/react-native-reanimated.cmake +45 -0
- package/native/cmake/libraries/react-native-worklets.cmake +46 -0
- package/native/cmake/libraries.cmake +109 -0
- package/native/cmake/linked-modules.cmake +112 -0
- package/native/cmake/react-native.cmake +175 -0
- package/native/cmake/runtime-dependencies.cmake +34 -0
- package/native/cmake/swift.cmake +43 -0
- package/native/cmake/third-party.cmake +74 -0
- package/native/core/include/ngn/absent-views.h +27 -0
- package/native/core/include/ngn/accessibility.h +140 -0
- package/native/core/include/ngn/address-search.h +69 -0
- package/native/core/include/ngn/animation-frames.h +39 -0
- package/native/core/include/ngn/app-info.h +52 -0
- package/native/core/include/ngn/app-menus.h +146 -0
- package/native/core/include/ngn/app-windows.h +181 -0
- package/native/core/include/ngn/apple-authentication.h +116 -0
- package/native/core/include/ngn/asset.h +28 -0
- package/native/core/include/ngn/audio.h +125 -0
- package/native/core/include/ngn/back-swipe.h +112 -0
- package/native/core/include/ngn/battery.h +48 -0
- package/native/core/include/ngn/bytes.h +59 -0
- package/native/core/include/ngn/calendar.h +180 -0
- package/native/core/include/ngn/camera.h +128 -0
- package/native/core/include/ngn/control-sizes.h +111 -0
- package/native/core/include/ngn/core-modules.h +105 -0
- package/native/core/include/ngn/crypto.h +38 -0
- package/native/core/include/ngn/default-menu.h +91 -0
- package/native/core/include/ngn/desktop-expo.h +193 -0
- package/native/core/include/ngn/desktop-modal.h +109 -0
- package/native/core/include/ngn/desktop-props.h +75 -0
- package/native/core/include/ngn/desktop-view-props.h +110 -0
- package/native/core/include/ngn/dev-server.h +33 -0
- package/native/core/include/ngn/download.h +24 -0
- package/native/core/include/ngn/expo-image.h +192 -0
- package/native/core/include/ngn/expo-ui.h +133 -0
- package/native/core/include/ngn/file-system.h +274 -0
- package/native/core/include/ngn/focus-order.h +63 -0
- package/native/core/include/ngn/fonts.h +64 -0
- package/native/core/include/ngn/gestures.h +305 -0
- package/native/core/include/ngn/glass.h +67 -0
- package/native/core/include/ngn/header-bar.h +112 -0
- package/native/core/include/ngn/host-state.h +243 -0
- package/native/core/include/ngn/image-manipulator.h +70 -0
- package/native/core/include/ngn/input-dispatcher.h +211 -0
- package/native/core/include/ngn/input-script.h +56 -0
- package/native/core/include/ngn/input.h +112 -0
- package/native/core/include/ngn/key-value-store.h +41 -0
- package/native/core/include/ngn/language-model.h +69 -0
- package/native/core/include/ngn/launch-frame.h +47 -0
- package/native/core/include/ngn/launch-settings.h +98 -0
- package/native/core/include/ngn/layout-animations.h +24 -0
- package/native/core/include/ngn/library-components.h +13 -0
- package/native/core/include/ngn/library-glue.h +53 -0
- package/native/core/include/ngn/live-regions.h +54 -0
- package/native/core/include/ngn/local-authentication.h +74 -0
- package/native/core/include/ngn/location.h +89 -0
- package/native/core/include/ngn/maps.h +226 -0
- package/native/core/include/ngn/module-registry.h +51 -0
- package/native/core/include/ngn/mounting-backend.h +96 -0
- package/native/core/include/ngn/mounting-manager.h +155 -0
- package/native/core/include/ngn/native-controls.h +161 -0
- package/native/core/include/ngn/native-module.h +109 -0
- package/native/core/include/ngn/network-state.h +44 -0
- package/native/core/include/ngn/network.h +100 -0
- package/native/core/include/ngn/notifications.h +185 -0
- package/native/core/include/ngn/photo-library.h +130 -0
- package/native/core/include/ngn/printing.h +69 -0
- package/native/core/include/ngn/processes.h +114 -0
- package/native/core/include/ngn/red-box.h +119 -0
- package/native/core/include/ngn/reload-thread.h +258 -0
- package/native/core/include/ngn/runtime.h +161 -0
- package/native/core/include/ngn/safe-areas.h +77 -0
- package/native/core/include/ngn/screen-capture.h +35 -0
- package/native/core/include/ngn/screen-presentation.h +85 -0
- package/native/core/include/ngn/screen-stacks.h +80 -0
- package/native/core/include/ngn/scrollers.h +106 -0
- package/native/core/include/ngn/sharing.h +39 -0
- package/native/core/include/ngn/spawn-rules.h +78 -0
- package/native/core/include/ngn/splash-screen.h +41 -0
- package/native/core/include/ngn/split-view.h +270 -0
- package/native/core/include/ngn/sqlite.h +38 -0
- package/native/core/include/ngn/store-review.h +26 -0
- package/native/core/include/ngn/surface-book.h +101 -0
- package/native/core/include/ngn/svg.h +393 -0
- package/native/core/include/ngn/symbol.h +90 -0
- package/native/core/include/ngn/system.h +102 -0
- package/native/core/include/ngn/tabs-host.h +171 -0
- package/native/core/include/ngn/text-input.h +125 -0
- package/native/core/include/ngn/text-measurer.h +38 -0
- package/native/core/include/ngn/text-recognition.h +55 -0
- package/native/core/include/ngn/tracking.h +34 -0
- package/native/core/include/ngn/tray-and-dock.h +107 -0
- package/native/core/include/ngn/undo.h +37 -0
- package/native/core/include/ngn/updates.h +253 -0
- package/native/core/include/ngn/video.h +126 -0
- package/native/core/include/ngn/view-box.h +126 -0
- package/native/core/include/ngn/view-transform.h +26 -0
- package/native/core/include/ngn/view-tree.h +85 -0
- package/native/core/include/ngn/web-browser.h +45 -0
- package/native/core/include/ngn/web-view.h +133 -0
- package/native/core/include/ngn/worklet-host.h +98 -0
- package/native/core/src/absent-views.cpp +41 -0
- package/native/core/src/accessibility.cpp +374 -0
- package/native/core/src/animation-frames.cpp +49 -0
- package/native/core/src/app-menus.cpp +352 -0
- package/native/core/src/app-windows.cpp +444 -0
- package/native/core/src/back-swipe.cpp +91 -0
- package/native/core/src/bytes.cpp +158 -0
- package/native/core/src/control-sizes.cpp +232 -0
- package/native/core/src/default-menu.cpp +96 -0
- package/native/core/src/desktop-modal.cpp +162 -0
- package/native/core/src/desktop-view-props.cpp +80 -0
- package/native/core/src/dev-server-helper.cpp +152 -0
- package/native/core/src/dev-server.cpp +103 -0
- package/native/core/src/download.cpp +53 -0
- package/native/core/src/expo-image.cpp +548 -0
- package/native/core/src/expo-ui.cpp +203 -0
- package/native/core/src/focus-order.cpp +441 -0
- package/native/core/src/gestures.cpp +1806 -0
- package/native/core/src/glass.cpp +49 -0
- package/native/core/src/header-bar.cpp +104 -0
- package/native/core/src/host-services.cpp +50 -0
- package/native/core/src/host-state.cpp +61 -0
- package/native/core/src/input-dispatcher.cpp +727 -0
- package/native/core/src/input-script.cpp +123 -0
- package/native/core/src/key-value-store.cpp +169 -0
- package/native/core/src/launch-settings.cpp +148 -0
- package/native/core/src/layout-animations.cpp +62 -0
- package/native/core/src/libraries/RNCWebViewSpec.cpp +80 -0
- package/native/core/src/libraries/react-native-reanimated.cpp +216 -0
- package/native/core/src/libraries/react-native-worklets.cpp +192 -0
- package/native/core/src/libraries/rnscreens.cpp +125 -0
- package/native/core/src/libraries/rnsvg.cpp +345 -0
- package/native/core/src/libraries/safeareacontext.cpp +70 -0
- package/native/core/src/libraries/worklets-idle-frames.js +70 -0
- package/native/core/src/library-glue.cpp +35 -0
- package/native/core/src/live-regions.cpp +122 -0
- package/native/core/src/module-registry.cpp +50 -0
- package/native/core/src/modules/accessibility-manager.cpp +98 -0
- package/native/core/src/modules/address-search.cpp +219 -0
- package/native/core/src/modules/alert-manager.cpp +140 -0
- package/native/core/src/modules/app-info.cpp +74 -0
- package/native/core/src/modules/app-modules.cpp +405 -0
- package/native/core/src/modules/apple-authentication.cpp +188 -0
- package/native/core/src/modules/asset.cpp +111 -0
- package/native/core/src/modules/async-storage.cpp +192 -0
- package/native/core/src/modules/audio.cpp +541 -0
- package/native/core/src/modules/battery.cpp +88 -0
- package/native/core/src/modules/calendar.cpp +457 -0
- package/native/core/src/modules/camera.cpp +221 -0
- package/native/core/src/modules/core-modules.cpp +62 -0
- package/native/core/src/modules/crypto.cpp +117 -0
- package/native/core/src/modules/desktop-expo.cpp +527 -0
- package/native/core/src/modules/file-system.cpp +941 -0
- package/native/core/src/modules/fonts.cpp +163 -0
- package/native/core/src/modules/image-loader.cpp +105 -0
- package/native/core/src/modules/image-manipulator.cpp +305 -0
- package/native/core/src/modules/language-model.cpp +195 -0
- package/native/core/src/modules/local-authentication.cpp +140 -0
- package/native/core/src/modules/location.cpp +186 -0
- package/native/core/src/modules/maps.cpp +500 -0
- package/native/core/src/modules/network-state.cpp +72 -0
- package/native/core/src/modules/networking.cpp +387 -0
- package/native/core/src/modules/notifications.cpp +549 -0
- package/native/core/src/modules/photo-library.cpp +371 -0
- package/native/core/src/modules/printing.cpp +201 -0
- package/native/core/src/modules/screen-capture.cpp +71 -0
- package/native/core/src/modules/sharing.cpp +59 -0
- package/native/core/src/modules/splash-screen.cpp +70 -0
- package/native/core/src/modules/sqlite.cpp +421 -0
- package/native/core/src/modules/store-review.cpp +23 -0
- package/native/core/src/modules/text-recognition.cpp +107 -0
- package/native/core/src/modules/tracking.cpp +46 -0
- package/native/core/src/modules/undo.cpp +59 -0
- package/native/core/src/modules/video.cpp +366 -0
- package/native/core/src/modules/web-browser.cpp +100 -0
- package/native/core/src/modules/web-socket.cpp +266 -0
- package/native/core/src/mounting-manager.cpp +380 -0
- package/native/core/src/native-controls.cpp +129 -0
- package/native/core/src/native-module.cpp +250 -0
- package/native/core/src/network.cpp +219 -0
- package/native/core/src/posix-launcher.cpp +366 -0
- package/native/core/src/processes.cpp +324 -0
- package/native/core/src/red-box-errors.js +83 -0
- package/native/core/src/red-box.cpp +306 -0
- package/native/core/src/runtime.cpp +422 -0
- package/native/core/src/safe-areas.cpp +130 -0
- package/native/core/src/screen-presentation.cpp +61 -0
- package/native/core/src/screen-stacks.cpp +254 -0
- package/native/core/src/scrollers.cpp +181 -0
- package/native/core/src/spawn-rules.cpp +292 -0
- package/native/core/src/split-view.cpp +343 -0
- package/native/core/src/svg.cpp +1883 -0
- package/native/core/src/symbol.cpp +94 -0
- package/native/core/src/tabs-host.cpp +234 -0
- package/native/core/src/text-input.cpp +126 -0
- package/native/core/src/text-layout-manager.cpp +63 -0
- package/native/core/src/tray-and-dock.cpp +154 -0
- package/native/core/src/updates.cpp +965 -0
- package/native/core/src/view-box.cpp +788 -0
- package/native/core/src/view-transform.cpp +45 -0
- package/native/core/src/view-tree.cpp +234 -0
- package/native/core/src/web-view.cpp +143 -0
- package/native/core/src/worklet-host.cpp +10 -0
- package/native/scripts/build-hermes.sh +44 -0
- package/native/scripts/build.sh +171 -0
- package/native/scripts/cache-dir.sh +18 -0
- package/native/scripts/codegen-library.sh +193 -0
- package/native/scripts/compiler-launcher.sh +17 -0
- package/native/scripts/fetch.sh +174 -0
- package/native/scripts/hermes-built.sh +10 -0
- package/native/scripts/host-dir.sh +16 -0
- package/native/scripts/macos-target.sh +8 -0
- package/native/scripts/make-prebuilt.mjs +360 -0
- package/native/scripts/prebuilt-host-cache.mjs +158 -0
- package/native/shim/openssl/sha.h +22 -0
- package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +37 -0
- package/package.json +73 -1
- package/prebuilt.json +33 -0
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
#import "header-toolbar.h"
|
|
2
|
+
|
|
3
|
+
#import "search-toolbar-item.h"
|
|
4
|
+
#import "surface-view.h"
|
|
5
|
+
|
|
6
|
+
#include "ngn/header-bar.h"
|
|
7
|
+
|
|
8
|
+
#include <react/renderer/graphics/Color.h>
|
|
9
|
+
|
|
10
|
+
using namespace facebook::react;
|
|
11
|
+
|
|
12
|
+
namespace {
|
|
13
|
+
|
|
14
|
+
ngn::InputSink *gInput = nullptr;
|
|
15
|
+
std::function<void(NSInteger, BOOL)> gContainerRootChanged;
|
|
16
|
+
std::function<void(NSWindow *, ngn::NavigationDirection, int)> gNavigate;
|
|
17
|
+
|
|
18
|
+
NSToolbarItemIdentifier const kHistory = @"ngn.history";
|
|
19
|
+
|
|
20
|
+
NSColor *nsColor(const SharedColor &color) {
|
|
21
|
+
if (!color) {
|
|
22
|
+
return nil;
|
|
23
|
+
}
|
|
24
|
+
auto c = colorComponentsFromColor(color);
|
|
25
|
+
return [NSColor colorWithSRGBRed:c.red green:c.green blue:c.blue alpha:c.alpha];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
NSString *nsString(const std::string &s) {
|
|
29
|
+
NSString *result = [NSString stringWithUTF8String:s.c_str()];
|
|
30
|
+
return result != nil ? result : @"";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
NSImage *symbol(const std::string &name, NSString *description) {
|
|
34
|
+
if (name.empty()) {
|
|
35
|
+
return nil;
|
|
36
|
+
}
|
|
37
|
+
return [NSImage imageWithSystemSymbolName:nsString(name) accessibilityDescription:description];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
} // namespace
|
|
41
|
+
|
|
42
|
+
#pragma mark - Config and subviews
|
|
43
|
+
|
|
44
|
+
@implementation NGNHeaderConfigView
|
|
45
|
+
- (instancetype)initWithShadowView:(const ShadowView &)view {
|
|
46
|
+
if ((self = [super initWithShadowView:view])) {
|
|
47
|
+
// Its subtree is never hit in the window's content: what of it shows is in the toolbar.
|
|
48
|
+
if (gContainerRootChanged) {
|
|
49
|
+
gContainerRootChanged(view.tag, YES);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return self;
|
|
53
|
+
}
|
|
54
|
+
- (void)setHidden:(BOOL)hidden {
|
|
55
|
+
[super setHidden:YES];
|
|
56
|
+
}
|
|
57
|
+
@end
|
|
58
|
+
|
|
59
|
+
@interface NGNHeaderSubviewView ()
|
|
60
|
+
@property (nonatomic) BOOL hosted;
|
|
61
|
+
@property (nonatomic, copy) void (^sizeChanged)(NSSize size);
|
|
62
|
+
@end
|
|
63
|
+
|
|
64
|
+
@implementation NGNHeaderSubviewView
|
|
65
|
+
- (void)updateLayout:(const LayoutMetrics &)metrics {
|
|
66
|
+
[super updateLayout:metrics];
|
|
67
|
+
if (_hosted) {
|
|
68
|
+
[self setFrameOrigin:NSZeroPoint];
|
|
69
|
+
if (_sizeChanged) {
|
|
70
|
+
_sizeChanged(self.frame.size);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
@end
|
|
75
|
+
|
|
76
|
+
@implementation NGNSearchBarView
|
|
77
|
+
|
|
78
|
+
- (instancetype)initWithShadowView:(const ShadowView &)view {
|
|
79
|
+
if ((self = [super initWithShadowView:view])) {
|
|
80
|
+
_item = [[NGNSearchToolbarItem alloc]
|
|
81
|
+
initWithItemIdentifier:[NSString stringWithFormat:@"ngn.search.%ld", (long)view.tag]];
|
|
82
|
+
__weak NGNSearchBarView *weakSelf = self;
|
|
83
|
+
_item.input = ^(ngn::SearchBarInput input, NSString *text) {
|
|
84
|
+
auto emitter = weakSelf.eventEmitter;
|
|
85
|
+
if (!emitter) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
for (auto &event : ngn::searchBarEvents(input, text.UTF8String != nullptr ? text.UTF8String : "")) {
|
|
89
|
+
emitter->dispatchEvent(event.name, std::move(event.payload), RawEvent::Category::Discrete);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return self;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
- (void)updateProps:(const Props::Shared &)props {
|
|
97
|
+
[super updateProps:props];
|
|
98
|
+
if (auto config = props ? ngn::searchBarConfig(*props) : std::nullopt) {
|
|
99
|
+
[_item apply:*config];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
- (void)handleCommand:(const std::string &)name args:(const folly::dynamic &)args {
|
|
104
|
+
if (auto command = ngn::searchBarCommand(name, args)) {
|
|
105
|
+
[_item run:*command];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
- (void)setHidden:(BOOL)hidden {
|
|
110
|
+
[super setHidden:YES];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@end
|
|
114
|
+
|
|
115
|
+
#pragma mark - Toolbar
|
|
116
|
+
|
|
117
|
+
// The back and forward chevrons as one control, Finder's and Safari's: a click on a segment goes
|
|
118
|
+
// that way, and pressing and holding it, or a secondary click, lists that way's entries.
|
|
119
|
+
@interface NGNHistoryControl : NSSegmentedControl
|
|
120
|
+
@end
|
|
121
|
+
|
|
122
|
+
@implementation NGNHistoryControl
|
|
123
|
+
- (NSMenu *)menuForEvent:(NSEvent *)event {
|
|
124
|
+
NSPoint point = [self convertPoint:event.locationInWindow fromView:nil];
|
|
125
|
+
NSInteger segment = point.x < NSWidth(self.bounds) / 2 ? 0 : 1;
|
|
126
|
+
return [self isEnabledForSegment:segment] ? [self menuForSegment:segment] : nil;
|
|
127
|
+
}
|
|
128
|
+
@end
|
|
129
|
+
|
|
130
|
+
// A toolbar item's container for a header item's content: part of the surface, hit-tested from
|
|
131
|
+
// the item's root.
|
|
132
|
+
@interface NGNHeaderItemContainer : NGNSurfaceView
|
|
133
|
+
@property (nonatomic, strong) NSLayoutConstraint *width;
|
|
134
|
+
@property (nonatomic, strong) NSLayoutConstraint *height;
|
|
135
|
+
@end
|
|
136
|
+
|
|
137
|
+
@implementation NGNHeaderItemContainer
|
|
138
|
+
@end
|
|
139
|
+
|
|
140
|
+
@implementation NGNHeaderToolbar {
|
|
141
|
+
__weak NSWindow *_window;
|
|
142
|
+
NSString *_appTitle;
|
|
143
|
+
NSToolbar *_toolbar;
|
|
144
|
+
NGNHeaderConfigView *_config;
|
|
145
|
+
NGNView *_screen;
|
|
146
|
+
BOOL _canGoBack;
|
|
147
|
+
std::optional<ngn::WindowHistory> _history;
|
|
148
|
+
ngn::HistoryButtons _buttons;
|
|
149
|
+
ngn::HeaderBar _bar;
|
|
150
|
+
NSArray<NSToolbarItemIdentifier> *_identifiers;
|
|
151
|
+
// Header item views now in the toolbar, by identifier, and the config each came from.
|
|
152
|
+
NSMutableDictionary<NSToolbarItemIdentifier, NGNHeaderSubviewView *> *_hosted;
|
|
153
|
+
NSMapTable<NGNHeaderSubviewView *, NSView *> *_homes;
|
|
154
|
+
// The type (left, right, center...) each hosted item had as it was hosted.
|
|
155
|
+
NSMapTable<NGNHeaderSubviewView *, NSString *> *_hostedTypes;
|
|
156
|
+
// The search items now in the toolbar, by identifier.
|
|
157
|
+
NSMutableDictionary<NSToolbarItemIdentifier, NGNSearchToolbarItem *> *_searchItems;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
+ (ngn::InputSink *)input {
|
|
161
|
+
return gInput;
|
|
162
|
+
}
|
|
163
|
+
+ (void)setInput:(ngn::InputSink *)input {
|
|
164
|
+
gInput = input;
|
|
165
|
+
}
|
|
166
|
+
+ (std::function<void(NSInteger, BOOL)>)containerRootChanged {
|
|
167
|
+
return gContainerRootChanged;
|
|
168
|
+
}
|
|
169
|
+
+ (void)setContainerRootChanged:(std::function<void(NSInteger, BOOL)>)fn {
|
|
170
|
+
gContainerRootChanged = std::move(fn);
|
|
171
|
+
}
|
|
172
|
+
+ (std::function<void(NSWindow *, ngn::NavigationDirection, int)>)navigate {
|
|
173
|
+
return gNavigate;
|
|
174
|
+
}
|
|
175
|
+
+ (void)setNavigate:(std::function<void(NSWindow *, ngn::NavigationDirection, int)>)fn {
|
|
176
|
+
gNavigate = std::move(fn);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
+ (BOOL)showHistoryMenuForEvent:(NSEvent *)event {
|
|
180
|
+
// The window's frame view, whose own coordinates are the window's: the toolbar is in it.
|
|
181
|
+
NSView *frame = event.window.contentView.superview;
|
|
182
|
+
NSView *hit = [frame hitTest:event.locationInWindow];
|
|
183
|
+
for (NSView *v = hit; v != nil; v = v.superview) {
|
|
184
|
+
if ([v isKindOfClass:NGNHistoryControl.class]) {
|
|
185
|
+
NSMenu *menu = [v menuForEvent:event];
|
|
186
|
+
if (menu == nil) {
|
|
187
|
+
return NO;
|
|
188
|
+
}
|
|
189
|
+
// From the run loop rather than here, where a replayed click is inside a main-queue block
|
|
190
|
+
// that the menu's tracking would hold up, and the queue with it.
|
|
191
|
+
CFRunLoopPerformBlock(CFRunLoopGetMain(), kCFRunLoopCommonModes, ^{
|
|
192
|
+
[NSMenu popUpContextMenu:menu withEvent:event forView:v];
|
|
193
|
+
});
|
|
194
|
+
CFRunLoopWakeUp(CFRunLoopGetMain());
|
|
195
|
+
return YES;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return NO;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
- (void)showHistory:(const std::optional<ngn::WindowHistory> &)history {
|
|
202
|
+
if (_history != history) {
|
|
203
|
+
_history = history;
|
|
204
|
+
[self rebuild];
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
- (instancetype)initWithWindow:(NSWindow *)window {
|
|
209
|
+
if ((self = [super init])) {
|
|
210
|
+
_window = window;
|
|
211
|
+
_appTitle = window.title;
|
|
212
|
+
_identifiers = @[];
|
|
213
|
+
_hosted = [NSMutableDictionary dictionary];
|
|
214
|
+
_homes = [NSMapTable weakToWeakObjectsMapTable];
|
|
215
|
+
_hostedTypes = [NSMapTable weakToStrongObjectsMapTable];
|
|
216
|
+
_searchItems = [NSMutableDictionary dictionary];
|
|
217
|
+
_toolbar = [[NSToolbar alloc] initWithIdentifier:@"ngn.header"];
|
|
218
|
+
_toolbar.delegate = self;
|
|
219
|
+
_toolbar.displayMode = NSToolbarDisplayModeIconOnly;
|
|
220
|
+
_toolbar.allowsUserCustomization = NO;
|
|
221
|
+
}
|
|
222
|
+
return self;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
- (void)setSidebar:(BOOL)sidebar {
|
|
226
|
+
if (_sidebar != sidebar) {
|
|
227
|
+
_sidebar = sidebar;
|
|
228
|
+
[self rebuild];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
- (void)showConfig:(NGNHeaderConfigView *)config screen:(NGNView *)screen canGoBack:(BOOL)canGoBack {
|
|
233
|
+
_config = config;
|
|
234
|
+
_screen = screen;
|
|
235
|
+
_canGoBack = canGoBack;
|
|
236
|
+
[self rebuild];
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
- (void)refreshIfShowing:(NGNView *)view {
|
|
240
|
+
if (_config == nil) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
for (NSView *v = view; v != nil; v = v.superview) {
|
|
244
|
+
if (v == _config) {
|
|
245
|
+
[self rebuild];
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
// An item hosted in the toolbar is no longer under the config, but still one of its items: a
|
|
250
|
+
// change of its type (the side it is on) rebuilds the toolbar.
|
|
251
|
+
if ([view isKindOfClass:NGNHeaderSubviewView.class]) {
|
|
252
|
+
auto *item = (NGNHeaderSubviewView *)view;
|
|
253
|
+
NSString *hostedAs = [_hostedTypes objectForKey:item];
|
|
254
|
+
if ([_homes objectForKey:item] == _config && hostedAs != nil && item.props &&
|
|
255
|
+
![hostedAs isEqualToString:@(ngn::headerItemType(*item.props).value_or("").c_str())]) {
|
|
256
|
+
[self rebuild];
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
// A hosted item's own content changed: its size follows its layout.
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
- (NSArray<NGNHeaderSubviewView *> *)itemsOfType:(const std::string &)type {
|
|
264
|
+
NSMutableArray *items = [NSMutableArray array];
|
|
265
|
+
for (NSView *v in _config.subviews) {
|
|
266
|
+
if ([v isKindOfClass:NGNHeaderSubviewView.class] && ((NGNView *)v).props &&
|
|
267
|
+
ngn::headerItemType(*((NGNView *)v).props) == type) {
|
|
268
|
+
[items addObject:v];
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
// Those already in the toolbar are no longer the config's subviews.
|
|
272
|
+
for (NGNHeaderSubviewView *v in _hosted.allValues) {
|
|
273
|
+
if ([_homes objectForKey:v] == _config && v.props && ngn::headerItemType(*v.props) == type) {
|
|
274
|
+
[items addObject:v];
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
[items sortUsingComparator:^NSComparisonResult(NGNView *a, NGNView *b) {
|
|
278
|
+
return a.reactTag < b.reactTag ? NSOrderedAscending : a.reactTag > b.reactTag ? NSOrderedDescending : NSOrderedSame;
|
|
279
|
+
}];
|
|
280
|
+
return items;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
- (void)returnHostedViews {
|
|
284
|
+
for (NSToolbarItemIdentifier identifier in _hosted) {
|
|
285
|
+
NGNHeaderSubviewView *view = _hosted[identifier];
|
|
286
|
+
NSView *home = [_homes objectForKey:view];
|
|
287
|
+
BOOL stillMounted = view.superview != nil;
|
|
288
|
+
view.hosted = NO;
|
|
289
|
+
view.sizeChanged = nil;
|
|
290
|
+
[view removeFromSuperview];
|
|
291
|
+
if (stillMounted && home != nil) {
|
|
292
|
+
[home addSubview:view];
|
|
293
|
+
}
|
|
294
|
+
if (gContainerRootChanged) {
|
|
295
|
+
gContainerRootChanged(view.reactTag, NO);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
[_hosted removeAllObjects];
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
- (void)rebuild {
|
|
302
|
+
NGNSearchToolbarItem *editing = nil;
|
|
303
|
+
for (NGNSearchToolbarItem *item in _searchItems.allValues) {
|
|
304
|
+
if (item.searchField.currentEditor != nil) {
|
|
305
|
+
editing = item;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
if (editing != nil) {
|
|
309
|
+
[editing keepFocusAcross:^{
|
|
310
|
+
[self rebuildItems];
|
|
311
|
+
}];
|
|
312
|
+
} else {
|
|
313
|
+
[self rebuildItems];
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
- (void)rebuildItems {
|
|
318
|
+
NSWindow *window = _window;
|
|
319
|
+
if (window == nil) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
[self returnHostedViews];
|
|
323
|
+
[_searchItems removeAllObjects];
|
|
324
|
+
auto bar = _config && _config.props ? ngn::headerBar(*_config.props) : std::nullopt;
|
|
325
|
+
_bar = bar.value_or(ngn::HeaderBar{});
|
|
326
|
+
|
|
327
|
+
NSMutableArray<NSToolbarItemIdentifier> *ids = [NSMutableArray array];
|
|
328
|
+
if (_sidebar) {
|
|
329
|
+
[ids addObject:NSToolbarToggleSidebarItemIdentifier];
|
|
330
|
+
[ids addObject:NSToolbarSidebarTrackingSeparatorItemIdentifier];
|
|
331
|
+
}
|
|
332
|
+
if (!bar) {
|
|
333
|
+
// No header in front: the chevrons still lead the content pane while the window has history.
|
|
334
|
+
_buttons = ngn::historyButtons(_history, NO, NO);
|
|
335
|
+
if (_buttons.shown && _sidebar) {
|
|
336
|
+
[ids addObject:kHistory];
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (bar) {
|
|
340
|
+
NSArray *left = [self itemsOfType:"left"];
|
|
341
|
+
NSArray *center = [self itemsOfType:"center"];
|
|
342
|
+
NSArray *right = [self itemsOfType:"right"];
|
|
343
|
+
BOOL replacesBack = left.count > 0 || !_bar.left.empty();
|
|
344
|
+
_buttons = ngn::historyButtons(_history, _canGoBack, _bar.hideBackButton || replacesBack);
|
|
345
|
+
if (_buttons.shown) {
|
|
346
|
+
[ids addObject:kHistory];
|
|
347
|
+
}
|
|
348
|
+
for (NGNHeaderSubviewView *v in left) {
|
|
349
|
+
[ids addObject:[self host:v]];
|
|
350
|
+
}
|
|
351
|
+
for (size_t i = 0; i < _bar.left.size(); i++) {
|
|
352
|
+
[ids addObject:[NSString stringWithFormat:@"ngn.button.left.%zu", i]];
|
|
353
|
+
}
|
|
354
|
+
[ids addObject:NSToolbarFlexibleSpaceItemIdentifier];
|
|
355
|
+
for (NGNHeaderSubviewView *v in center) {
|
|
356
|
+
[ids addObject:[self host:v]];
|
|
357
|
+
}
|
|
358
|
+
if (center.count > 0) {
|
|
359
|
+
[ids addObject:NSToolbarFlexibleSpaceItemIdentifier];
|
|
360
|
+
}
|
|
361
|
+
for (size_t i = 0; i < _bar.right.size(); i++) {
|
|
362
|
+
[ids addObject:[NSString stringWithFormat:@"ngn.button.right.%zu", i]];
|
|
363
|
+
}
|
|
364
|
+
for (NGNHeaderSubviewView *v in right) {
|
|
365
|
+
[ids addObject:[self host:v]];
|
|
366
|
+
}
|
|
367
|
+
for (NGNHeaderSubviewView *v in [self itemsOfType:"searchBar"]) {
|
|
368
|
+
for (NSView *child in v.subviews) {
|
|
369
|
+
if ([child isKindOfClass:NGNSearchBarView.class]) {
|
|
370
|
+
NGNSearchToolbarItem *item = ((NGNSearchBarView *)child).item;
|
|
371
|
+
_searchItems[item.itemIdentifier] = item;
|
|
372
|
+
[ids addObject:item.itemIdentifier];
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
_identifiers = ids;
|
|
378
|
+
|
|
379
|
+
window.title = bar && !_bar.title.empty() ? nsString(_bar.title) : _appTitle;
|
|
380
|
+
while (_toolbar.items.count > 0) {
|
|
381
|
+
[_toolbar removeItemAtIndex:0];
|
|
382
|
+
}
|
|
383
|
+
for (NSUInteger i = 0; i < ids.count; i++) {
|
|
384
|
+
[_toolbar insertItemWithItemIdentifier:ids[i] atIndex:(NSInteger)i];
|
|
385
|
+
}
|
|
386
|
+
if ((bar && !_bar.hidden) || _sidebar) {
|
|
387
|
+
window.toolbar = _toolbar;
|
|
388
|
+
window.toolbarStyle = NSWindowToolbarStyleUnified;
|
|
389
|
+
window.titlebarSeparatorStyle =
|
|
390
|
+
bar && _bar.hideShadow ? NSTitlebarSeparatorStyleNone : NSTitlebarSeparatorStyleAutomatic;
|
|
391
|
+
} else {
|
|
392
|
+
window.toolbar = nil;
|
|
393
|
+
}
|
|
394
|
+
// The safe area's top follows the toolbar; containers report it as they lay out.
|
|
395
|
+
window.contentView.needsLayout = YES;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// Moves a header item's view into a container of its own, which its toolbar item shows.
|
|
399
|
+
- (NSToolbarItemIdentifier)host:(NGNHeaderSubviewView *)view {
|
|
400
|
+
NSToolbarItemIdentifier identifier = [NSString stringWithFormat:@"ngn.view.%ld", (long)view.reactTag];
|
|
401
|
+
[_homes setObject:view.superview != nil ? view.superview : _config forKey:view];
|
|
402
|
+
[_hostedTypes setObject:view.props ? @(ngn::headerItemType(*view.props).value_or("").c_str()) : @"" forKey:view];
|
|
403
|
+
_hosted[identifier] = view;
|
|
404
|
+
return identifier;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar
|
|
408
|
+
itemForItemIdentifier:(NSToolbarItemIdentifier)identifier
|
|
409
|
+
willBeInsertedIntoToolbar:(BOOL)flag {
|
|
410
|
+
NSToolbarItem *item = nil;
|
|
411
|
+
NSColor *tint = nsColor(_bar.color);
|
|
412
|
+
if ([identifier isEqualToString:kHistory]) {
|
|
413
|
+
item = [[NSToolbarItem alloc] initWithItemIdentifier:identifier];
|
|
414
|
+
item.view = [self historyControlWithTint:tint];
|
|
415
|
+
item.label = @"Back/Forward";
|
|
416
|
+
// Before the title, as Finder's and Safari's are.
|
|
417
|
+
item.navigational = YES;
|
|
418
|
+
} else if (NGNSearchToolbarItem *search = _searchItems[identifier]) {
|
|
419
|
+
item = search;
|
|
420
|
+
} else if (NGNHeaderSubviewView *view = _hosted[identifier]) {
|
|
421
|
+
item = [self itemHosting:view identifier:identifier];
|
|
422
|
+
} else if ([identifier hasPrefix:@"ngn.button."]) {
|
|
423
|
+
BOOL left = [identifier hasPrefix:@"ngn.button.left."];
|
|
424
|
+
size_t index = (size_t)[identifier.pathExtension integerValue];
|
|
425
|
+
const auto &buttons = left ? _bar.left : _bar.right;
|
|
426
|
+
if (index < buttons.size()) {
|
|
427
|
+
item = [self itemForButton:buttons[index] identifier:identifier tint:tint];
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return item;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
- (NSToolbarItem *)itemHosting:(NGNHeaderSubviewView *)view identifier:(NSToolbarItemIdentifier)identifier {
|
|
434
|
+
NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier:identifier];
|
|
435
|
+
NSSize size = view.frame.size;
|
|
436
|
+
NGNHeaderItemContainer *container = [[NGNHeaderItemContainer alloc]
|
|
437
|
+
initWithFrame:NSMakeRect(0, 0, size.width, size.height)
|
|
438
|
+
surfaceId:static_cast<SurfaceId>(view.surfaceId)
|
|
439
|
+
container:static_cast<ngn::ContainerId>(view.reactTag)
|
|
440
|
+
rootTag:static_cast<Tag>(view.reactTag)
|
|
441
|
+
input:gInput];
|
|
442
|
+
container.translatesAutoresizingMaskIntoConstraints = NO;
|
|
443
|
+
container.width = [container.widthAnchor constraintEqualToConstant:size.width];
|
|
444
|
+
container.height = [container.heightAnchor constraintEqualToConstant:size.height];
|
|
445
|
+
container.width.active = YES;
|
|
446
|
+
container.height.active = YES;
|
|
447
|
+
[view removeFromSuperview];
|
|
448
|
+
[view setFrameOrigin:NSZeroPoint];
|
|
449
|
+
[container addSubview:view];
|
|
450
|
+
view.hosted = YES;
|
|
451
|
+
__weak NGNHeaderItemContainer *weakContainer = container;
|
|
452
|
+
view.sizeChanged = ^(NSSize newSize) {
|
|
453
|
+
weakContainer.width.constant = newSize.width;
|
|
454
|
+
weakContainer.height.constant = newSize.height;
|
|
455
|
+
};
|
|
456
|
+
if (gContainerRootChanged) {
|
|
457
|
+
gContainerRootChanged(view.reactTag, YES);
|
|
458
|
+
}
|
|
459
|
+
item.view = container;
|
|
460
|
+
return item;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
- (NSToolbarItem *)itemForButton:(const ngn::BarButton &)button
|
|
464
|
+
identifier:(NSToolbarItemIdentifier)identifier
|
|
465
|
+
tint:(NSColor *)headerTint {
|
|
466
|
+
if (button.spacing) {
|
|
467
|
+
NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier:identifier];
|
|
468
|
+
item.view = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, *button.spacing, 1)];
|
|
469
|
+
return item;
|
|
470
|
+
}
|
|
471
|
+
NSString *title = nsString(button.title);
|
|
472
|
+
NSString *label = button.accessibilityLabel.empty() ? title : nsString(button.accessibilityLabel);
|
|
473
|
+
NSImage *image = symbol(button.symbol, label);
|
|
474
|
+
NSColor *tint = button.tint ? nsColor(button.tint) : headerTint;
|
|
475
|
+
if (button.menu) {
|
|
476
|
+
NSMenuToolbarItem *item = [[NSMenuToolbarItem alloc] initWithItemIdentifier:identifier];
|
|
477
|
+
item.menu = [self menuFor:*button.menu];
|
|
478
|
+
item.title = image != nil ? @"" : title;
|
|
479
|
+
item.image = image;
|
|
480
|
+
item.label = label;
|
|
481
|
+
item.enabled = !button.disabled;
|
|
482
|
+
item.showsIndicator = image == nil;
|
|
483
|
+
return item;
|
|
484
|
+
}
|
|
485
|
+
NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier:identifier];
|
|
486
|
+
NSButton *view = [self buttonWithTitle:image != nil ? nil : title image:image tint:tint action:@selector(pressButton:)];
|
|
487
|
+
view.identifier = nsString(button.id);
|
|
488
|
+
view.enabled = !button.disabled;
|
|
489
|
+
view.toolTip = label.length > 0 ? label : nil;
|
|
490
|
+
item.view = view;
|
|
491
|
+
item.label = label;
|
|
492
|
+
return item;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
- (NSButton *)buttonWithTitle:(NSString *)title image:(NSImage *)image tint:(NSColor *)tint action:(SEL)action {
|
|
496
|
+
NSButton *button = image != nil ? [NSButton buttonWithImage:image target:self action:action]
|
|
497
|
+
: [NSButton buttonWithTitle:title != nil ? title : @"" target:self action:action];
|
|
498
|
+
#pragma clang diagnostic push
|
|
499
|
+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
500
|
+
button.bezelStyle = NSBezelStyleTexturedRounded;
|
|
501
|
+
#pragma clang diagnostic pop
|
|
502
|
+
if (tint != nil) {
|
|
503
|
+
button.contentTintColor = tint;
|
|
504
|
+
}
|
|
505
|
+
return button;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
- (NSMenu *)menuFor:(const ngn::HeaderMenuItem &)entry {
|
|
509
|
+
NSMenu *menu = [[NSMenu alloc] initWithTitle:nsString(entry.title)];
|
|
510
|
+
for (const auto &child : entry.items) {
|
|
511
|
+
if (child.inlineSection) {
|
|
512
|
+
[menu addItem:NSMenuItem.separatorItem];
|
|
513
|
+
for (const auto &inner : child.items) {
|
|
514
|
+
[menu addItem:[self menuItemFor:inner]];
|
|
515
|
+
}
|
|
516
|
+
[menu addItem:NSMenuItem.separatorItem];
|
|
517
|
+
} else {
|
|
518
|
+
[menu addItem:[self menuItemFor:child]];
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
return menu;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
- (NSMenuItem *)menuItemFor:(const ngn::HeaderMenuItem &)entry {
|
|
525
|
+
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:nsString(entry.title) action:nil keyEquivalent:@""];
|
|
526
|
+
item.image = symbol(entry.symbol, nil);
|
|
527
|
+
item.state = entry.on ? NSControlStateValueOn : NSControlStateValueOff;
|
|
528
|
+
if (!entry.items.empty() || entry.menuId.empty()) {
|
|
529
|
+
item.submenu = [self menuFor:entry];
|
|
530
|
+
} else {
|
|
531
|
+
item.representedObject = nsString(entry.menuId);
|
|
532
|
+
item.target = self;
|
|
533
|
+
item.action = entry.disabled ? nil : @selector(chooseMenuItem:);
|
|
534
|
+
}
|
|
535
|
+
return item;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
- (NGNHistoryControl *)historyControlWithTint:(NSColor *)tint {
|
|
539
|
+
NSArray<NSImage *> *images = @[ symbol("chevron.backward", @"Back"), symbol("chevron.forward", @"Forward") ];
|
|
540
|
+
if (tint != nil) {
|
|
541
|
+
// The header's tint on the chevrons, as on the bar's other buttons: a segment has no content
|
|
542
|
+
// tint of its own, so the symbol is drawn in that colour.
|
|
543
|
+
NSImageSymbolConfiguration *colour = [NSImageSymbolConfiguration configurationWithPaletteColors:@[ tint ]];
|
|
544
|
+
images = @[
|
|
545
|
+
[images[0] imageWithSymbolConfiguration:colour], [images[1] imageWithSymbolConfiguration:colour]
|
|
546
|
+
];
|
|
547
|
+
}
|
|
548
|
+
NGNHistoryControl *control = [NGNHistoryControl segmentedControlWithImages:images
|
|
549
|
+
trackingMode:NSSegmentSwitchTrackingMomentary
|
|
550
|
+
target:self
|
|
551
|
+
action:@selector(chooseChevron:)];
|
|
552
|
+
control.segmentStyle = NSSegmentStyleSeparated;
|
|
553
|
+
[control setToolTip:@"Back" forSegment:0];
|
|
554
|
+
[control setToolTip:@"Forward" forSegment:1];
|
|
555
|
+
[control setEnabled:_buttons.backEnabled forSegment:0];
|
|
556
|
+
[control setEnabled:_buttons.forwardEnabled forSegment:1];
|
|
557
|
+
if (_history && _buttons.fromHistory) {
|
|
558
|
+
[control setMenu:[self historyMenu:ngn::NavigationDirection::Back] forSegment:0];
|
|
559
|
+
[control setMenu:[self historyMenu:ngn::NavigationDirection::Forward] forSegment:1];
|
|
560
|
+
[control setShowsMenuIndicator:NO forSegment:0];
|
|
561
|
+
[control setShowsMenuIndicator:NO forSegment:1];
|
|
562
|
+
}
|
|
563
|
+
return control;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
- (NSMenu *)historyMenu:(ngn::NavigationDirection)direction {
|
|
567
|
+
NSMenu *menu = [[NSMenu alloc] initWithTitle:direction == ngn::NavigationDirection::Back ? @"Back" : @"Forward"];
|
|
568
|
+
for (const auto &entry : ngn::historyMenu(*_history, direction)) {
|
|
569
|
+
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:nsString(entry.title)
|
|
570
|
+
action:@selector(chooseHistoryItem:)
|
|
571
|
+
keyEquivalent:@""];
|
|
572
|
+
item.target = self;
|
|
573
|
+
item.tag = direction == ngn::NavigationDirection::Back ? -entry.steps : entry.steps;
|
|
574
|
+
[menu addItem:item];
|
|
575
|
+
}
|
|
576
|
+
return menu;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
- (void)chooseChevron:(NGNHistoryControl *)sender {
|
|
580
|
+
auto direction = sender.selectedSegment == 0 ? ngn::NavigationDirection::Back : ngn::NavigationDirection::Forward;
|
|
581
|
+
if (_buttons.fromHistory) {
|
|
582
|
+
if (gNavigate) {
|
|
583
|
+
gNavigate(_window, direction, 1);
|
|
584
|
+
}
|
|
585
|
+
} else if (direction == ngn::NavigationDirection::Back) {
|
|
586
|
+
[self goBack:sender];
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
- (void)chooseHistoryItem:(NSMenuItem *)sender {
|
|
591
|
+
if (gNavigate && sender.tag != 0) {
|
|
592
|
+
gNavigate(
|
|
593
|
+
_window,
|
|
594
|
+
sender.tag < 0 ? ngn::NavigationDirection::Back : ngn::NavigationDirection::Forward,
|
|
595
|
+
static_cast<int>(sender.tag < 0 ? -sender.tag : sender.tag));
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
- (void)goBack:(id)sender {
|
|
600
|
+
if (auto emitter = _screen.eventEmitter) {
|
|
601
|
+
emitter->dispatchEvent("headerBackButtonClicked");
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
- (void)pressButton:(NSButton *)sender {
|
|
606
|
+
if (auto emitter = _config.eventEmitter) {
|
|
607
|
+
emitter->dispatchEvent("pressHeaderBarButtonItem", folly::dynamic::object("buttonId", sender.identifier.UTF8String));
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
- (void)chooseMenuItem:(NSMenuItem *)sender {
|
|
612
|
+
NSString *menuId = sender.representedObject;
|
|
613
|
+
if (auto emitter = _config.eventEmitter; emitter && menuId != nil) {
|
|
614
|
+
emitter->dispatchEvent("pressHeaderBarButtonMenuItem", folly::dynamic::object("menuId", menuId.UTF8String));
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
- (NSArray<NSToolbarItemIdentifier> *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar {
|
|
619
|
+
return _identifiers;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
- (NSArray<NSToolbarItemIdentifier> *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar {
|
|
623
|
+
return [_identifiers arrayByAddingObjectsFromArray:@[
|
|
624
|
+
NSToolbarFlexibleSpaceItemIdentifier, NSToolbarToggleSidebarItemIdentifier,
|
|
625
|
+
NSToolbarSidebarTrackingSeparatorItemIdentifier
|
|
626
|
+
]];
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
@end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// The NSView every Fabric view mounts as: layer-backed, flipped, placed at Yoga's frame.
|
|
2
|
+
// A Paragraph draws its text with Core Text; a TextInput hosts a real NSTextField.
|
|
3
|
+
#pragma once
|
|
4
|
+
|
|
5
|
+
#import <AppKit/AppKit.h>
|
|
6
|
+
|
|
7
|
+
#include "ngn/accessibility.h"
|
|
8
|
+
#include "ngn/desktop-view-props.h"
|
|
9
|
+
#include "ngn/input-dispatcher.h"
|
|
10
|
+
|
|
11
|
+
#include <react/renderer/mounting/ShadowView.h>
|
|
12
|
+
|
|
13
|
+
@interface NGNView : NSView
|
|
14
|
+
// Set once by the host: where VoiceOver's press, Space and Return on a focused view send the click
|
|
15
|
+
// they stand for when the view has no accessibility handler of its own.
|
|
16
|
+
@property (class, nonatomic) ngn::InputDispatcher *activator;
|
|
17
|
+
@property (nonatomic, readonly) NSInteger reactTag;
|
|
18
|
+
@property (nonatomic, readonly) NSInteger surfaceId;
|
|
19
|
+
@property (nonatomic, readonly, copy) NSString *componentName;
|
|
20
|
+
// A screen below the top of its stack: hidden, and kept mounted.
|
|
21
|
+
@property (nonatomic) BOOL covered;
|
|
22
|
+
// A back swipe's frame (back-swipe.h): the screen in front moved right by `swipeOffset` points
|
|
23
|
+
// and faded to `swipeOpacity`, and the covered screen below it drawn while `swipeShown`. Layout
|
|
24
|
+
// keeps them until the swipe sets them back.
|
|
25
|
+
@property (nonatomic) CGFloat swipeOffset;
|
|
26
|
+
@property (nonatomic) CGFloat swipeOpacity;
|
|
27
|
+
@property (nonatomic) BOOL swipeShown;
|
|
28
|
+
- (instancetype)initWithShadowView:(const facebook::react::ShadowView &)view;
|
|
29
|
+
- (void)updateProps:(const facebook::react::Props::Shared &)props;
|
|
30
|
+
- (void)updateLayout:(const facebook::react::LayoutMetrics &)metrics;
|
|
31
|
+
- (void)updateState:(const facebook::react::State::Shared &)state;
|
|
32
|
+
- (void)updateEventEmitter:(const facebook::react::EventEmitter::Shared &)emitter;
|
|
33
|
+
- (void)updateDesktopProps:(const ngn::DesktopProps &)props;
|
|
34
|
+
- (void)handleCommand:(const std::string &)name args:(const folly::dynamic &)args;
|
|
35
|
+
- (facebook::react::EventEmitter::Shared)eventEmitter;
|
|
36
|
+
- (const ngn::DesktopProps &)desktopProps;
|
|
37
|
+
- (facebook::react::Props::Shared)props;
|
|
38
|
+
- (facebook::react::State::Shared)state;
|
|
39
|
+
- (const facebook::react::LayoutMetrics &)layoutMetrics;
|
|
40
|
+
// What VoiceOver is told about the view (accessibility.h).
|
|
41
|
+
- (ngn::AxInfo)axInfo;
|
|
42
|
+
// Where Fabric children mount: the view itself, or a scroll view's document view.
|
|
43
|
+
- (NSView *)contentContainer;
|
|
44
|
+
// What takes the keyboard when Tab moves the focus here: the view itself, or the AppKit control
|
|
45
|
+
// or field it holds.
|
|
46
|
+
- (NSResponder *)keyboardResponder;
|
|
47
|
+
@end
|
|
48
|
+
|
|
49
|
+
// Hosts a real NSTextField, so the field editor, NSTextInputClient and IME are AppKit's own.
|
|
50
|
+
@interface NGNTextInputView : NGNView <NSTextFieldDelegate>
|
|
51
|
+
@end
|
|
52
|
+
|
|
53
|
+
// The view for a component name: a text field for TextInput, a plain NGNView otherwise.
|
|
54
|
+
NGNView *NGNMakeView(const facebook::react::ShadowView &view);
|