@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,251 @@
|
|
|
1
|
+
#import "scroll-view.h"
|
|
2
|
+
|
|
3
|
+
#import "scrollers.h"
|
|
4
|
+
|
|
5
|
+
#include <react/renderer/components/scrollview/ScrollViewEventEmitter.h>
|
|
6
|
+
#include <react/renderer/components/scrollview/ScrollViewProps.h>
|
|
7
|
+
#include <react/renderer/components/scrollview/ScrollViewState.h>
|
|
8
|
+
#include <react/renderer/core/ConcreteState.h>
|
|
9
|
+
|
|
10
|
+
using namespace facebook::react;
|
|
11
|
+
|
|
12
|
+
namespace {
|
|
13
|
+
std::function<void(NSInteger, CGPoint)> gOffsetChanged;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@interface NGNScrollDocumentView : NSView
|
|
17
|
+
@end
|
|
18
|
+
|
|
19
|
+
@implementation NGNScrollDocumentView
|
|
20
|
+
- (BOOL)isFlipped {
|
|
21
|
+
return YES;
|
|
22
|
+
}
|
|
23
|
+
@end
|
|
24
|
+
|
|
25
|
+
@implementation NGNScrollView {
|
|
26
|
+
NGNWheelScrollView *_scrollView;
|
|
27
|
+
NGNScrollDocumentView *_document;
|
|
28
|
+
State::Shared _scrollState;
|
|
29
|
+
BOOL _applyingState;
|
|
30
|
+
BOOL _showsVertical;
|
|
31
|
+
BOOL _showsHorizontal;
|
|
32
|
+
NGNScrollerStyleObserver *_styleObserver;
|
|
33
|
+
// The `contentOffset` prop last read, and one not yet applied: it waits for the content's size
|
|
34
|
+
// and the view's, and is applied once, as the prop arrives or changes.
|
|
35
|
+
std::optional<facebook::react::Point> _offsetProp;
|
|
36
|
+
std::optional<facebook::react::Point> _pendingOffset;
|
|
37
|
+
BOOL _offsetQueued;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
+ (std::function<void(NSInteger, CGPoint)>)offsetChanged {
|
|
41
|
+
return gOffsetChanged;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
+ (void)setOffsetChanged:(std::function<void(NSInteger, CGPoint)>)offsetChanged {
|
|
45
|
+
gOffsetChanged = std::move(offsetChanged);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
- (instancetype)initWithShadowView:(const ShadowView &)view {
|
|
49
|
+
if ((self = [super initWithShadowView:view])) {
|
|
50
|
+
_scrollView = [[NGNWheelScrollView alloc] initWithFrame:NSZeroRect];
|
|
51
|
+
_scrollView.drawsBackground = NO;
|
|
52
|
+
_scrollView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
|
53
|
+
_scrollView.autohidesScrollers = YES;
|
|
54
|
+
// The user's "Show scroll bars" setting. A legacy scroller's strip is a gutter the content is
|
|
55
|
+
// laid out without (scrollers.h).
|
|
56
|
+
_scrollView.scrollerStyle = NSScroller.preferredScrollerStyle;
|
|
57
|
+
_showsVertical = YES;
|
|
58
|
+
_showsHorizontal = YES;
|
|
59
|
+
_document = [[NGNScrollDocumentView alloc] initWithFrame:NSZeroRect];
|
|
60
|
+
_scrollView.documentView = _document;
|
|
61
|
+
_scrollView.contentView.postsBoundsChangedNotifications = YES;
|
|
62
|
+
[NSNotificationCenter.defaultCenter addObserver:self
|
|
63
|
+
selector:@selector(boundsDidChange:)
|
|
64
|
+
name:NSViewBoundsDidChangeNotification
|
|
65
|
+
object:_scrollView.contentView];
|
|
66
|
+
[self addSubview:_scrollView];
|
|
67
|
+
__weak NGNScrollView *weakSelf = self;
|
|
68
|
+
_styleObserver = [[NGNScrollerStyleObserver alloc] initWithChanged:^{
|
|
69
|
+
[weakSelf updateScrollers];
|
|
70
|
+
}];
|
|
71
|
+
}
|
|
72
|
+
return self;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
- (void)dealloc {
|
|
76
|
+
[NSNotificationCenter.defaultCenter removeObserver:self];
|
|
77
|
+
ngn::ScrollerGutters::shared().remove(self.reactTag);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
- (NSView *)contentContainer {
|
|
81
|
+
return _document;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
- (void)updateProps:(const Props::Shared &)props {
|
|
85
|
+
[super updateProps:props];
|
|
86
|
+
auto p = std::dynamic_pointer_cast<const ScrollViewProps>(props);
|
|
87
|
+
if (!p) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
_showsVertical = p->showsVerticalScrollIndicator;
|
|
91
|
+
_showsHorizontal = p->showsHorizontalScrollIndicator;
|
|
92
|
+
[self updateScrollers];
|
|
93
|
+
_scrollView.verticalScrollElasticity = p->bounces ? NSScrollElasticityAutomatic : NSScrollElasticityNone;
|
|
94
|
+
_scrollView.horizontalScrollElasticity = _scrollView.verticalScrollElasticity;
|
|
95
|
+
// The inner scroll view takes the wheel before this view does.
|
|
96
|
+
_scrollView.scrollingDisabled = !p->scrollEnabled;
|
|
97
|
+
if (_offsetProp != p->contentOffset) {
|
|
98
|
+
bool first = !_offsetProp;
|
|
99
|
+
_offsetProp = p->contentOffset;
|
|
100
|
+
if (!first || p->contentOffset != facebook::react::Point{}) {
|
|
101
|
+
_pendingOffset = p->contentOffset;
|
|
102
|
+
}
|
|
103
|
+
[self applyPendingOffsetAfterMount];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// After the rest of this mount: its state and its layout, which come after the props in that
|
|
108
|
+
// order, give the content's size and the view's. Once, however many of them change.
|
|
109
|
+
- (void)applyPendingOffsetAfterMount {
|
|
110
|
+
if (!_pendingOffset || _offsetQueued) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
_offsetQueued = YES;
|
|
114
|
+
__weak NGNScrollView *weakSelf = self;
|
|
115
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
116
|
+
NGNScrollView *strong = weakSelf;
|
|
117
|
+
if (strong != nil) {
|
|
118
|
+
strong->_offsetQueued = NO;
|
|
119
|
+
[strong applyPendingOffset];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// The starting offset the props ask for, within the content, once there is content to scroll. The
|
|
125
|
+
// viewport is the clip view's, which a legacy scroller's gutter makes smaller than this view.
|
|
126
|
+
- (void)applyPendingOffset {
|
|
127
|
+
NSSize doc = _document.frame.size, view = _scrollView.contentView.bounds.size;
|
|
128
|
+
if (!_pendingOffset || doc.width <= 0 || doc.height <= 0 || view.width <= 0 || view.height <= 0) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
NSPoint target = NSMakePoint(std::clamp<CGFloat>(_pendingOffset->x, 0, std::max<CGFloat>(0, doc.width - view.width)),
|
|
132
|
+
std::clamp<CGFloat>(_pendingOffset->y, 0, std::max<CGFloat>(0, doc.height - view.height)));
|
|
133
|
+
_pendingOffset.reset();
|
|
134
|
+
NSClipView *clip = _scrollView.contentView;
|
|
135
|
+
[clip scrollToPoint:target];
|
|
136
|
+
[_scrollView reflectScrolledClipView:clip];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
- (void)updateLayout:(const LayoutMetrics &)metrics {
|
|
140
|
+
[super updateLayout:metrics];
|
|
141
|
+
_scrollView.frame = self.bounds;
|
|
142
|
+
[self updateScrollers];
|
|
143
|
+
[self applyPendingOffsetAfterMount];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
- (void)updateDesktopProps:(const ngn::DesktopProps &)props {
|
|
147
|
+
[super updateDesktopProps:props];
|
|
148
|
+
[self updateScrollers];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// The scrollers the core says show (scrollers.h), in the user's style; `thin` draws AppKit's small
|
|
152
|
+
// ones. When a legacy scroller's gutter changes, the content is laid out again without it.
|
|
153
|
+
- (void)updateScrollers {
|
|
154
|
+
const auto &desktop = self.desktopProps;
|
|
155
|
+
NSSize content = _document.frame.size, view = self.bounds.size;
|
|
156
|
+
auto visibility = ngn::scrollerVisibility(
|
|
157
|
+
desktop,
|
|
158
|
+
_showsVertical,
|
|
159
|
+
_showsHorizontal,
|
|
160
|
+
{static_cast<Float>(content.width), static_cast<Float>(content.height)},
|
|
161
|
+
{static_cast<Float>(view.width), static_cast<Float>(view.height)});
|
|
162
|
+
_scrollView.scrollerStyle = NSScroller.preferredScrollerStyle;
|
|
163
|
+
_scrollView.hasVerticalScroller = visibility.vertical;
|
|
164
|
+
_scrollView.hasHorizontalScroller = visibility.horizontal;
|
|
165
|
+
_scrollView.autohidesScrollers = visibility.autohides;
|
|
166
|
+
BOOL thin = desktop.scrollbarWidth == ngn::ScrollbarWidth::Thin;
|
|
167
|
+
NSControlSize size = thin ? NSControlSizeSmall : NSControlSizeRegular;
|
|
168
|
+
_scrollView.verticalScroller.controlSize = size;
|
|
169
|
+
_scrollView.horizontalScroller.controlSize = size;
|
|
170
|
+
auto gutter = ngn::scrollerGutter(NGNPreferredScrollerStyle(), NGNLegacyScrollerWidth(thin), visibility);
|
|
171
|
+
// Recorded only once there is a state to update, so a gutter is never recorded that no layout
|
|
172
|
+
// has asked for.
|
|
173
|
+
if (_scrollState && ngn::ScrollerGutters::shared().set(self.reactTag, gutter)) {
|
|
174
|
+
[self layOutAgain];
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// A state update clones the scroll view's node, which reads its gutter (scrollers.h).
|
|
179
|
+
- (void)layOutAgain {
|
|
180
|
+
auto concrete = std::dynamic_pointer_cast<const ConcreteState<ScrollViewState>>(_scrollState);
|
|
181
|
+
if (concrete) {
|
|
182
|
+
concrete->updateState(ScrollViewState(concrete->getData()));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
- (void)updateState:(const State::Shared &)state {
|
|
187
|
+
[super updateState:state];
|
|
188
|
+
_scrollState = state;
|
|
189
|
+
auto concrete = std::dynamic_pointer_cast<const ConcreteState<ScrollViewState>>(state);
|
|
190
|
+
if (!concrete) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
auto size = concrete->getData().getContentSize();
|
|
194
|
+
_applyingState = YES;
|
|
195
|
+
[_document setFrameSize:NSMakeSize(size.width, size.height)];
|
|
196
|
+
_applyingState = NO;
|
|
197
|
+
[self updateScrollers];
|
|
198
|
+
[self applyPendingOffsetAfterMount];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
- (void)scrollWheel:(NSEvent *)event {
|
|
202
|
+
auto p = std::dynamic_pointer_cast<const ScrollViewProps>(self.props);
|
|
203
|
+
if (p && !p->scrollEnabled) {
|
|
204
|
+
[self.nextResponder scrollWheel:event];
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
[_scrollView scrollWheel:event];
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
- (void)boundsDidChange:(NSNotification *)note {
|
|
211
|
+
NSPoint origin = _scrollView.contentView.bounds.origin;
|
|
212
|
+
if (gOffsetChanged) {
|
|
213
|
+
gOffsetChanged(self.reactTag, origin);
|
|
214
|
+
}
|
|
215
|
+
auto concrete = std::dynamic_pointer_cast<const ConcreteState<ScrollViewState>>(_scrollState);
|
|
216
|
+
if (concrete && !_applyingState) {
|
|
217
|
+
auto data = concrete->getData();
|
|
218
|
+
data.contentOffset = {static_cast<Float>(origin.x), static_cast<Float>(origin.y)};
|
|
219
|
+
concrete->updateState(std::move(data));
|
|
220
|
+
}
|
|
221
|
+
auto emitter = std::dynamic_pointer_cast<const ScrollViewEventEmitter>(self.eventEmitter);
|
|
222
|
+
if (emitter) {
|
|
223
|
+
ScrollEvent event;
|
|
224
|
+
event.contentOffset = {static_cast<Float>(origin.x), static_cast<Float>(origin.y)};
|
|
225
|
+
event.contentSize = {static_cast<Float>(_document.frame.size.width), static_cast<Float>(_document.frame.size.height)};
|
|
226
|
+
event.containerSize = {static_cast<Float>(self.bounds.size.width), static_cast<Float>(self.bounds.size.height)};
|
|
227
|
+
event.zoomScale = 1;
|
|
228
|
+
event.timestamp = NSProcessInfo.processInfo.systemUptime;
|
|
229
|
+
emitter->onScroll(event);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
- (void)handleCommand:(const std::string &)name args:(const folly::dynamic &)args {
|
|
234
|
+
NSClipView *clip = _scrollView.contentView;
|
|
235
|
+
NSPoint target = clip.bounds.origin;
|
|
236
|
+
if (name == "scrollTo" && args.isArray() && args.size() >= 2) {
|
|
237
|
+
target = NSMakePoint(args[0].asDouble(), args[1].asDouble());
|
|
238
|
+
} else if (name == "scrollToEnd") {
|
|
239
|
+
NSSize doc = _document.frame.size, view = clip.bounds.size;
|
|
240
|
+
target = NSMakePoint(std::max<CGFloat>(0, doc.width - view.width), std::max<CGFloat>(0, doc.height - view.height));
|
|
241
|
+
if (doc.height > view.height) {
|
|
242
|
+
target.x = clip.bounds.origin.x;
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
[clip scrollToPoint:target];
|
|
248
|
+
[_scrollView reflectScrolledClipView:clip];
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
@end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// The AppKit half of scrollers.h: the scroller style the user's "Show scroll bars" setting gives,
|
|
2
|
+
// how wide a legacy scroller is, and word when the setting changes.
|
|
3
|
+
#pragma once
|
|
4
|
+
|
|
5
|
+
#import <AppKit/AppKit.h>
|
|
6
|
+
|
|
7
|
+
#include "ngn/scrollers.h"
|
|
8
|
+
|
|
9
|
+
ngn::ScrollerStyle NGNPreferredScrollerStyle();
|
|
10
|
+
|
|
11
|
+
// The strip a legacy scroller takes: AppKit's regular one, or its small one for
|
|
12
|
+
// `scrollbar-width: thin`.
|
|
13
|
+
float NGNLegacyScrollerWidth(BOOL thin);
|
|
14
|
+
|
|
15
|
+
// Calls `changed` on the main thread each time the preferred scroller style changes, which the
|
|
16
|
+
// setting does, and in "Automatically" a mouse plugged in or out. Stops when released.
|
|
17
|
+
@interface NGNScrollerStyleObserver : NSObject
|
|
18
|
+
- (instancetype)initWithChanged:(void (^)(void))changed;
|
|
19
|
+
@end
|
|
20
|
+
|
|
21
|
+
// A scroll view's NSScrollView, which takes a wheel turn before the view holding it: with
|
|
22
|
+
// `scrollingDisabled` (`scrollEnabled={false}`) the turn goes past it, up the responder chain.
|
|
23
|
+
@interface NGNWheelScrollView : NSScrollView
|
|
24
|
+
@property (nonatomic) BOOL scrollingDisabled;
|
|
25
|
+
@end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#import "scrollers.h"
|
|
2
|
+
|
|
3
|
+
ngn::ScrollerStyle NGNPreferredScrollerStyle() {
|
|
4
|
+
return NSScroller.preferredScrollerStyle == NSScrollerStyleLegacy ? ngn::ScrollerStyle::Legacy
|
|
5
|
+
: ngn::ScrollerStyle::Overlay;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
float NGNLegacyScrollerWidth(BOOL thin) {
|
|
9
|
+
return static_cast<float>([NSScroller scrollerWidthForControlSize:thin ? NSControlSizeSmall : NSControlSizeRegular
|
|
10
|
+
scrollerStyle:NSScrollerStyleLegacy]);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@implementation NGNScrollerStyleObserver {
|
|
14
|
+
id<NSObject> _token;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
- (instancetype)initWithChanged:(void (^)(void))changed {
|
|
18
|
+
if ((self = [super init])) {
|
|
19
|
+
_token = [NSNotificationCenter.defaultCenter addObserverForName:NSPreferredScrollerStyleDidChangeNotification
|
|
20
|
+
object:nil
|
|
21
|
+
queue:NSOperationQueue.mainQueue
|
|
22
|
+
usingBlock:^(NSNotification *) {
|
|
23
|
+
changed();
|
|
24
|
+
}];
|
|
25
|
+
}
|
|
26
|
+
return self;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
- (void)dealloc {
|
|
30
|
+
[NSNotificationCenter.defaultCenter removeObserver:_token];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@end
|
|
34
|
+
|
|
35
|
+
@implementation NGNWheelScrollView
|
|
36
|
+
- (void)scrollWheel:(NSEvent *)event {
|
|
37
|
+
if (self.scrollingDisabled) {
|
|
38
|
+
[self.nextResponder scrollWheel:event];
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
[super scrollWheel:event];
|
|
42
|
+
}
|
|
43
|
+
@end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// `<search-field>` on macOS: an NSSearchField with `@ng-native/expo`'s iOS contract. The text is
|
|
2
|
+
// controlled from JavaScript and a text older than what has been typed since is skipped; Return
|
|
3
|
+
// submits, and the clear button and Escape cancel, emptying the field. No Fabric here, so it is
|
|
4
|
+
// tested on offscreen windows; native-controls.mm puts it in a Fabric view.
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#import <AppKit/AppKit.h>
|
|
8
|
+
|
|
9
|
+
#include "ngn/native-controls.h"
|
|
10
|
+
|
|
11
|
+
// The font the field draws its text in: the control size's system font, with the CSS's face, size,
|
|
12
|
+
// weight and slant over it. A name no face has is looked up as a family; one the system lacks
|
|
13
|
+
// keeps the system face.
|
|
14
|
+
NSFont *NGNSearchFieldFont(const ngn::NativeControlProps &props);
|
|
15
|
+
|
|
16
|
+
// How big AppKit draws the field at its control size, font and placeholder, measured with a private
|
|
17
|
+
// NSSearchFieldCell that no view holds. The control measurer calls it on the layout thread, as it
|
|
18
|
+
// measures its other controls' cells; AppKit's threading guide names NSCell main-thread-only.
|
|
19
|
+
NSSize NGNSearchFieldSize(const ngn::NativeControlProps &props);
|
|
20
|
+
|
|
21
|
+
@interface NGNSearchField : NSView
|
|
22
|
+
@property (nonatomic, readonly) NSSearchField *field;
|
|
23
|
+
// The text the user changed, with the count of changes so far.
|
|
24
|
+
@property (nonatomic, copy) void (^changed)(NSString *text, int eventCount);
|
|
25
|
+
// Return, with the text.
|
|
26
|
+
@property (nonatomic, copy) void (^submitted)(NSString *text);
|
|
27
|
+
// The clear button or Escape, after the field is emptied.
|
|
28
|
+
@property (nonatomic, copy) void (^cancelled)(void);
|
|
29
|
+
@property (nonatomic, copy) void (^began)(void);
|
|
30
|
+
@property (nonatomic, copy) void (^ended)(void);
|
|
31
|
+
- (void)apply:(const ngn::NativeControlProps &)props;
|
|
32
|
+
- (void)focus;
|
|
33
|
+
- (void)blur;
|
|
34
|
+
@end
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
#import "search-field.h"
|
|
2
|
+
|
|
3
|
+
#import "text-input-field.h"
|
|
4
|
+
|
|
5
|
+
using ngn::ControlSize;
|
|
6
|
+
using ngn::NativeControlProps;
|
|
7
|
+
|
|
8
|
+
namespace {
|
|
9
|
+
|
|
10
|
+
NSControlSize controlSize(ControlSize size) {
|
|
11
|
+
switch (size) {
|
|
12
|
+
case ControlSize::Mini:
|
|
13
|
+
return NSControlSizeMini;
|
|
14
|
+
case ControlSize::Small:
|
|
15
|
+
return NSControlSizeSmall;
|
|
16
|
+
case ControlSize::Large:
|
|
17
|
+
return NSControlSizeLarge;
|
|
18
|
+
case ControlSize::Regular:
|
|
19
|
+
return NSControlSizeRegular;
|
|
20
|
+
}
|
|
21
|
+
return NSControlSizeRegular;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
NSString *string(const std::string &s) {
|
|
25
|
+
NSString *out = [NSString stringWithUTF8String:s.c_str()];
|
|
26
|
+
return out != nil ? out : @"";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// A CSS weight as AppKit's nearest, as the iOS field maps it to UIKit's.
|
|
30
|
+
NSFontWeight fontWeight(int css) {
|
|
31
|
+
static const NSFontWeight weights[] = {
|
|
32
|
+
NSFontWeightUltraLight,
|
|
33
|
+
NSFontWeightThin,
|
|
34
|
+
NSFontWeightLight,
|
|
35
|
+
NSFontWeightRegular,
|
|
36
|
+
NSFontWeightMedium,
|
|
37
|
+
NSFontWeightSemibold,
|
|
38
|
+
NSFontWeightBold,
|
|
39
|
+
NSFontWeightHeavy,
|
|
40
|
+
NSFontWeightBlack};
|
|
41
|
+
long index = std::lround(css / 100.0) - 1;
|
|
42
|
+
return weights[std::clamp<long>(index, 0, 8)];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
ngn::TextInputOptions inputOptions(const NativeControlProps &p) {
|
|
46
|
+
ngn::TextInputOptions options{.capitalize = ngn::Capitalize::None};
|
|
47
|
+
if (p.autoCapitalize == "words") {
|
|
48
|
+
options.capitalize = ngn::Capitalize::Words;
|
|
49
|
+
} else if (p.autoCapitalize == "sentences") {
|
|
50
|
+
options.capitalize = ngn::Capitalize::Sentences;
|
|
51
|
+
} else if (p.autoCapitalize == "characters") {
|
|
52
|
+
options.capitalize = ngn::Capitalize::Characters;
|
|
53
|
+
}
|
|
54
|
+
return options;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
} // namespace
|
|
58
|
+
|
|
59
|
+
NSFont *NGNSearchFieldFont(const NativeControlProps &p) {
|
|
60
|
+
CGFloat base = [NSFont systemFontSizeForControlSize:controlSize(p.controlSize)];
|
|
61
|
+
CGFloat size = p.fontSize ? static_cast<CGFloat>(*p.fontSize) : base;
|
|
62
|
+
NSFont *font = p.fontWeight ? [NSFont systemFontOfSize:size weight:fontWeight(*p.fontWeight)] : [NSFont systemFontOfSize:size];
|
|
63
|
+
if (!p.fontFamily.empty()) {
|
|
64
|
+
NSString *family = string(p.fontFamily);
|
|
65
|
+
NSFont *named = [NSFont fontWithName:family size:size];
|
|
66
|
+
NSString *familyName = named ? named.familyName : ([NSFontManager.sharedFontManager availableMembersOfFontFamily:family] ? family : nil);
|
|
67
|
+
if (familyName && p.fontWeight) {
|
|
68
|
+
NSFontDescriptor *descriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:@{
|
|
69
|
+
NSFontFamilyAttribute : familyName,
|
|
70
|
+
NSFontTraitsAttribute : @{NSFontWeightTrait : @(fontWeight(*p.fontWeight))},
|
|
71
|
+
}];
|
|
72
|
+
NSFont *weighted = [NSFont fontWithDescriptor:descriptor size:size];
|
|
73
|
+
font = weighted ? weighted : font;
|
|
74
|
+
} else if (named) {
|
|
75
|
+
font = named;
|
|
76
|
+
} else if (familyName) {
|
|
77
|
+
NSFontDescriptor *descriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:@{NSFontFamilyAttribute : familyName}];
|
|
78
|
+
NSFont *found = [NSFont fontWithDescriptor:descriptor size:size];
|
|
79
|
+
font = found ? found : font;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (p.italic) {
|
|
83
|
+
font = [NSFontManager.sharedFontManager convertFont:font toHaveTrait:NSItalicFontMask];
|
|
84
|
+
}
|
|
85
|
+
return font;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
NSSize NGNSearchFieldSize(const NativeControlProps &p) {
|
|
89
|
+
@autoreleasepool {
|
|
90
|
+
NSSearchFieldCell *cell = [[NSSearchFieldCell alloc] initTextCell:string(p.text)];
|
|
91
|
+
cell.controlSize = controlSize(p.controlSize);
|
|
92
|
+
cell.font = NGNSearchFieldFont(p);
|
|
93
|
+
cell.placeholderString = string(p.placeholder);
|
|
94
|
+
cell.bezeled = YES;
|
|
95
|
+
cell.editable = YES;
|
|
96
|
+
NSSize size = cell.cellSize;
|
|
97
|
+
// The cell keeps its control size's height whatever the font, so a larger face gets the
|
|
98
|
+
// padding the control size's own font has around it.
|
|
99
|
+
NSFont *system = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:cell.controlSize]];
|
|
100
|
+
auto lineHeight = [](NSFont *font) { return std::ceil(font.ascender - font.descender + font.leading); };
|
|
101
|
+
CGFloat padding = size.height - lineHeight(system);
|
|
102
|
+
CGFloat height = std::max<CGFloat>(size.height, lineHeight(cell.font) + padding);
|
|
103
|
+
return NSMakeSize(std::ceil(size.width), std::ceil(height));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@interface NGNSearchField () <NSSearchFieldDelegate>
|
|
108
|
+
- (const ngn::TextInputOptions &)options;
|
|
109
|
+
- (void)fieldDidBecomeFirstResponder;
|
|
110
|
+
@end
|
|
111
|
+
|
|
112
|
+
// The field itself: it tells its box when it takes the keyboard, and keeps the shared field editor
|
|
113
|
+
// to its capitalization.
|
|
114
|
+
@interface NGNSearchControl : NSSearchField
|
|
115
|
+
@property (nonatomic, weak) NGNSearchField *box;
|
|
116
|
+
@end
|
|
117
|
+
|
|
118
|
+
@implementation NGNSearchControl {
|
|
119
|
+
BOOL _inserting;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
- (BOOL)becomeFirstResponder {
|
|
123
|
+
if (![super becomeFirstResponder]) {
|
|
124
|
+
return NO;
|
|
125
|
+
}
|
|
126
|
+
[self.box fieldDidBecomeFirstResponder];
|
|
127
|
+
return YES;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
- (BOOL)textView:(NSTextView *)textView shouldChangeTextInRange:(NSRange)range replacementString:(NSString *)string {
|
|
131
|
+
static const ngn::TextInputOptions none{};
|
|
132
|
+
return NGNControlShouldChangeText(
|
|
133
|
+
self, NSSearchField.class, textView, range, string, self.box ? self.box.options : none, &_inserting);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
- (NSDictionary<NSTextCheckingOptionKey, id> *)textView:(NSTextView *)view
|
|
137
|
+
willCheckTextInRange:(NSRange)range
|
|
138
|
+
options:(NSDictionary<NSTextCheckingOptionKey, id> *)options
|
|
139
|
+
types:(NSTextCheckingTypes *)checkingTypes {
|
|
140
|
+
return self.box ? NGNTextCheckingOptions(options, self.box.options) : options;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@end
|
|
144
|
+
|
|
145
|
+
@implementation NGNSearchField {
|
|
146
|
+
ngn::TextInputOptions _options;
|
|
147
|
+
NSColor *_tint;
|
|
148
|
+
int _eventCount;
|
|
149
|
+
CGFloat _height;
|
|
150
|
+
// Counts the editing ends: only the latest one's turn-later check may report a blur.
|
|
151
|
+
NSUInteger _endings;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
- (instancetype)initWithFrame:(NSRect)frame {
|
|
155
|
+
if ((self = [super initWithFrame:frame])) {
|
|
156
|
+
NGNSearchControl *field = [[NGNSearchControl alloc] initWithFrame:self.bounds];
|
|
157
|
+
field.box = self;
|
|
158
|
+
field.delegate = self;
|
|
159
|
+
field.sendsWholeSearchString = YES;
|
|
160
|
+
_field = field;
|
|
161
|
+
[self addSubview:field];
|
|
162
|
+
[self takeCancelButton];
|
|
163
|
+
}
|
|
164
|
+
return self;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
- (const ngn::TextInputOptions &)options {
|
|
168
|
+
return _options;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// The clear button empties the field through `cancel`, so JavaScript hears the text and the cancel.
|
|
172
|
+
- (void)takeCancelButton {
|
|
173
|
+
NSButtonCell *cancel = ((NSSearchFieldCell *)_field.cell).cancelButtonCell;
|
|
174
|
+
cancel.target = self;
|
|
175
|
+
cancel.action = @selector(cancel);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
- (void)apply:(const NativeControlProps &)p {
|
|
179
|
+
_field.controlSize = controlSize(p.controlSize);
|
|
180
|
+
_field.font = NGNSearchFieldFont(p);
|
|
181
|
+
NSString *placeholder = string(p.placeholder);
|
|
182
|
+
if (![_field.placeholderString isEqualToString:placeholder]) {
|
|
183
|
+
_field.placeholderString = placeholder;
|
|
184
|
+
}
|
|
185
|
+
_options = inputOptions(p);
|
|
186
|
+
if (p.tintColor) {
|
|
187
|
+
auto c = facebook::react::colorComponentsFromColor(p.tintColor);
|
|
188
|
+
_tint = [NSColor colorWithSRGBRed:c.red green:c.green blue:c.blue alpha:c.alpha];
|
|
189
|
+
} else {
|
|
190
|
+
_tint = nil;
|
|
191
|
+
}
|
|
192
|
+
[self applyTint];
|
|
193
|
+
if (!p.enabled) {
|
|
194
|
+
[self blur]; // before AppKit ends the editing silently
|
|
195
|
+
}
|
|
196
|
+
_field.enabled = p.enabled;
|
|
197
|
+
NSString *text = string(p.text);
|
|
198
|
+
NSText *editor = _field.currentEditor;
|
|
199
|
+
BOOL composing = [editor isKindOfClass:NSTextView.class] && [(NSTextView *)editor hasMarkedText];
|
|
200
|
+
if (ngn::controlledTextIsCurrent(p.mostRecentEventCount, _eventCount, composing) && ![_field.stringValue isEqualToString:text]) {
|
|
201
|
+
_field.stringValue = text;
|
|
202
|
+
}
|
|
203
|
+
[self takeCancelButton];
|
|
204
|
+
_height = NGNSearchFieldSize(p).height;
|
|
205
|
+
[self layoutField];
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
- (void)applyTint {
|
|
209
|
+
if ([_field.currentEditor isKindOfClass:NSTextView.class]) {
|
|
210
|
+
((NSTextView *)_field.currentEditor).insertionPointColor = _tint ? _tint : NSColor.textColor;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
- (void)layoutField {
|
|
215
|
+
// Its own height at its control size and font, centred in the box Yoga gives it.
|
|
216
|
+
CGFloat own = _height > 0 ? _height : _field.intrinsicContentSize.height;
|
|
217
|
+
CGFloat height = std::min<CGFloat>(NSHeight(self.bounds), own);
|
|
218
|
+
_field.frame = NSMakeRect(0, std::round((NSHeight(self.bounds) - height) / 2), NSWidth(self.bounds), height);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
- (void)setFrameSize:(NSSize)size {
|
|
222
|
+
[super setFrameSize:size];
|
|
223
|
+
[self layoutField];
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
- (void)focus {
|
|
227
|
+
[self.window makeFirstResponder:_field];
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
- (void)blur {
|
|
231
|
+
if (_field.currentEditor) {
|
|
232
|
+
[self.window makeFirstResponder:nil];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
- (void)fieldDidBecomeFirstResponder {
|
|
237
|
+
[self applyTint];
|
|
238
|
+
if (self.began) {
|
|
239
|
+
self.began();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
- (void)cancel {
|
|
244
|
+
if (_field.stringValue.length > 0) {
|
|
245
|
+
_field.stringValue = @"";
|
|
246
|
+
[self changedTo:@""];
|
|
247
|
+
}
|
|
248
|
+
if (self.cancelled) {
|
|
249
|
+
self.cancelled();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
- (void)changedTo:(NSString *)text {
|
|
254
|
+
_eventCount++;
|
|
255
|
+
if (self.changed) {
|
|
256
|
+
self.changed(text, _eventCount);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
- (void)controlTextDidChange:(NSNotification *)note {
|
|
261
|
+
[self changedTo:_field.stringValue];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// A turn later, and only when the field no longer edits: a click into the field ends its editing
|
|
265
|
+
// and starts it again at the click's point, which is no blur.
|
|
266
|
+
- (void)controlTextDidEndEditing:(NSNotification *)note {
|
|
267
|
+
__weak NGNSearchField *weakSelf = self;
|
|
268
|
+
NSUInteger ending = ++_endings;
|
|
269
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
270
|
+
NGNSearchField *strongSelf = weakSelf;
|
|
271
|
+
if (strongSelf != nil && strongSelf->_endings == ending && strongSelf.field.currentEditor == nil && strongSelf.ended) {
|
|
272
|
+
strongSelf.ended();
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)selector {
|
|
278
|
+
if (selector == @selector(insertNewline:)) {
|
|
279
|
+
if (self.submitted) {
|
|
280
|
+
self.submitted(_field.stringValue);
|
|
281
|
+
}
|
|
282
|
+
return YES;
|
|
283
|
+
}
|
|
284
|
+
if (selector == @selector(cancelOperation:)) {
|
|
285
|
+
[self cancel];
|
|
286
|
+
return YES;
|
|
287
|
+
}
|
|
288
|
+
return NO;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
@end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// `<native-search-bar>` on macOS: react-native-screens' RNSSearchBar as the window's
|
|
2
|
+
// NSSearchToolbarItem, trailing the toolbar as Finder's and Mail's search does. It reports what the
|
|
3
|
+
// user does as the core's SearchBarInput (header-bar.h) and takes RNSSearchBar's commands. No
|
|
4
|
+
// Fabric here, so it is tested on offscreen windows; header-toolbar.mm puts it in the toolbar.
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#import <AppKit/AppKit.h>
|
|
8
|
+
|
|
9
|
+
#include "ngn/header-bar.h"
|
|
10
|
+
|
|
11
|
+
@interface NGNSearchToolbarItem : NSSearchToolbarItem
|
|
12
|
+
// What the user did, with the field's text after it.
|
|
13
|
+
@property (nonatomic, copy) void (^input)(ngn::SearchBarInput input, NSString *text);
|
|
14
|
+
- (void)apply:(const ngn::SearchBarConfig &)config;
|
|
15
|
+
- (void)run:(const ngn::SearchBarCommand &)command;
|
|
16
|
+
// Runs `change`, which may take the item out of its toolbar and put it back, and gives the field
|
|
17
|
+
// the keyboard and selection again if it was editing, with no blur or focus reported.
|
|
18
|
+
- (void)keepFocusAcross:(void (^)(void))change;
|
|
19
|
+
@end
|