@ng-native/desktop 0.0.0 → 0.24.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 +277 -0
- package/native/appkit/CMakeLists.txt +130 -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-sheet.h +59 -0
- package/native/appkit/camera-sheet.mm +344 -0
- package/native/appkit/camera-view.h +15 -0
- package/native/appkit/camera-view.mm +134 -0
- package/native/appkit/camera.h +61 -0
- package/native/appkit/camera.mm +496 -0
- package/native/appkit/cg-canvas.h +24 -0
- package/native/appkit/cg-canvas.mm +663 -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 +632 -0
- package/native/appkit/host-view.h +54 -0
- package/native/appkit/host-view.mm +1228 -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 +1475 -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 +562 -0
- package/native/appkit/svg-view.h +18 -0
- package/native/appkit/svg-view.mm +103 -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/tab-walk.h +31 -0
- package/native/appkit/tab-walk.mm +64 -0
- package/native/appkit/test-launch.h +36 -0
- package/native/appkit/test-launch.mm +115 -0
- package/native/appkit/text-input-field.h +81 -0
- package/native/appkit/text-input-field.mm +525 -0
- package/native/appkit/text-layout.h +58 -0
- package/native/appkit/text-layout.mm +485 -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 +10 -0
- package/native/appkit/web-view-component.mm +62 -0
- package/native/appkit/web-view.h +31 -0
- package/native/appkit/web-view.mm +401 -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 +151 -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 +121 -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 +222 -0
- package/native/core/include/ngn/control-sizes.h +111 -0
- package/native/core/include/ngn/core-modules.h +108 -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/dom-web-view.h +53 -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 +134 -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 +163 -0
- package/native/core/include/ngn/safe-areas.h +82 -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/surface-metrics.h +51 -0
- package/native/core/include/ngn/svg.h +434 -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 +134 -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 +137 -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 +359 -0
- package/native/core/src/app-windows.cpp +444 -0
- package/native/core/src/back-swipe.cpp +98 -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/dom-web-view.cpp +45 -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 +358 -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 +412 -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 +401 -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 +385 -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 +384 -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 +420 -0
- package/native/core/src/safe-areas.cpp +137 -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 +2190 -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 +139 -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 +175 -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/launch-probe.sh +60 -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,1228 @@
|
|
|
1
|
+
#import "host-view.h"
|
|
2
|
+
|
|
3
|
+
#include "ngn/view-transform.h"
|
|
4
|
+
|
|
5
|
+
#import <QuartzCore/QuartzCore.h>
|
|
6
|
+
|
|
7
|
+
#import "cg-canvas.h"
|
|
8
|
+
#import "header-toolbar.h"
|
|
9
|
+
#import "image-view.h"
|
|
10
|
+
#import "modal-host-view.h"
|
|
11
|
+
#import "native-controls.h"
|
|
12
|
+
#import "presented-screen.h"
|
|
13
|
+
#import "scroll-view.h"
|
|
14
|
+
#import "split-view.h"
|
|
15
|
+
#import "svg-view.h"
|
|
16
|
+
#import "symbol-view.h"
|
|
17
|
+
#import "glass-view.h"
|
|
18
|
+
|
|
19
|
+
#include "ngn/dom-web-view.h"
|
|
20
|
+
#include "ngn/glass.h"
|
|
21
|
+
#import "web-view-component.h"
|
|
22
|
+
#import "expo-image-view.h"
|
|
23
|
+
#import "expo-ui-view.h"
|
|
24
|
+
#import "camera-view.h"
|
|
25
|
+
#import "video-view.h"
|
|
26
|
+
#import "apple-button-view.h"
|
|
27
|
+
#import "map-view.h"
|
|
28
|
+
#import "text-input-field.h"
|
|
29
|
+
|
|
30
|
+
#include "text-layout.h"
|
|
31
|
+
|
|
32
|
+
#include "ngn/accessibility.h"
|
|
33
|
+
#include "ngn/symbol.h"
|
|
34
|
+
#include "ngn/view-box.h"
|
|
35
|
+
|
|
36
|
+
#include "ngn/text-input.h"
|
|
37
|
+
#include <react/renderer/components/text/ParagraphState.h>
|
|
38
|
+
#include <react/renderer/components/textinput/TextInputEventEmitter.h>
|
|
39
|
+
#include <react/renderer/components/view/ViewEventEmitter.h>
|
|
40
|
+
#include <react/renderer/components/view/ViewProps.h>
|
|
41
|
+
#include <react/renderer/core/ConcreteState.h>
|
|
42
|
+
|
|
43
|
+
using namespace facebook::react;
|
|
44
|
+
|
|
45
|
+
namespace {
|
|
46
|
+
|
|
47
|
+
NSColor *nsColor(const SharedColor &color) {
|
|
48
|
+
if (!color) {
|
|
49
|
+
return nil;
|
|
50
|
+
}
|
|
51
|
+
auto c = colorComponentsFromColor(color);
|
|
52
|
+
return [NSColor colorWithSRGBRed:c.red green:c.green blue:c.blue alpha:c.alpha];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
CGColorRef cgColor(uint32_t argb) {
|
|
56
|
+
return [NSColor colorWithSRGBRed:((argb >> 16) & 0xff) / 255.0
|
|
57
|
+
green:((argb >> 8) & 0xff) / 255.0
|
|
58
|
+
blue:(argb & 0xff) / 255.0
|
|
59
|
+
alpha:(argb >> 24) / 255.0]
|
|
60
|
+
.CGColor;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// A mask layer over `bounds` showing `path`.
|
|
64
|
+
CAShapeLayer *shapeLayer(const ngn::SvgPath &path, BOOL evenOdd, NSRect bounds) {
|
|
65
|
+
CAShapeLayer *mask = [CAShapeLayer layer];
|
|
66
|
+
mask.frame = bounds;
|
|
67
|
+
CGPathRef p = NGNCreatePath(path);
|
|
68
|
+
mask.path = p;
|
|
69
|
+
CGPathRelease(p);
|
|
70
|
+
mask.fillRule = evenOdd ? kCAFillRuleEvenOdd : kCAFillRuleNonZero;
|
|
71
|
+
return mask;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
NSString *nsString(const std::string &s) {
|
|
75
|
+
NSString *result = [NSString stringWithUTF8String:s.c_str()];
|
|
76
|
+
return result != nil ? result : @"";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
NSAccessibilityRole nsRole(ngn::AxRole role) {
|
|
80
|
+
switch (role) {
|
|
81
|
+
case ngn::AxRole::Group:
|
|
82
|
+
return NSAccessibilityGroupRole;
|
|
83
|
+
case ngn::AxRole::Button:
|
|
84
|
+
return NSAccessibilityButtonRole;
|
|
85
|
+
case ngn::AxRole::Link:
|
|
86
|
+
return NSAccessibilityLinkRole;
|
|
87
|
+
case ngn::AxRole::Image:
|
|
88
|
+
return NSAccessibilityImageRole;
|
|
89
|
+
case ngn::AxRole::StaticText:
|
|
90
|
+
return NSAccessibilityStaticTextRole;
|
|
91
|
+
case ngn::AxRole::CheckBox:
|
|
92
|
+
return NSAccessibilityCheckBoxRole;
|
|
93
|
+
case ngn::AxRole::RadioButton:
|
|
94
|
+
return NSAccessibilityRadioButtonRole;
|
|
95
|
+
case ngn::AxRole::RadioGroup:
|
|
96
|
+
return NSAccessibilityRadioGroupRole;
|
|
97
|
+
case ngn::AxRole::Slider:
|
|
98
|
+
return NSAccessibilitySliderRole;
|
|
99
|
+
case ngn::AxRole::TextField:
|
|
100
|
+
return NSAccessibilityTextFieldRole;
|
|
101
|
+
case ngn::AxRole::List:
|
|
102
|
+
return NSAccessibilityListRole;
|
|
103
|
+
case ngn::AxRole::Menu:
|
|
104
|
+
return NSAccessibilityMenuRole;
|
|
105
|
+
case ngn::AxRole::MenuItem:
|
|
106
|
+
return NSAccessibilityMenuItemRole;
|
|
107
|
+
case ngn::AxRole::MenuBar:
|
|
108
|
+
return NSAccessibilityMenuBarRole;
|
|
109
|
+
case ngn::AxRole::ProgressIndicator:
|
|
110
|
+
return NSAccessibilityProgressIndicatorRole;
|
|
111
|
+
case ngn::AxRole::ComboBox:
|
|
112
|
+
return NSAccessibilityComboBoxRole;
|
|
113
|
+
case ngn::AxRole::TabGroup:
|
|
114
|
+
return NSAccessibilityTabGroupRole;
|
|
115
|
+
case ngn::AxRole::Toolbar:
|
|
116
|
+
return NSAccessibilityToolbarRole;
|
|
117
|
+
case ngn::AxRole::ScrollBar:
|
|
118
|
+
return NSAccessibilityScrollBarRole;
|
|
119
|
+
case ngn::AxRole::Table:
|
|
120
|
+
return NSAccessibilityTableRole;
|
|
121
|
+
case ngn::AxRole::Row:
|
|
122
|
+
return NSAccessibilityRowRole;
|
|
123
|
+
case ngn::AxRole::Cell:
|
|
124
|
+
return NSAccessibilityCellRole;
|
|
125
|
+
case ngn::AxRole::Incrementor:
|
|
126
|
+
return NSAccessibilityIncrementorRole;
|
|
127
|
+
case ngn::AxRole::Heading:
|
|
128
|
+
if (@available(macOS 26, *)) {
|
|
129
|
+
return NSAccessibilityHeadingRole;
|
|
130
|
+
}
|
|
131
|
+
return NSAccessibilityGroupRole;
|
|
132
|
+
case ngn::AxRole::LevelIndicator:
|
|
133
|
+
return NSAccessibilityLevelIndicatorRole;
|
|
134
|
+
case ngn::AxRole::Outline:
|
|
135
|
+
return NSAccessibilityOutlineRole;
|
|
136
|
+
case ngn::AxRole::ScrollArea:
|
|
137
|
+
return NSAccessibilityScrollAreaRole;
|
|
138
|
+
}
|
|
139
|
+
return NSAccessibilityGroupRole;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Whether AppKit has a role of its own for this one, so its own name for it is spoken.
|
|
143
|
+
bool nativeRole(ngn::AxRole role) {
|
|
144
|
+
if (role == ngn::AxRole::Heading) {
|
|
145
|
+
if (@available(macOS 26, *)) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
NSAccessibilitySubrole nsSubrole(ngn::AxSubrole subrole) {
|
|
154
|
+
switch (subrole) {
|
|
155
|
+
case ngn::AxSubrole::Switch:
|
|
156
|
+
return NSAccessibilitySwitchSubrole;
|
|
157
|
+
case ngn::AxSubrole::Toggle:
|
|
158
|
+
return NSAccessibilityToggleSubrole;
|
|
159
|
+
case ngn::AxSubrole::Tab:
|
|
160
|
+
return NSAccessibilityTabButtonSubrole;
|
|
161
|
+
case ngn::AxSubrole::SearchField:
|
|
162
|
+
return NSAccessibilitySearchFieldSubrole;
|
|
163
|
+
case ngn::AxSubrole::OutlineRow:
|
|
164
|
+
return NSAccessibilityOutlineRowSubrole;
|
|
165
|
+
case ngn::AxSubrole::None:
|
|
166
|
+
return nil;
|
|
167
|
+
}
|
|
168
|
+
return nil;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
} // namespace
|
|
172
|
+
|
|
173
|
+
#pragma mark - NGNView
|
|
174
|
+
|
|
175
|
+
static ngn::InputDispatcher *gViewInput;
|
|
176
|
+
|
|
177
|
+
// A view's backing layer, holding the transform from its props. AppKit puts a layer-backed view's
|
|
178
|
+
// own geometry back on its layer as it lays out and displays the window, which sets the transform
|
|
179
|
+
// back to the identity (the view has no rotation of its own); this layer keeps the view's.
|
|
180
|
+
@interface NGNViewLayer : CALayer
|
|
181
|
+
@property (nonatomic) CATransform3D viewTransform;
|
|
182
|
+
@end
|
|
183
|
+
|
|
184
|
+
@implementation NGNViewLayer
|
|
185
|
+
|
|
186
|
+
- (instancetype)init {
|
|
187
|
+
if ((self = [super init])) {
|
|
188
|
+
_viewTransform = CATransform3DIdentity;
|
|
189
|
+
}
|
|
190
|
+
return self;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
- (void)setTransform:(CATransform3D)transform {
|
|
194
|
+
[super setTransform:_viewTransform];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
- (void)setViewTransform:(CATransform3D)transform {
|
|
198
|
+
_viewTransform = transform;
|
|
199
|
+
[super setTransform:transform];
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
@end
|
|
203
|
+
|
|
204
|
+
@implementation NGNView {
|
|
205
|
+
Props::Shared _props;
|
|
206
|
+
LayoutMetrics _layout;
|
|
207
|
+
State::Shared _state;
|
|
208
|
+
EventEmitter::Shared _emitter;
|
|
209
|
+
ngn::DesktopProps _desktop;
|
|
210
|
+
BOOL _focusVisible;
|
|
211
|
+
// drawRect draws the box (ngn/view-box.h), which the layer does not.
|
|
212
|
+
BOOL _boxDrawn;
|
|
213
|
+
NSMutableArray<CALayer *> *_shadowLayers;
|
|
214
|
+
// The transform from the props, as NGNViewLayer holds it.
|
|
215
|
+
CATransform3D _transform;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
- (instancetype)initWithShadowView:(const ShadowView &)view {
|
|
219
|
+
if ((self = [super initWithFrame:NSZeroRect])) {
|
|
220
|
+
_transform = CATransform3DIdentity;
|
|
221
|
+
_swipeOpacity = 1;
|
|
222
|
+
_reactTag = view.tag;
|
|
223
|
+
_surfaceId = view.surfaceId;
|
|
224
|
+
_componentName = [NSString stringWithUTF8String:view.componentName];
|
|
225
|
+
self.wantsLayer = YES;
|
|
226
|
+
self.layerContentsRedrawPolicy = NSViewLayerContentsRedrawOnSetNeedsDisplay;
|
|
227
|
+
}
|
|
228
|
+
return self;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
+ (ngn::InputDispatcher *)activator {
|
|
232
|
+
return gViewInput;
|
|
233
|
+
}
|
|
234
|
+
+ (void)setActivator:(ngn::InputDispatcher *)input {
|
|
235
|
+
gViewInput = input;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
- (BOOL)isFlipped {
|
|
239
|
+
return YES;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
- (CALayer *)makeBackingLayer {
|
|
243
|
+
NGNViewLayer *layer = [NGNViewLayer layer];
|
|
244
|
+
layer.contentsScale = self.window ? self.window.backingScaleFactor : NSScreen.mainScreen.backingScaleFactor;
|
|
245
|
+
return layer;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// A layer of the view's own making draws its contents at the scale it is given, not the screen's.
|
|
249
|
+
- (void)viewDidChangeBackingProperties {
|
|
250
|
+
[super viewDidChangeBackingProperties];
|
|
251
|
+
if (self.window) {
|
|
252
|
+
self.layer.contentsScale = self.window.backingScaleFactor;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// AppKit's hit test goes by the frame and ignores the layer's transform. A transformed view is
|
|
257
|
+
// hit where its layer draws it, as the core's hit test finds it (ViewTree::pointIn): `point` (in
|
|
258
|
+
// the superview's coordinates) goes back through the transform, about the frame's corner, before
|
|
259
|
+
// AppKit tests the frame and the subviews.
|
|
260
|
+
- (NSView *)hitTest:(NSPoint)point {
|
|
261
|
+
CATransform3D t = _transform;
|
|
262
|
+
if (CATransform3DIsIdentity(t)) {
|
|
263
|
+
return [super hitTest:point];
|
|
264
|
+
}
|
|
265
|
+
const CGFloat columns[16] = {
|
|
266
|
+
t.m11, t.m12, t.m13, t.m14, t.m21, t.m22, t.m23, t.m24, t.m31, t.m32, t.m33, t.m34, t.m41, t.m42, t.m43, t.m44};
|
|
267
|
+
Transform matrix;
|
|
268
|
+
for (size_t i = 0; i < 16; ++i) {
|
|
269
|
+
matrix.matrix[i] = static_cast<Float>(columns[i]);
|
|
270
|
+
}
|
|
271
|
+
NSPoint origin = self.frame.origin;
|
|
272
|
+
auto local = ngn::layerPointAt(matrix, {static_cast<Float>(point.x - origin.x), static_cast<Float>(point.y - origin.y)});
|
|
273
|
+
if (!local) {
|
|
274
|
+
return nil;
|
|
275
|
+
}
|
|
276
|
+
return [super hitTest:NSMakePoint(origin.x + local->x, origin.y + local->y)];
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Any tabIndex takes the focus, -1 too, as on the web: out of Tab order, but where a click or the
|
|
280
|
+
// arrow keys in a composite widget move it (focus-order.h).
|
|
281
|
+
- (BOOL)acceptsFirstResponder {
|
|
282
|
+
return _desktop.focusable.value_or(false) || _desktop.tabIndex.has_value();
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
// Whether the event AppKit is handling is a key's: a focus a key moved draws a ring and matches
|
|
287
|
+
// `:focus-visible`, which the engine learns from `focusVisible` on the focus event.
|
|
288
|
+
static BOOL focusFromKeyboard() {
|
|
289
|
+
NSEventType type = NSApp.currentEvent.type;
|
|
290
|
+
return type == NSEventTypeKeyDown || type == NSEventTypeKeyUp;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
- (BOOL)becomeFirstResponder {
|
|
294
|
+
if (![super becomeFirstResponder]) {
|
|
295
|
+
return NO;
|
|
296
|
+
}
|
|
297
|
+
_focusVisible = focusFromKeyboard();
|
|
298
|
+
self.focusRingType = _focusVisible ? NSFocusRingTypeDefault : NSFocusRingTypeNone;
|
|
299
|
+
[self noteFocusRingMaskChanged];
|
|
300
|
+
if (_emitter) {
|
|
301
|
+
_emitter->dispatchEvent("focus", folly::dynamic::object("target", (int)_reactTag)("focusVisible", (bool)_focusVisible));
|
|
302
|
+
}
|
|
303
|
+
return YES;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
- (BOOL)resignFirstResponder {
|
|
307
|
+
if (![super resignFirstResponder]) {
|
|
308
|
+
return NO;
|
|
309
|
+
}
|
|
310
|
+
_focusVisible = NO;
|
|
311
|
+
[self noteFocusRingMaskChanged];
|
|
312
|
+
if (_emitter) {
|
|
313
|
+
_emitter->dispatchEvent("blur", folly::dynamic::object("target", (int)_reactTag));
|
|
314
|
+
}
|
|
315
|
+
return YES;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// AppKit's focus ring, in the view's shape, while the focus came from the keyboard. An app that
|
|
319
|
+
// styles `outline` draws its own.
|
|
320
|
+
- (void)drawFocusRingMask {
|
|
321
|
+
auto viewProps = std::dynamic_pointer_cast<const ViewProps>(_props);
|
|
322
|
+
CGFloat radius = viewProps ? viewProps->resolveBorderMetrics(_layout).borderRadii.topLeft.horizontal : 0;
|
|
323
|
+
[[NSBezierPath bezierPathWithRoundedRect:self.bounds xRadius:radius yRadius:radius] fill];
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
- (NSRect)focusRingMaskBounds {
|
|
327
|
+
auto viewProps = std::dynamic_pointer_cast<const ViewProps>(_props);
|
|
328
|
+
BOOL ownOutline = viewProps && (viewProps->outlineWidth > 0 || viewProps->outlineColor);
|
|
329
|
+
return _focusVisible && !ownOutline ? self.bounds : NSZeroRect;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
- (EventEmitter::Shared)eventEmitter {
|
|
333
|
+
return _emitter;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
- (Props::Shared)props {
|
|
337
|
+
return _props;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
- (State::Shared)state {
|
|
341
|
+
return _state;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
- (const LayoutMetrics &)layoutMetrics {
|
|
345
|
+
return _layout;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
- (const ngn::DesktopProps &)desktopProps {
|
|
349
|
+
return _desktop;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
- (NSView *)contentContainer {
|
|
353
|
+
return self;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
- (NSResponder *)keyboardResponder {
|
|
357
|
+
return self;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
#pragma mark Accessibility
|
|
361
|
+
|
|
362
|
+
// React Native's accessibility props, mapped in the core (accessibility.h).
|
|
363
|
+
- (ngn::AxInfo)axInfo {
|
|
364
|
+
auto viewProps = std::dynamic_pointer_cast<const ViewProps>(_props);
|
|
365
|
+
if (!viewProps) {
|
|
366
|
+
return ngn::AxInfo{};
|
|
367
|
+
}
|
|
368
|
+
if ([_componentName isEqualToString:@"Paragraph"]) {
|
|
369
|
+
return ngn::paragraphAccessibilityInfo(*viewProps, ngn::paragraphText(_state));
|
|
370
|
+
}
|
|
371
|
+
return ngn::accessibilityInfo(*viewProps);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
- (BOOL)isAccessibilityElement {
|
|
375
|
+
return [self axInfo].element;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
- (NSAccessibilityRole)accessibilityRole {
|
|
379
|
+
return nsRole([self axInfo].role);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
- (NSAccessibilitySubrole)accessibilitySubrole {
|
|
383
|
+
return nsSubrole([self axInfo].subrole);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
- (NSString *)accessibilityRoleDescription {
|
|
387
|
+
auto info = [self axInfo];
|
|
388
|
+
// A role AppKit has (a heading from macOS 26) is spoken by AppKit's own name for it.
|
|
389
|
+
if (!info.roleDescription.empty() && !(info.role == ngn::AxRole::Heading && nativeRole(info.role))) {
|
|
390
|
+
return nsString(info.roleDescription);
|
|
391
|
+
}
|
|
392
|
+
return NSAccessibilityRoleDescription(nsRole(info.role), nsSubrole(info.subrole));
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
- (NSString *)accessibilityLabel {
|
|
396
|
+
auto info = [self axInfo];
|
|
397
|
+
if (info.label.empty() && info.hidesChildren && ![_componentName isEqualToString:@"Paragraph"]) {
|
|
398
|
+
// Read as one element with no label of its own: named by the text inside it, as iOS does.
|
|
399
|
+
NSMutableArray<NSString *> *texts = [NSMutableArray array];
|
|
400
|
+
[self collectTextInto:texts];
|
|
401
|
+
return texts.count > 0 ? [texts componentsJoinedByString:@" "] : nil;
|
|
402
|
+
}
|
|
403
|
+
return info.label.empty() ? nil : nsString(info.label);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
- (void)collectTextInto:(NSMutableArray<NSString *> *)texts {
|
|
407
|
+
for (NSView *child in [self contentContainer].subviews) {
|
|
408
|
+
if (![child isKindOfClass:NGNView.class] || child.hidden) {
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
NGNView *view = (NGNView *)child;
|
|
412
|
+
auto info = [view axInfo];
|
|
413
|
+
if (!info.label.empty()) {
|
|
414
|
+
[texts addObject:nsString(info.label)];
|
|
415
|
+
} else if ([view.componentName isEqualToString:@"Paragraph"]) {
|
|
416
|
+
auto text = ngn::paragraphText(view.state);
|
|
417
|
+
if (!text.empty()) {
|
|
418
|
+
[texts addObject:nsString(text)];
|
|
419
|
+
}
|
|
420
|
+
} else {
|
|
421
|
+
[view collectTextInto:texts];
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// An element read as one has no elements inside it.
|
|
427
|
+
- (NSArray *)accessibilityChildren {
|
|
428
|
+
if ([self axInfo].hidesChildren) {
|
|
429
|
+
return @[];
|
|
430
|
+
}
|
|
431
|
+
return [super accessibilityChildren];
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
- (NSString *)accessibilityHelp {
|
|
435
|
+
auto info = [self axInfo];
|
|
436
|
+
return info.hint.empty() ? nil : nsString(info.hint);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
- (id)accessibilityValue {
|
|
440
|
+
auto info = [self axInfo];
|
|
441
|
+
if (info.checked) {
|
|
442
|
+
return @(*info.checked);
|
|
443
|
+
}
|
|
444
|
+
return info.value.empty() ? nil : nsString(info.value);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// The heading level, which AppKit names from macOS 26 and has no property for.
|
|
448
|
+
#pragma clang diagnostic push
|
|
449
|
+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
450
|
+
- (NSArray<NSAccessibilityAttributeName> *)accessibilityAttributeNames {
|
|
451
|
+
NSArray *names = [super accessibilityAttributeNames];
|
|
452
|
+
auto info = [self axInfo];
|
|
453
|
+
if (info.level && nativeRole(info.role) && info.role == ngn::AxRole::Heading) {
|
|
454
|
+
return [names arrayByAddingObject:@"AXHeadingLevel"];
|
|
455
|
+
}
|
|
456
|
+
return names;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
- (id)accessibilityAttributeValue:(NSAccessibilityAttributeName)attribute {
|
|
460
|
+
if ([attribute isEqualToString:@"AXHeadingLevel"]) {
|
|
461
|
+
auto level = [self axInfo].level;
|
|
462
|
+
return level ? @(*level) : nil;
|
|
463
|
+
}
|
|
464
|
+
return [super accessibilityAttributeValue:attribute];
|
|
465
|
+
}
|
|
466
|
+
#pragma clang diagnostic pop
|
|
467
|
+
|
|
468
|
+
- (BOOL)isAccessibilityEnabled {
|
|
469
|
+
return ![self axInfo].disabled;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
- (BOOL)isAccessibilitySelected {
|
|
473
|
+
return [self axInfo].selected;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
- (BOOL)isAccessibilityExpanded {
|
|
477
|
+
return [self axInfo].expanded.value_or(false);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
- (NSArray<NSAccessibilityCustomAction *> *)accessibilityCustomActions {
|
|
481
|
+
auto info = [self axInfo];
|
|
482
|
+
if (info.customActions.empty()) {
|
|
483
|
+
return nil;
|
|
484
|
+
}
|
|
485
|
+
NSMutableArray<NSAccessibilityCustomAction *> *actions = [NSMutableArray array];
|
|
486
|
+
__weak NGNView *weakSelf = self;
|
|
487
|
+
for (const auto &action : info.customActions) {
|
|
488
|
+
std::string name = action.name;
|
|
489
|
+
[actions addObject:[[NSAccessibilityCustomAction alloc] initWithName:nsString(action.label)
|
|
490
|
+
handler:^BOOL {
|
|
491
|
+
return [weakSelf sendAccessibilityAction:name];
|
|
492
|
+
}]];
|
|
493
|
+
}
|
|
494
|
+
return actions;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// Sends a declared action, as iOS does only to a view that listens for them.
|
|
498
|
+
- (BOOL)sendAccessibilityAction:(const std::string &)name {
|
|
499
|
+
auto viewProps = std::dynamic_pointer_cast<const ViewProps>(_props);
|
|
500
|
+
auto emitter = std::dynamic_pointer_cast<const ViewEventEmitter>(_emitter);
|
|
501
|
+
if (!viewProps || !viewProps->onAccessibilityAction || !emitter) {
|
|
502
|
+
return NO;
|
|
503
|
+
}
|
|
504
|
+
emitter->onAccessibilityAction(name);
|
|
505
|
+
return YES;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// One of AppKit's standard actions, as the core decides it reaches the app (accessibility.h).
|
|
509
|
+
- (BOOL)performAxVerb:(ngn::AxVerb)verb {
|
|
510
|
+
auto viewProps = std::dynamic_pointer_cast<const ViewProps>(_props);
|
|
511
|
+
auto emitter = std::dynamic_pointer_cast<const ViewEventEmitter>(_emitter);
|
|
512
|
+
if (!viewProps || !emitter) {
|
|
513
|
+
return NO;
|
|
514
|
+
}
|
|
515
|
+
auto dispatch = ngn::axDispatch(*viewProps, verb);
|
|
516
|
+
switch (dispatch.kind) {
|
|
517
|
+
case ngn::AxDispatch::Kind::None:
|
|
518
|
+
return NO;
|
|
519
|
+
case ngn::AxDispatch::Kind::Tap:
|
|
520
|
+
emitter->onAccessibilityTap();
|
|
521
|
+
return YES;
|
|
522
|
+
case ngn::AxDispatch::Kind::Escape:
|
|
523
|
+
emitter->onAccessibilityEscape();
|
|
524
|
+
return YES;
|
|
525
|
+
case ngn::AxDispatch::Kind::Action:
|
|
526
|
+
emitter->onAccessibilityAction(dispatch.action);
|
|
527
|
+
return YES;
|
|
528
|
+
case ngn::AxDispatch::Kind::Click:
|
|
529
|
+
return gViewInput != nullptr && gViewInput->activate(static_cast<SurfaceId>(_surfaceId), static_cast<Tag>(_reactTag));
|
|
530
|
+
}
|
|
531
|
+
return NO;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
- (BOOL)accessibilityPerformPress {
|
|
535
|
+
return [self performAxVerb:ngn::AxVerb::Press];
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
- (BOOL)accessibilityPerformIncrement {
|
|
539
|
+
return [self performAxVerb:ngn::AxVerb::Increment];
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
- (BOOL)accessibilityPerformDecrement {
|
|
543
|
+
return [self performAxVerb:ngn::AxVerb::Decrement];
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
- (BOOL)accessibilityPerformCancel {
|
|
547
|
+
return [self performAxVerb:ngn::AxVerb::Cancel];
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// AppKit lists an action for every one of these the class implements; a view offers only those
|
|
551
|
+
// that mean something for it. A focusable view is pressed as a control is.
|
|
552
|
+
- (BOOL)isAccessibilitySelectorAllowed:(SEL)selector {
|
|
553
|
+
if (selector == @selector(accessibilityPerformPress)) {
|
|
554
|
+
return [self axInfo].offersPress || [self acceptsFirstResponder];
|
|
555
|
+
}
|
|
556
|
+
if (selector == @selector(accessibilityPerformIncrement) || selector == @selector(accessibilityPerformDecrement)) {
|
|
557
|
+
return [self axInfo].offersIncrement;
|
|
558
|
+
}
|
|
559
|
+
if (selector == @selector(accessibilityPerformCancel)) {
|
|
560
|
+
return [self axInfo].offersCancel;
|
|
561
|
+
}
|
|
562
|
+
// Only a view that expands says whether it is expanded.
|
|
563
|
+
if (selector == @selector(isAccessibilityExpanded)) {
|
|
564
|
+
return [self axInfo].expanded.has_value();
|
|
565
|
+
}
|
|
566
|
+
return [super isAccessibilitySelectorAllowed:selector];
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// Space and Return press a focused view, as they press a focused AppKit control. A default button
|
|
570
|
+
// takes Return first, as AppKit's own key equivalents do.
|
|
571
|
+
- (void)keyDown:(NSEvent *)event {
|
|
572
|
+
NSEventModifierFlags modifiers = event.modifierFlags & (NSEventModifierFlagCommand | NSEventModifierFlagControl |
|
|
573
|
+
NSEventModifierFlagOption);
|
|
574
|
+
NSString *key = event.charactersIgnoringModifiers;
|
|
575
|
+
BOOL activates = [key isEqualToString:@" "] || [key isEqualToString:@"\r"];
|
|
576
|
+
if (modifiers == 0 && activates && !event.isARepeat && self.window.firstResponder == self &&
|
|
577
|
+
[self performAxVerb:ngn::AxVerb::Press]) {
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
[super keyDown:event];
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
- (void)updateProps:(const Props::Shared &)props {
|
|
584
|
+
_props = props;
|
|
585
|
+
[self applyVisuals];
|
|
586
|
+
if ([_componentName isEqualToString:@"Paragraph"]) {
|
|
587
|
+
[self setNeedsDisplay:YES];
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
- (void)updateLayout:(const LayoutMetrics &)metrics {
|
|
592
|
+
_layout = metrics;
|
|
593
|
+
const auto &f = metrics.frame;
|
|
594
|
+
self.frame = NSMakeRect(f.origin.x + _swipeOffset, f.origin.y, f.size.width, f.size.height);
|
|
595
|
+
[self updateHidden];
|
|
596
|
+
[self applyVisuals];
|
|
597
|
+
[self setNeedsDisplay:YES];
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
- (void)updateHidden {
|
|
601
|
+
self.hidden = _layout.displayType == DisplayType::None || (_covered && !_swipeShown);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
- (void)setCovered:(BOOL)covered {
|
|
605
|
+
_covered = covered;
|
|
606
|
+
[self updateHidden];
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
- (void)setSwipeShown:(BOOL)swipeShown {
|
|
610
|
+
_swipeShown = swipeShown;
|
|
611
|
+
[self updateHidden];
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
- (void)setSwipeOffset:(CGFloat)swipeOffset {
|
|
615
|
+
_swipeOffset = swipeOffset;
|
|
616
|
+
[self setFrameOrigin:NSMakePoint(_layout.frame.origin.x + swipeOffset, _layout.frame.origin.y)];
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
- (void)setSwipeOpacity:(CGFloat)swipeOpacity {
|
|
620
|
+
_swipeOpacity = swipeOpacity;
|
|
621
|
+
[self applyVisuals];
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
- (void)updateState:(const State::Shared &)state {
|
|
625
|
+
_state = state;
|
|
626
|
+
[self setNeedsDisplay:YES];
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
- (void)updateEventEmitter:(const EventEmitter::Shared &)emitter {
|
|
630
|
+
_emitter = emitter;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
- (void)updateDesktopProps:(const ngn::DesktopProps &)props {
|
|
634
|
+
// Kept for the Tab-order walk; focusable already decides acceptsFirstResponder.
|
|
635
|
+
_desktop = props;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
- (void)handleCommand:(const std::string &)name args:(const folly::dynamic &)args {
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
- (void)applyVisuals {
|
|
642
|
+
auto viewProps = std::dynamic_pointer_cast<const ViewProps>(_props);
|
|
643
|
+
if (!viewProps) {
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
CALayer *layer = self.layer;
|
|
647
|
+
self.alphaValue = viewProps->opacity * _swipeOpacity;
|
|
648
|
+
auto box = ngn::viewBox(*viewProps, _layout);
|
|
649
|
+
layer.backgroundColor = box.background ? cgColor(*box.background) : nil;
|
|
650
|
+
layer.cornerRadius = box.cornerRadius;
|
|
651
|
+
layer.borderWidth = box.borderWidth;
|
|
652
|
+
layer.borderColor = box.borderColor ? cgColor(*box.borderColor) : nil;
|
|
653
|
+
layer.masksToBounds = viewProps->yogaStyle.overflow() != facebook::yoga::Overflow::Visible;
|
|
654
|
+
layer.mask = box.clip ? shapeLayer(*box.clip, NO, self.bounds) : nil;
|
|
655
|
+
[self applyShadows:box.shadows];
|
|
656
|
+
// Its transform, about its centre on a layer anchored at its corner (view-transform.h).
|
|
657
|
+
CATransform3D transform = CATransform3DIdentity;
|
|
658
|
+
if (auto matrix = ngn::layerTransform(*viewProps, _layout)) {
|
|
659
|
+
const auto &m = matrix->matrix;
|
|
660
|
+
transform = CATransform3D{m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9], m[10], m[11], m[12], m[13], m[14], m[15]};
|
|
661
|
+
}
|
|
662
|
+
if (!CATransform3DEqualToTransform(_transform, transform)) {
|
|
663
|
+
_transform = transform;
|
|
664
|
+
if ([layer isKindOfClass:NGNViewLayer.class]) {
|
|
665
|
+
((NGNViewLayer *)layer).viewTransform = transform;
|
|
666
|
+
} else {
|
|
667
|
+
layer.transform = transform;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
if (box.drawn || _boxDrawn) {
|
|
671
|
+
[self setNeedsDisplay:YES];
|
|
672
|
+
}
|
|
673
|
+
_boxDrawn = box.drawn;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
// Each box shadow as a layer under the children, as RCTViewComponentView adds them.
|
|
677
|
+
- (void)applyShadows:(const std::vector<ngn::BoxShadowLayer> &)shadows {
|
|
678
|
+
for (CALayer *old in _shadowLayers) {
|
|
679
|
+
[old removeFromSuperlayer];
|
|
680
|
+
}
|
|
681
|
+
[_shadowLayers removeAllObjects];
|
|
682
|
+
if (shadows.empty()) {
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
if (_shadowLayers == nil) {
|
|
686
|
+
_shadowLayers = [NSMutableArray array];
|
|
687
|
+
}
|
|
688
|
+
for (const auto &shadow : shadows) {
|
|
689
|
+
CALayer *layer = [CALayer layer];
|
|
690
|
+
layer.frame = self.bounds;
|
|
691
|
+
layer.zPosition = -1000;
|
|
692
|
+
layer.shadowColor = cgColor(shadow.argb);
|
|
693
|
+
layer.shadowOpacity = 1;
|
|
694
|
+
layer.shadowOffset = CGSizeZero;
|
|
695
|
+
layer.shadowRadius = shadow.radius;
|
|
696
|
+
CGPathRef path = NGNCreatePath(shadow.shadowPath);
|
|
697
|
+
layer.shadowPath = path;
|
|
698
|
+
CGPathRelease(path);
|
|
699
|
+
layer.mask = shapeLayer(shadow.mask, shadow.maskEvenOdd, self.bounds);
|
|
700
|
+
[self.layer addSublayer:layer];
|
|
701
|
+
[_shadowLayers addObject:layer];
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
- (void)drawRect:(NSRect)dirtyRect {
|
|
706
|
+
auto viewProps = std::dynamic_pointer_cast<const ViewProps>(_props);
|
|
707
|
+
if (_boxDrawn && viewProps) {
|
|
708
|
+
CGContextRef context = NSGraphicsContext.currentContext.CGContext;
|
|
709
|
+
CGFloat scale = self.window ? self.window.backingScaleFactor : NSScreen.mainScreen.backingScaleFactor;
|
|
710
|
+
auto canvas = NGNMakeCGCanvas(context, self.bounds.size, scale, nil);
|
|
711
|
+
CGContextSaveGState(context);
|
|
712
|
+
ngn::drawViewBox(*viewProps, _layout, *canvas);
|
|
713
|
+
CGContextRestoreGState(context);
|
|
714
|
+
}
|
|
715
|
+
if (![_componentName isEqualToString:@"Paragraph"] || !_state) {
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
auto state = std::static_pointer_cast<const ConcreteState<ParagraphState>>(_state);
|
|
719
|
+
const auto &data = state->getData();
|
|
720
|
+
const auto &insets = _layout.contentInsets;
|
|
721
|
+
CGFloat width = _layout.frame.size.width - insets.left - insets.right;
|
|
722
|
+
// A hair of slack, so the width Yoga rounded to the pixel lays out the same lines as measure.
|
|
723
|
+
auto layout = ngn::layoutText(data.attributedString, data.paragraphAttributes, width + 0.5);
|
|
724
|
+
ngn::drawText(layout, NSGraphicsContext.currentContext.CGContext, CGPointMake(insets.left, insets.top), width);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
@end
|
|
728
|
+
|
|
729
|
+
#pragma mark - NGNTextInputView
|
|
730
|
+
|
|
731
|
+
using ngn::DesktopTextInputProps;
|
|
732
|
+
|
|
733
|
+
namespace {
|
|
734
|
+
|
|
735
|
+
// The font a TextInput's text attributes resolve to, as its Paragraph would draw them.
|
|
736
|
+
NSFont *inputFont(const DesktopTextInputProps &p) {
|
|
737
|
+
auto attrs = p.getEffectiveTextAttributes(1);
|
|
738
|
+
AttributedString probe;
|
|
739
|
+
probe.appendFragment(AttributedString::Fragment{.string = "x", .textAttributes = attrs, .parentShadowView = {}});
|
|
740
|
+
CFAttributedStringRef s = ngn::makeAttributedString(probe);
|
|
741
|
+
NSFont *font = (__bridge NSFont *)CFAttributedStringGetAttribute(s, 0, kCTFontAttributeName, nullptr);
|
|
742
|
+
CFRelease(s);
|
|
743
|
+
return font;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// How a TextInput aligns its text and placeholder (inputAlignment), in a layout running `direction`,
|
|
747
|
+
// and the base writing direction its `writingDirection` sets, natural when unset.
|
|
748
|
+
void alignInput(id field, const DesktopTextInputProps &p, LayoutDirection direction) {
|
|
749
|
+
NSTextAlignment alignment = NSTextAlignmentLeft;
|
|
750
|
+
switch (ngn::inputAlignment(p.textAttributes.alignment, direction)) {
|
|
751
|
+
case TextAlignment::Right: alignment = NSTextAlignmentRight; break;
|
|
752
|
+
case TextAlignment::Center: alignment = NSTextAlignmentCenter; break;
|
|
753
|
+
case TextAlignment::Justified: alignment = NSTextAlignmentJustified; break;
|
|
754
|
+
default: break;
|
|
755
|
+
}
|
|
756
|
+
NSWritingDirection writing = NSWritingDirectionNatural;
|
|
757
|
+
if (p.textAttributes.baseWritingDirection == WritingDirection::LeftToRight) {
|
|
758
|
+
writing = NSWritingDirectionLeftToRight;
|
|
759
|
+
} else if (p.textAttributes.baseWritingDirection == WritingDirection::RightToLeft) {
|
|
760
|
+
writing = NSWritingDirectionRightToLeft;
|
|
761
|
+
}
|
|
762
|
+
[field setTextAlignment:alignment writingDirection:writing];
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// The `selection` prop, when it is new in this update: React Native iOS applies it only then.
|
|
766
|
+
std::optional<NSRange> newSelection(const Props::Shared &old, const DesktopTextInputProps &p) {
|
|
767
|
+
if (!p.selection) {
|
|
768
|
+
return std::nullopt;
|
|
769
|
+
}
|
|
770
|
+
auto before = std::dynamic_pointer_cast<const DesktopTextInputProps>(old);
|
|
771
|
+
if (before && before->selection && before->selection->start == p.selection->start &&
|
|
772
|
+
before->selection->end == p.selection->end) {
|
|
773
|
+
return std::nullopt;
|
|
774
|
+
}
|
|
775
|
+
int start = std::max(0, std::min(p.selection->start, p.selection->end));
|
|
776
|
+
int end = std::max(p.selection->start, p.selection->end);
|
|
777
|
+
return NSMakeRange(start, end - start);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
} // namespace
|
|
781
|
+
|
|
782
|
+
@implementation NGNTextInputView {
|
|
783
|
+
NGNTextField *_box;
|
|
784
|
+
int _eventCount;
|
|
785
|
+
BOOL _settingText;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
- (instancetype)initWithShadowView:(const ShadowView &)view {
|
|
789
|
+
if ((self = [super initWithShadowView:view])) {
|
|
790
|
+
_box = [[NGNTextField alloc] initWithFrame:NSZeroRect];
|
|
791
|
+
NSTextField *field = _box.control;
|
|
792
|
+
field.bezeled = NO;
|
|
793
|
+
field.bordered = NO;
|
|
794
|
+
field.drawsBackground = NO;
|
|
795
|
+
field.focusRingType = NSFocusRingTypeNone;
|
|
796
|
+
field.usesSingleLineMode = YES;
|
|
797
|
+
field.cell.scrollable = YES;
|
|
798
|
+
field.cell.wraps = NO;
|
|
799
|
+
field.delegate = self;
|
|
800
|
+
__weak NGNTextInputView *weakSelf = self;
|
|
801
|
+
_box.focused = ^{
|
|
802
|
+
NGNTextInputView *strong = weakSelf;
|
|
803
|
+
if (auto e = [strong inputEmitter]) {
|
|
804
|
+
e->onFocus([strong metrics]);
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
// Secure entry is a field of its own class in AppKit; the box swaps it as the prop changes.
|
|
808
|
+
auto first = std::dynamic_pointer_cast<const DesktopTextInputProps>(view.props);
|
|
809
|
+
_box.secure = first && first->traits.secureTextEntry;
|
|
810
|
+
_box.autoFocus = first && first->autoFocus;
|
|
811
|
+
[self addSubview:_box];
|
|
812
|
+
}
|
|
813
|
+
return self;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
- (void)dealloc {
|
|
817
|
+
[NSNotificationCenter.defaultCenter removeObserver:self];
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
- (void)updateProps:(const Props::Shared &)props {
|
|
821
|
+
Props::Shared old = self.props;
|
|
822
|
+
[super updateProps:props];
|
|
823
|
+
auto p = std::dynamic_pointer_cast<const DesktopTextInputProps>(props);
|
|
824
|
+
if (!p) {
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
_box.secure = p->traits.secureTextEntry;
|
|
828
|
+
NSTextField *field = _box.control;
|
|
829
|
+
auto attrs = p->getEffectiveTextAttributes(1);
|
|
830
|
+
field.font = inputFont(*p);
|
|
831
|
+
field.textColor = attrs.foregroundColor ? nsColor(attrs.foregroundColor) : NSColor.textColor;
|
|
832
|
+
[_box setPlaceholder:nsString(p->placeholder) color:p->placeholderTextColor ? nsColor(p->placeholderTextColor) : nil];
|
|
833
|
+
alignInput(_box, *p, self.layoutMetrics.layoutDirection);
|
|
834
|
+
field.editable = p->editable && !p->readOnly;
|
|
835
|
+
[_box applyOptions:ngn::textInputOptions(*p)];
|
|
836
|
+
// The text prop wins only when it is not older than what the field has sent (React Native iOS's
|
|
837
|
+
// rule), and never while an input method is composing.
|
|
838
|
+
if (ngn::controlledTextIsCurrent(p->mostRecentEventCount, _eventCount, [self composing]) && !p->text.empty()) {
|
|
839
|
+
NSString *text = nsString(p->text);
|
|
840
|
+
if (![field.stringValue isEqualToString:text]) {
|
|
841
|
+
field.stringValue = text;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
if (auto range = newSelection(old, *p)) {
|
|
845
|
+
[_box selectRange:*range];
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
- (void)updateLayout:(const LayoutMetrics &)metrics {
|
|
850
|
+
[super updateLayout:metrics];
|
|
851
|
+
if (auto p = std::dynamic_pointer_cast<const DesktopTextInputProps>(self.props)) {
|
|
852
|
+
alignInput(_box, *p, metrics.layoutDirection);
|
|
853
|
+
}
|
|
854
|
+
const auto &i = metrics.contentInsets;
|
|
855
|
+
NSRect content = NSMakeRect(
|
|
856
|
+
i.left, i.top, metrics.frame.size.width - i.left - i.right, metrics.frame.size.height - i.top - i.bottom);
|
|
857
|
+
// The single line, centred vertically in the content box.
|
|
858
|
+
CGFloat h = std::min<CGFloat>(content.size.height, _box.control.intrinsicContentSize.height);
|
|
859
|
+
_box.frame = NSMakeRect(content.origin.x, content.origin.y + (content.size.height - h) / 2, content.size.width, h);
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
- (NSResponder *)keyboardResponder {
|
|
863
|
+
return _box.control;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
- (BOOL)composing {
|
|
867
|
+
NSText *editor = _box.currentEditor;
|
|
868
|
+
return [editor isKindOfClass:NSTextView.class] && [(NSTextView *)editor hasMarkedText];
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
- (TextInputEventEmitter::Metrics)metrics {
|
|
872
|
+
NSString *value = _box.stringValue;
|
|
873
|
+
NSRange sel = _box.currentEditor ? _box.currentEditor.selectedRange : NSMakeRange(value.length, 0);
|
|
874
|
+
return TextInputEventEmitter::Metrics{
|
|
875
|
+
.text = std::string(value.UTF8String),
|
|
876
|
+
.selectionRange = {.location = (int)sel.location, .length = (int)sel.length},
|
|
877
|
+
.eventCount = _eventCount,
|
|
878
|
+
.target = (Tag)self.reactTag,
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
- (std::shared_ptr<const TextInputEventEmitter>)inputEmitter {
|
|
883
|
+
return std::static_pointer_cast<const TextInputEventEmitter>(self.eventEmitter);
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
- (void)controlTextDidChange:(NSNotification *)note {
|
|
887
|
+
if (_settingText) {
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
_eventCount++;
|
|
891
|
+
if (auto e = [self inputEmitter]) {
|
|
892
|
+
e->onChange([self metrics]);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
- (void)controlTextDidBeginEditing:(NSNotification *)note {
|
|
897
|
+
NSTextView *editor = note.userInfo[@"NSFieldEditor"];
|
|
898
|
+
if (editor != nil) {
|
|
899
|
+
[NSNotificationCenter.defaultCenter addObserver:self
|
|
900
|
+
selector:@selector(selectionDidChange:)
|
|
901
|
+
name:NSTextViewDidChangeSelectionNotification
|
|
902
|
+
object:editor];
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
- (void)controlTextDidEndEditing:(NSNotification *)note {
|
|
907
|
+
[NSNotificationCenter.defaultCenter removeObserver:self name:NSTextViewDidChangeSelectionNotification object:nil];
|
|
908
|
+
if (_box.swapping) {
|
|
909
|
+
return; // secure entry changing hands the keyboard from one control to the other
|
|
910
|
+
}
|
|
911
|
+
if (auto e = [self inputEmitter]) {
|
|
912
|
+
e->onEndEditing([self metrics]);
|
|
913
|
+
e->onBlur([self metrics]);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
- (void)selectionDidChange:(NSNotification *)note {
|
|
918
|
+
if (auto e = [self inputEmitter]) {
|
|
919
|
+
e->onSelectionChange([self metrics]);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)selector {
|
|
924
|
+
if (selector == @selector(insertNewline:)) {
|
|
925
|
+
if (auto e = [self inputEmitter]) {
|
|
926
|
+
e->onSubmitEditing([self metrics]);
|
|
927
|
+
}
|
|
928
|
+
return YES;
|
|
929
|
+
}
|
|
930
|
+
return NO;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
- (void)handleCommand:(const std::string &)name args:(const folly::dynamic &)args {
|
|
934
|
+
if (name == "focus") {
|
|
935
|
+
// The box reports the focus as the field takes the keyboard.
|
|
936
|
+
[self.window makeFirstResponder:_box.control];
|
|
937
|
+
} else if (name == "blur") {
|
|
938
|
+
[self.window makeFirstResponder:nil];
|
|
939
|
+
} else if (name == "setTextAndSelection" && args.isArray() && args.size() >= 4) {
|
|
940
|
+
int count = (int)args[0].asInt();
|
|
941
|
+
if (count < _eventCount) {
|
|
942
|
+
return; // stale: the field has moved on since JavaScript sent this
|
|
943
|
+
}
|
|
944
|
+
NSTextField *field = _box.control;
|
|
945
|
+
if (args[1].isString() && ![self composing]) {
|
|
946
|
+
NSString *text = nsString(args[1].asString());
|
|
947
|
+
if (![field.stringValue isEqualToString:text]) {
|
|
948
|
+
_settingText = YES;
|
|
949
|
+
field.stringValue = text;
|
|
950
|
+
_settingText = NO;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
if (args[2].isNumber() && args[3].isNumber() && field.currentEditor) {
|
|
954
|
+
NSInteger start = args[2].asInt(), end = args[3].asInt();
|
|
955
|
+
if (start >= 0 && end >= start && (NSUInteger)end <= field.stringValue.length) {
|
|
956
|
+
field.currentEditor.selectedRange = NSMakeRange(start, end - start);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
@end
|
|
963
|
+
|
|
964
|
+
#pragma mark - NGNMultilineTextInputView
|
|
965
|
+
|
|
966
|
+
// A multiline TextInput: an NSTextView, which wraps, scrolls and takes Return as a new line.
|
|
967
|
+
@interface NGNMultilineTextInputView : NGNView <NSTextViewDelegate>
|
|
968
|
+
@end
|
|
969
|
+
|
|
970
|
+
@implementation NGNMultilineTextInputView {
|
|
971
|
+
NSScrollView *_scroll;
|
|
972
|
+
NGNTextView *_text;
|
|
973
|
+
int _eventCount;
|
|
974
|
+
BOOL _settingText;
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
- (instancetype)initWithShadowView:(const ShadowView &)view {
|
|
978
|
+
if ((self = [super initWithShadowView:view])) {
|
|
979
|
+
_scroll = [[NSScrollView alloc] initWithFrame:NSZeroRect];
|
|
980
|
+
_scroll.drawsBackground = NO;
|
|
981
|
+
_scroll.hasVerticalScroller = YES;
|
|
982
|
+
_scroll.autohidesScrollers = YES;
|
|
983
|
+
_text = [[NGNTextView alloc] initWithFrame:NSZeroRect];
|
|
984
|
+
_text.drawsBackground = NO;
|
|
985
|
+
_text.richText = NO;
|
|
986
|
+
_text.allowsUndo = YES;
|
|
987
|
+
_text.verticallyResizable = YES;
|
|
988
|
+
_text.horizontallyResizable = NO;
|
|
989
|
+
_text.autoresizingMask = NSViewWidthSizable;
|
|
990
|
+
_text.textContainer.widthTracksTextView = YES;
|
|
991
|
+
_text.textContainerInset = NSZeroSize;
|
|
992
|
+
_text.textContainer.lineFragmentPadding = 0;
|
|
993
|
+
_text.delegate = self;
|
|
994
|
+
__weak NGNMultilineTextInputView *weakSelf = self;
|
|
995
|
+
_text.focused = ^{
|
|
996
|
+
NGNMultilineTextInputView *strong = weakSelf;
|
|
997
|
+
if (auto e = [strong inputEmitter]) {
|
|
998
|
+
e->onFocus([strong metrics]);
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
auto first = std::dynamic_pointer_cast<const DesktopTextInputProps>(view.props);
|
|
1002
|
+
_text.autoFocus = first && first->autoFocus;
|
|
1003
|
+
_scroll.documentView = _text;
|
|
1004
|
+
[self addSubview:_scroll];
|
|
1005
|
+
}
|
|
1006
|
+
return self;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
- (void)updateProps:(const Props::Shared &)props {
|
|
1010
|
+
Props::Shared old = self.props;
|
|
1011
|
+
[super updateProps:props];
|
|
1012
|
+
auto p = std::dynamic_pointer_cast<const DesktopTextInputProps>(props);
|
|
1013
|
+
if (!p) {
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
auto attrs = p->getEffectiveTextAttributes(1);
|
|
1017
|
+
_text.font = inputFont(*p);
|
|
1018
|
+
_text.textColor = attrs.foregroundColor ? nsColor(attrs.foregroundColor) : NSColor.textColor;
|
|
1019
|
+
[_text setPlaceholder:nsString(p->placeholder) color:p->placeholderTextColor ? nsColor(p->placeholderTextColor) : nil];
|
|
1020
|
+
alignInput(_text, *p, self.layoutMetrics.layoutDirection);
|
|
1021
|
+
_text.editable = p->editable && !p->readOnly;
|
|
1022
|
+
[_text applyOptions:ngn::textInputOptions(*p)];
|
|
1023
|
+
if (ngn::controlledTextIsCurrent(p->mostRecentEventCount, _eventCount, _text.hasMarkedText) && !p->text.empty()) {
|
|
1024
|
+
NSString *text = nsString(p->text);
|
|
1025
|
+
if (![_text.string isEqualToString:text]) {
|
|
1026
|
+
_settingText = YES;
|
|
1027
|
+
_text.string = text;
|
|
1028
|
+
_settingText = NO;
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
if (auto range = newSelection(old, *p)) {
|
|
1032
|
+
[_text selectRange:*range];
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
- (void)updateLayout:(const LayoutMetrics &)metrics {
|
|
1037
|
+
[super updateLayout:metrics];
|
|
1038
|
+
if (auto p = std::dynamic_pointer_cast<const DesktopTextInputProps>(self.props)) {
|
|
1039
|
+
alignInput(_text, *p, metrics.layoutDirection);
|
|
1040
|
+
}
|
|
1041
|
+
const auto &i = metrics.contentInsets;
|
|
1042
|
+
_scroll.frame = NSMakeRect(
|
|
1043
|
+
i.left, i.top, metrics.frame.size.width - i.left - i.right, metrics.frame.size.height - i.top - i.bottom);
|
|
1044
|
+
_text.frame = NSMakeRect(0, 0, _scroll.contentSize.width, std::max(_text.frame.size.height, _scroll.contentSize.height));
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
- (NSResponder *)keyboardResponder {
|
|
1048
|
+
return _text;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
- (TextInputEventEmitter::Metrics)metrics {
|
|
1052
|
+
NSRange sel = _text.selectedRange;
|
|
1053
|
+
return TextInputEventEmitter::Metrics{
|
|
1054
|
+
.text = std::string(_text.string.UTF8String),
|
|
1055
|
+
.selectionRange = {.location = (int)sel.location, .length = (int)sel.length},
|
|
1056
|
+
.eventCount = _eventCount,
|
|
1057
|
+
.target = (Tag)self.reactTag,
|
|
1058
|
+
};
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
- (std::shared_ptr<const TextInputEventEmitter>)inputEmitter {
|
|
1062
|
+
return std::static_pointer_cast<const TextInputEventEmitter>(self.eventEmitter);
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
- (void)textDidChange:(NSNotification *)note {
|
|
1066
|
+
if (_settingText) {
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
_eventCount++;
|
|
1070
|
+
if (auto e = [self inputEmitter]) {
|
|
1071
|
+
e->onChange([self metrics]);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
- (void)textDidEndEditing:(NSNotification *)note {
|
|
1076
|
+
if (auto e = [self inputEmitter]) {
|
|
1077
|
+
e->onEndEditing([self metrics]);
|
|
1078
|
+
e->onBlur([self metrics]);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
- (void)textViewDidChangeSelection:(NSNotification *)note {
|
|
1083
|
+
if (auto e = [self inputEmitter]) {
|
|
1084
|
+
e->onSelectionChange([self metrics]);
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
- (NSDictionary<NSTextCheckingOptionKey, id> *)textView:(NSTextView *)view
|
|
1089
|
+
willCheckTextInRange:(NSRange)range
|
|
1090
|
+
options:(NSDictionary<NSTextCheckingOptionKey, id> *)options
|
|
1091
|
+
types:(NSTextCheckingTypes *)checkingTypes {
|
|
1092
|
+
auto p = std::dynamic_pointer_cast<const DesktopTextInputProps>(self.props);
|
|
1093
|
+
return p ? NGNTextCheckingOptions(options, ngn::textInputOptions(*p)) : options;
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
- (void)handleCommand:(const std::string &)name args:(const folly::dynamic &)args {
|
|
1097
|
+
if (name == "focus") {
|
|
1098
|
+
[self.window makeFirstResponder:_text];
|
|
1099
|
+
} else if (name == "blur") {
|
|
1100
|
+
[self.window makeFirstResponder:nil];
|
|
1101
|
+
} else if (name == "setTextAndSelection" && args.isArray() && args.size() >= 4) {
|
|
1102
|
+
if ((int)args[0].asInt() < _eventCount) {
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1105
|
+
if (args[1].isString() && !_text.hasMarkedText) {
|
|
1106
|
+
NSString *text = nsString(args[1].asString());
|
|
1107
|
+
if (![_text.string isEqualToString:text]) {
|
|
1108
|
+
_settingText = YES;
|
|
1109
|
+
_text.string = text;
|
|
1110
|
+
_settingText = NO;
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
if (args[2].isNumber() && args[3].isNumber()) {
|
|
1114
|
+
NSInteger start = args[2].asInt(), end = args[3].asInt();
|
|
1115
|
+
if (start >= 0 && end >= start && (NSUInteger)end <= _text.string.length) {
|
|
1116
|
+
_text.selectedRange = NSMakeRange(start, end - start);
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
@end
|
|
1123
|
+
|
|
1124
|
+
// The libraries' views (component-view.h), by component name. Filled as the binary loads, before
|
|
1125
|
+
// anything mounts, and read on the UI thread after.
|
|
1126
|
+
static NSMutableDictionary<NSString *, Class> *libraryViews() {
|
|
1127
|
+
static NSMutableDictionary<NSString *, Class> *views = [NSMutableDictionary dictionary];
|
|
1128
|
+
return views;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
void NGNRegisterComponentView(NSString *componentName, Class viewClass) {
|
|
1132
|
+
if (![viewClass isSubclassOfClass:NGNView.class]) {
|
|
1133
|
+
NSLog(@"[ngn] %@ is not an NGNView, so %@ mounts as a plain view", viewClass, componentName);
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
1136
|
+
libraryViews()[componentName] = viewClass;
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
NGNView *NGNMakeView(const ShadowView &view) {
|
|
1140
|
+
if (NGNView *control = NGNMakeControlView(view)) {
|
|
1141
|
+
return control;
|
|
1142
|
+
}
|
|
1143
|
+
std::string_view name = view.componentName;
|
|
1144
|
+
if (name == "TextInput") {
|
|
1145
|
+
auto props = std::dynamic_pointer_cast<const DesktopTextInputProps>(view.props);
|
|
1146
|
+
if (props && props->multiline) {
|
|
1147
|
+
return [[NGNMultilineTextInputView alloc] initWithShadowView:view];
|
|
1148
|
+
}
|
|
1149
|
+
return [[NGNTextInputView alloc] initWithShadowView:view];
|
|
1150
|
+
}
|
|
1151
|
+
if (name == "Image") {
|
|
1152
|
+
return [[NGNImageView alloc] initWithShadowView:view];
|
|
1153
|
+
}
|
|
1154
|
+
if (name == "ModalHostView") {
|
|
1155
|
+
return [[NGNModalHostView alloc] initWithShadowView:view];
|
|
1156
|
+
}
|
|
1157
|
+
if (name == "RNSScreen") {
|
|
1158
|
+
return [[NGNPresentedScreenView alloc] initWithShadowView:view];
|
|
1159
|
+
}
|
|
1160
|
+
if (name == "RNSScreenStackHeaderConfig") {
|
|
1161
|
+
return [[NGNHeaderConfigView alloc] initWithShadowView:view];
|
|
1162
|
+
}
|
|
1163
|
+
if (name == "RNSScreenStackHeaderSubview") {
|
|
1164
|
+
return [[NGNHeaderSubviewView alloc] initWithShadowView:view];
|
|
1165
|
+
}
|
|
1166
|
+
if (name == "RNSSearchBar") {
|
|
1167
|
+
return [[NGNSearchBarView alloc] initWithShadowView:view];
|
|
1168
|
+
}
|
|
1169
|
+
if (name == "ScrollView") {
|
|
1170
|
+
return [[NGNScrollView alloc] initWithShadowView:view];
|
|
1171
|
+
}
|
|
1172
|
+
if (name == ngn::SplitViewComponentName) {
|
|
1173
|
+
return [[NGNSplitView alloc] initWithShadowView:view];
|
|
1174
|
+
}
|
|
1175
|
+
if (name == ngn::SidebarComponentName || name == ngn::SplitContentComponentName) {
|
|
1176
|
+
return [[NGNSplitPaneView alloc] initWithShadowView:view];
|
|
1177
|
+
}
|
|
1178
|
+
if (name == "RNSTabsHostIOS") {
|
|
1179
|
+
return [[NGNTabsHostView alloc] initWithShadowView:view];
|
|
1180
|
+
}
|
|
1181
|
+
if (name == "RNSTabsScreenIOS") {
|
|
1182
|
+
return [[NGNTabScreenView alloc] initWithShadowView:view];
|
|
1183
|
+
}
|
|
1184
|
+
if (name == ngn::SidebarSectionComponentName) {
|
|
1185
|
+
return [[NGNSidebarSectionView alloc] initWithShadowView:view];
|
|
1186
|
+
}
|
|
1187
|
+
if (name == ngn::SidebarItemComponentName) {
|
|
1188
|
+
return [[NGNSidebarItemView alloc] initWithShadowView:view];
|
|
1189
|
+
}
|
|
1190
|
+
if (name == ngn::SymbolComponentName) {
|
|
1191
|
+
return [[NGNSymbolView alloc] initWithShadowView:view];
|
|
1192
|
+
}
|
|
1193
|
+
if (name == ngn::GlassViewComponentName) {
|
|
1194
|
+
return [[NGNGlassView alloc] initWithShadowView:view];
|
|
1195
|
+
}
|
|
1196
|
+
// react-native-svg's: the svg draws its elements, whose own views are hidden.
|
|
1197
|
+
if (name == "RNSVGSvgView") {
|
|
1198
|
+
return [[NGNSvgView alloc] initWithShadowView:view];
|
|
1199
|
+
}
|
|
1200
|
+
if (name.starts_with("RNSVG")) {
|
|
1201
|
+
return [[NGNSvgElementView alloc] initWithShadowView:view];
|
|
1202
|
+
}
|
|
1203
|
+
if (name == ngn::MapComponentName) {
|
|
1204
|
+
return [[NGNMapView alloc] initWithShadowView:view];
|
|
1205
|
+
}
|
|
1206
|
+
if (name == ngn::CameraComponentName) {
|
|
1207
|
+
return [[NGNCameraView alloc] initWithShadowView:view];
|
|
1208
|
+
}
|
|
1209
|
+
if (name == ngn::VideoViewComponentName) {
|
|
1210
|
+
return [[NGNVideoView alloc] initWithShadowView:view];
|
|
1211
|
+
}
|
|
1212
|
+
if (name == ngn::AppleButtonComponentName) {
|
|
1213
|
+
return [[NGNAppleButtonView alloc] initWithShadowView:view];
|
|
1214
|
+
}
|
|
1215
|
+
if (NGNView *expoUI = NGNMakeExpoUIView(view)) {
|
|
1216
|
+
return expoUI;
|
|
1217
|
+
}
|
|
1218
|
+
if (name == ngn::ExpoImageComponentName) {
|
|
1219
|
+
return [[NGNExpoImageView alloc] initWithShadowView:view];
|
|
1220
|
+
}
|
|
1221
|
+
if (name == "RNCWebView" || name == ngn::DomWebViewComponentName) {
|
|
1222
|
+
return [[NGNWebView alloc] initWithShadowView:view];
|
|
1223
|
+
}
|
|
1224
|
+
if (Class library = libraryViews()[@(view.componentName)]) {
|
|
1225
|
+
return [[library alloc] initWithShadowView:view];
|
|
1226
|
+
}
|
|
1227
|
+
return [[NGNView alloc] initWithShadowView:view];
|
|
1228
|
+
}
|