@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,345 @@
|
|
|
1
|
+
// The core's reading of react-native-svg's props into svg elements (svg.h), compiled into the host
|
|
2
|
+
// only with the library (cmake/libraries.cmake).
|
|
3
|
+
//
|
|
4
|
+
// It also registers two components of the desktop's own: RNSVGSvgView, which the library's Android
|
|
5
|
+
// build leaves out of its list (Android draws into RNSVGSvgViewAndroid), and the two gradients,
|
|
6
|
+
// whose codegen props read their stops' colours as `float`, which rounds an ARGB colour's low bits
|
|
7
|
+
// off: here they are read as `double`, as React Native iOS's CGFloat does.
|
|
8
|
+
#include "ngn/library-glue.h"
|
|
9
|
+
#include "ngn/svg.h"
|
|
10
|
+
|
|
11
|
+
#include <react/renderer/components/rnsvg/ComponentDescriptors.h>
|
|
12
|
+
#include <react/renderer/components/rnsvg/RNSVGComponentDescriptors.h>
|
|
13
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
14
|
+
#include <react/renderer/core/propsConversions.h>
|
|
15
|
+
#include <react/renderer/graphics/ColorComponents.h>
|
|
16
|
+
|
|
17
|
+
#include <cmath>
|
|
18
|
+
#include <type_traits>
|
|
19
|
+
|
|
20
|
+
using namespace facebook::react;
|
|
21
|
+
|
|
22
|
+
namespace ngn {
|
|
23
|
+
|
|
24
|
+
namespace {
|
|
25
|
+
|
|
26
|
+
// A gradient's props, its stops' colours read at full precision.
|
|
27
|
+
class GradientProps : public ViewProps {
|
|
28
|
+
public:
|
|
29
|
+
GradientProps() = default;
|
|
30
|
+
GradientProps(const PropsParserContext &context, const GradientProps &source, const RawProps &raw)
|
|
31
|
+
: ViewProps(context, source, raw),
|
|
32
|
+
name(convertRawProp(context, raw, "name", source.name, {})),
|
|
33
|
+
x1(convertRawProp(context, raw, "x1", source.x1, {})),
|
|
34
|
+
y1(convertRawProp(context, raw, "y1", source.y1, {})),
|
|
35
|
+
x2(convertRawProp(context, raw, "x2", source.x2, {})),
|
|
36
|
+
y2(convertRawProp(context, raw, "y2", source.y2, {})),
|
|
37
|
+
cx(convertRawProp(context, raw, "cx", source.cx, {})),
|
|
38
|
+
cy(convertRawProp(context, raw, "cy", source.cy, {})),
|
|
39
|
+
rx(convertRawProp(context, raw, "rx", source.rx, {})),
|
|
40
|
+
ry(convertRawProp(context, raw, "ry", source.ry, {})),
|
|
41
|
+
fx(convertRawProp(context, raw, "fx", source.fx, {})),
|
|
42
|
+
fy(convertRawProp(context, raw, "fy", source.fy, {})),
|
|
43
|
+
gradient(convertRawProp(context, raw, "gradient", source.gradient, {})),
|
|
44
|
+
gradientUnits(convertRawProp(context, raw, "gradientUnits", source.gradientUnits, 0)),
|
|
45
|
+
gradientTransform(convertRawProp(context, raw, "gradientTransform", source.gradientTransform, {})) {}
|
|
46
|
+
|
|
47
|
+
std::string name;
|
|
48
|
+
folly::dynamic x1, y1, x2, y2, cx, cy, rx, ry, fx, fy;
|
|
49
|
+
std::vector<double> gradient;
|
|
50
|
+
int gradientUnits{0};
|
|
51
|
+
std::vector<double> gradientTransform;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
class LinearGradientProps final : public GradientProps {
|
|
55
|
+
public:
|
|
56
|
+
using GradientProps::GradientProps;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
class RadialGradientProps final : public GradientProps {
|
|
60
|
+
public:
|
|
61
|
+
using GradientProps::GradientProps;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
using LinearGradientShadowNode = RNSVGConcreteShadowNode<RNSVGLinearGradientComponentName, LinearGradientProps>;
|
|
65
|
+
using RadialGradientShadowNode = RNSVGConcreteShadowNode<RNSVGRadialGradientComponentName, RadialGradientProps>;
|
|
66
|
+
|
|
67
|
+
std::optional<SvgMatrix> matrixOf(const auto &values) {
|
|
68
|
+
if (values.size() != 6) {
|
|
69
|
+
return std::nullopt;
|
|
70
|
+
}
|
|
71
|
+
return SvgMatrix{
|
|
72
|
+
static_cast<double>(values[0]),
|
|
73
|
+
static_cast<double>(values[1]),
|
|
74
|
+
static_cast<double>(values[2]),
|
|
75
|
+
static_cast<double>(values[3]),
|
|
76
|
+
static_cast<double>(values[4]),
|
|
77
|
+
static_cast<double>(values[5])};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
std::optional<uint32_t> argbOf(const SharedColor &color) {
|
|
81
|
+
if (!color) {
|
|
82
|
+
return std::nullopt;
|
|
83
|
+
}
|
|
84
|
+
auto c = colorComponentsFromColor(color);
|
|
85
|
+
auto channel = [](float v) { return static_cast<uint32_t>(std::lround(std::clamp(v, 0.0f, 1.0f) * 255)); };
|
|
86
|
+
return channel(c.alpha) << 24 | channel(c.red) << 16 | channel(c.green) << 8 | channel(c.blue);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
void lengths(SvgElement &e, std::initializer_list<std::pair<const char *, const folly::dynamic *>> values) {
|
|
90
|
+
for (const auto &[name, value] : values) {
|
|
91
|
+
auto length = svgLength(*value);
|
|
92
|
+
if (length.set) {
|
|
93
|
+
e.lengths[name] = length;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// What every element shares: its name, transform, opacity, clip and mask, and its presentation.
|
|
99
|
+
template <typename P>
|
|
100
|
+
void common(SvgElement &e, const P &p) {
|
|
101
|
+
e.name = p.name;
|
|
102
|
+
e.opacity = p.opacity;
|
|
103
|
+
e.matrix = matrixOf(p.matrix);
|
|
104
|
+
if constexpr (requires { p.clipPath; }) {
|
|
105
|
+
e.clipPath = p.clipPath;
|
|
106
|
+
e.clipRule = p.clipRule;
|
|
107
|
+
e.mask = p.mask;
|
|
108
|
+
e.hidden = p.display == "none";
|
|
109
|
+
}
|
|
110
|
+
if constexpr (requires { p.filter; }) {
|
|
111
|
+
e.filter = p.filter;
|
|
112
|
+
}
|
|
113
|
+
if constexpr (requires { p.markerStart; }) {
|
|
114
|
+
e.markerStart = p.markerStart;
|
|
115
|
+
e.markerMid = p.markerMid;
|
|
116
|
+
e.markerEnd = p.markerEnd;
|
|
117
|
+
}
|
|
118
|
+
if constexpr (requires { p.fill; }) {
|
|
119
|
+
e.color = argbOf(p.color);
|
|
120
|
+
e.propList = p.propList;
|
|
121
|
+
e.fill = svgBrush(p.fill);
|
|
122
|
+
e.fillOpacity = p.fillOpacity;
|
|
123
|
+
e.fillRule = p.fillRule;
|
|
124
|
+
e.stroke = svgBrush(p.stroke);
|
|
125
|
+
e.strokeOpacity = p.strokeOpacity;
|
|
126
|
+
e.strokeWidth = svgLength(p.strokeWidth);
|
|
127
|
+
e.strokeLinecap = p.strokeLinecap;
|
|
128
|
+
e.strokeLinejoin = p.strokeLinejoin;
|
|
129
|
+
e.strokeDasharray = svgLengths(p.strokeDasharray);
|
|
130
|
+
e.strokeDashoffset = p.strokeDashoffset;
|
|
131
|
+
e.strokeMiterlimit = p.strokeMiterlimit;
|
|
132
|
+
}
|
|
133
|
+
if constexpr (requires { p.font; }) {
|
|
134
|
+
const auto &font = p.font;
|
|
135
|
+
auto size = font.isObject() ? font.getDefault("fontSize", nullptr) : folly::dynamic(nullptr);
|
|
136
|
+
e.fontSize = svgLength(size.isNull() ? p.fontSize : size);
|
|
137
|
+
if (font.isObject()) {
|
|
138
|
+
auto family = font.getDefault("fontFamily", "");
|
|
139
|
+
auto weight = font.getDefault("fontWeight", "");
|
|
140
|
+
e.fontFamily = family.isString() ? family.getString() : "";
|
|
141
|
+
e.fontWeight = weight.isString() ? weight.getString() : weight.isNumber() ? std::to_string(weight.asInt()) : "";
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
template <typename P>
|
|
147
|
+
void text(SvgElement &e, const P &p) {
|
|
148
|
+
e.xs = svgLengths(p.x);
|
|
149
|
+
e.ys = svgLengths(p.y);
|
|
150
|
+
e.dxs = svgLengths(p.dx);
|
|
151
|
+
e.dys = svgLengths(p.dy);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// What every filter step shares: its subregion, inputs and result.
|
|
155
|
+
template <typename P>
|
|
156
|
+
void primitive(SvgElement &e, const P &p) {
|
|
157
|
+
lengths(e, {{"x", &p.x}, {"y", &p.y}, {"width", &p.width}, {"height", &p.height}});
|
|
158
|
+
e.result = p.result;
|
|
159
|
+
if constexpr (requires { p.in1; }) {
|
|
160
|
+
e.in1 = p.in1;
|
|
161
|
+
}
|
|
162
|
+
if constexpr (requires { p.in2; }) {
|
|
163
|
+
e.in2 = p.in2;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
template <typename P>
|
|
168
|
+
void viewBox(SvgElement &e, const P &p) {
|
|
169
|
+
e.minX = p.minX;
|
|
170
|
+
e.minY = p.minY;
|
|
171
|
+
e.vbWidth = p.vbWidth;
|
|
172
|
+
e.vbHeight = p.vbHeight;
|
|
173
|
+
e.align = p.align;
|
|
174
|
+
e.meetOrSlice = p.meetOrSlice;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
void stops(SvgElement &e, const GradientProps &p) {
|
|
178
|
+
for (size_t i = 0; i + 1 < p.gradient.size(); i += 2) {
|
|
179
|
+
e.stops.emplace_back(p.gradient[i], static_cast<uint32_t>(static_cast<int64_t>(p.gradient[i + 1])));
|
|
180
|
+
}
|
|
181
|
+
e.units = p.gradientUnits;
|
|
182
|
+
e.gradientTransform = matrixOf(p.gradientTransform);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
std::optional<SvgElement> svgElement(const Props &props) {
|
|
186
|
+
SvgElement e;
|
|
187
|
+
if (const auto *p = dynamic_cast<const RNSVGSvgViewProps *>(&props)) {
|
|
188
|
+
e.kind = SvgKind::Svg;
|
|
189
|
+
e.color = argbOf(p->color);
|
|
190
|
+
e.minX = p->minX;
|
|
191
|
+
e.minY = p->minY;
|
|
192
|
+
e.vbWidth = p->vbWidth;
|
|
193
|
+
e.vbHeight = p->vbHeight;
|
|
194
|
+
e.align = p->align;
|
|
195
|
+
e.meetOrSlice = p->meetOrSlice;
|
|
196
|
+
e.bbWidth = svgLength(p->bbWidth);
|
|
197
|
+
e.bbHeight = svgLength(p->bbHeight);
|
|
198
|
+
return e;
|
|
199
|
+
}
|
|
200
|
+
if (const auto *p = dynamic_cast<const RNSVGGroupProps *>(&props)) {
|
|
201
|
+
e.kind = SvgKind::Group;
|
|
202
|
+
common(e, *p);
|
|
203
|
+
} else if (const auto *p = dynamic_cast<const RNSVGPathProps *>(&props)) {
|
|
204
|
+
e.kind = SvgKind::Path;
|
|
205
|
+
common(e, *p);
|
|
206
|
+
e.d = p->d;
|
|
207
|
+
} else if (const auto *p = dynamic_cast<const RNSVGRectProps *>(&props)) {
|
|
208
|
+
e.kind = SvgKind::Rect;
|
|
209
|
+
common(e, *p);
|
|
210
|
+
lengths(e, {{"x", &p->x}, {"y", &p->y}, {"width", &p->width}, {"height", &p->height}, {"rx", &p->rx}, {"ry", &p->ry}});
|
|
211
|
+
} else if (const auto *p = dynamic_cast<const RNSVGCircleProps *>(&props)) {
|
|
212
|
+
e.kind = SvgKind::Circle;
|
|
213
|
+
common(e, *p);
|
|
214
|
+
lengths(e, {{"cx", &p->cx}, {"cy", &p->cy}, {"r", &p->r}});
|
|
215
|
+
} else if (const auto *p = dynamic_cast<const RNSVGEllipseProps *>(&props)) {
|
|
216
|
+
e.kind = SvgKind::Ellipse;
|
|
217
|
+
common(e, *p);
|
|
218
|
+
lengths(e, {{"cx", &p->cx}, {"cy", &p->cy}, {"rx", &p->rx}, {"ry", &p->ry}});
|
|
219
|
+
} else if (const auto *p = dynamic_cast<const RNSVGLineProps *>(&props)) {
|
|
220
|
+
e.kind = SvgKind::Line;
|
|
221
|
+
common(e, *p);
|
|
222
|
+
lengths(e, {{"x1", &p->x1}, {"y1", &p->y1}, {"x2", &p->x2}, {"y2", &p->y2}});
|
|
223
|
+
} else if (const auto *p = dynamic_cast<const RNSVGUseProps *>(&props)) {
|
|
224
|
+
e.kind = SvgKind::Use;
|
|
225
|
+
common(e, *p);
|
|
226
|
+
e.href = p->href;
|
|
227
|
+
lengths(e, {{"x", &p->x}, {"y", &p->y}, {"width", &p->width}, {"height", &p->height}});
|
|
228
|
+
} else if (const auto *p = dynamic_cast<const RNSVGDefsProps *>(&props)) {
|
|
229
|
+
e.kind = SvgKind::Defs;
|
|
230
|
+
e.name = p->name;
|
|
231
|
+
} else if (const auto *p = dynamic_cast<const GradientProps *>(&props)) {
|
|
232
|
+
bool radial = dynamic_cast<const RadialGradientProps *>(&props) != nullptr;
|
|
233
|
+
e.kind = radial ? SvgKind::RadialGradient : SvgKind::LinearGradient;
|
|
234
|
+
e.name = p->name;
|
|
235
|
+
if (radial) {
|
|
236
|
+
lengths(e, {{"cx", &p->cx}, {"cy", &p->cy}, {"rx", &p->rx}, {"ry", &p->ry}, {"fx", &p->fx}, {"fy", &p->fy}});
|
|
237
|
+
} else {
|
|
238
|
+
lengths(e, {{"x1", &p->x1}, {"y1", &p->y1}, {"x2", &p->x2}, {"y2", &p->y2}});
|
|
239
|
+
}
|
|
240
|
+
stops(e, *p);
|
|
241
|
+
} else if (const auto *p = dynamic_cast<const RNSVGClipPathProps *>(&props)) {
|
|
242
|
+
e.kind = SvgKind::ClipPath;
|
|
243
|
+
common(e, *p);
|
|
244
|
+
} else if (const auto *p = dynamic_cast<const RNSVGMaskProps *>(&props)) {
|
|
245
|
+
e.kind = SvgKind::Mask;
|
|
246
|
+
common(e, *p);
|
|
247
|
+
lengths(e, {{"x", &p->x}, {"y", &p->y}, {"width", &p->width}, {"height", &p->height}});
|
|
248
|
+
e.units = p->maskUnits;
|
|
249
|
+
e.contentUnits = p->maskContentUnits;
|
|
250
|
+
e.maskType = p->maskType;
|
|
251
|
+
} else if (const auto *p = dynamic_cast<const RNSVGSymbolProps *>(&props)) {
|
|
252
|
+
e.kind = SvgKind::Symbol;
|
|
253
|
+
common(e, *p);
|
|
254
|
+
e.minX = p->minX;
|
|
255
|
+
e.minY = p->minY;
|
|
256
|
+
e.vbWidth = p->vbWidth;
|
|
257
|
+
e.vbHeight = p->vbHeight;
|
|
258
|
+
e.align = p->align;
|
|
259
|
+
e.meetOrSlice = p->meetOrSlice;
|
|
260
|
+
} else if (const auto *p = dynamic_cast<const RNSVGImageProps *>(&props)) {
|
|
261
|
+
e.kind = SvgKind::Image;
|
|
262
|
+
common(e, *p);
|
|
263
|
+
lengths(e, {{"x", &p->x}, {"y", &p->y}, {"width", &p->width}, {"height", &p->height}});
|
|
264
|
+
e.uri = p->src.uri;
|
|
265
|
+
e.align = p->align;
|
|
266
|
+
e.meetOrSlice = p->meetOrSlice;
|
|
267
|
+
} else if (const auto *p = dynamic_cast<const RNSVGTextProps *>(&props)) {
|
|
268
|
+
e.kind = SvgKind::Text;
|
|
269
|
+
common(e, *p);
|
|
270
|
+
text(e, *p);
|
|
271
|
+
} else if (const auto *p = dynamic_cast<const RNSVGTSpanProps *>(&props)) {
|
|
272
|
+
e.kind = SvgKind::TSpan;
|
|
273
|
+
common(e, *p);
|
|
274
|
+
text(e, *p);
|
|
275
|
+
e.content = p->content;
|
|
276
|
+
} else if (const auto *p = dynamic_cast<const RNSVGMarkerProps *>(&props)) {
|
|
277
|
+
e.kind = SvgKind::Marker;
|
|
278
|
+
common(e, *p);
|
|
279
|
+
lengths(e, {{"refX", &p->refX}, {"refY", &p->refY}, {"markerWidth", &p->markerWidth}, {"markerHeight", &p->markerHeight}});
|
|
280
|
+
e.markerUnits = p->markerUnits;
|
|
281
|
+
e.orient = p->orient;
|
|
282
|
+
viewBox(e, *p);
|
|
283
|
+
} else if (const auto *p = dynamic_cast<const RNSVGPatternProps *>(&props)) {
|
|
284
|
+
e.kind = SvgKind::Pattern;
|
|
285
|
+
common(e, *p);
|
|
286
|
+
// A pattern's transform is its patternTransform, never the element's own.
|
|
287
|
+
e.matrix.reset();
|
|
288
|
+
lengths(e, {{"x", &p->x}, {"y", &p->y}, {"width", &p->width}, {"height", &p->height}});
|
|
289
|
+
e.units = p->patternUnits;
|
|
290
|
+
e.contentUnits = p->patternContentUnits;
|
|
291
|
+
e.gradientTransform = matrixOf(p->patternTransform);
|
|
292
|
+
viewBox(e, *p);
|
|
293
|
+
} else if (const auto *p = dynamic_cast<const RNSVGFilterProps *>(&props)) {
|
|
294
|
+
e.kind = SvgKind::Filter;
|
|
295
|
+
e.name = p->name;
|
|
296
|
+
lengths(e, {{"x", &p->x}, {"y", &p->y}, {"width", &p->width}, {"height", &p->height}});
|
|
297
|
+
e.units = p->filterUnits == RNSVGFilterFilterUnits::ObjectBoundingBox ? 0 : 1;
|
|
298
|
+
e.contentUnits = p->primitiveUnits == RNSVGFilterPrimitiveUnits::ObjectBoundingBox ? 0 : 1;
|
|
299
|
+
} else if (const auto *p = dynamic_cast<const RNSVGFeGaussianBlurProps *>(&props)) {
|
|
300
|
+
e.kind = SvgKind::FeGaussianBlur;
|
|
301
|
+
primitive(e, *p);
|
|
302
|
+
e.stdDeviationX = p->stdDeviationX;
|
|
303
|
+
e.stdDeviationY = p->stdDeviationY;
|
|
304
|
+
} else if (const auto *p = dynamic_cast<const RNSVGFeOffsetProps *>(&props)) {
|
|
305
|
+
e.kind = SvgKind::FeOffset;
|
|
306
|
+
primitive(e, *p);
|
|
307
|
+
lengths(e, {{"dx", &p->dx}, {"dy", &p->dy}});
|
|
308
|
+
} else if (const auto *p = dynamic_cast<const RNSVGFeColorMatrixProps *>(&props)) {
|
|
309
|
+
e.kind = SvgKind::FeColorMatrix;
|
|
310
|
+
primitive(e, *p);
|
|
311
|
+
e.op = static_cast<int>(p->type);
|
|
312
|
+
e.values.assign(p->values.begin(), p->values.end());
|
|
313
|
+
} else if (const auto *p = dynamic_cast<const RNSVGFeFloodProps *>(&props)) {
|
|
314
|
+
e.kind = SvgKind::FeFlood;
|
|
315
|
+
primitive(e, *p);
|
|
316
|
+
if (auto flood = svgBrush(p->floodColor); flood.type == SvgBrush::Type::Color) {
|
|
317
|
+
e.flood = flood;
|
|
318
|
+
}
|
|
319
|
+
e.floodOpacity = p->floodOpacity;
|
|
320
|
+
} else if (const auto *p = dynamic_cast<const RNSVGFeCompositeProps *>(&props)) {
|
|
321
|
+
e.kind = SvgKind::FeComposite;
|
|
322
|
+
primitive(e, *p);
|
|
323
|
+
e.op = static_cast<int>(p->operator1);
|
|
324
|
+
e.k = {p->k1, p->k2, p->k3, p->k4};
|
|
325
|
+
} else if (const auto *p = dynamic_cast<const RNSVGFeMergeProps *>(&props)) {
|
|
326
|
+
e.kind = SvgKind::FeMerge;
|
|
327
|
+
primitive(e, *p);
|
|
328
|
+
e.nodes = p->nodes;
|
|
329
|
+
} else {
|
|
330
|
+
return std::nullopt;
|
|
331
|
+
}
|
|
332
|
+
return e;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
} // namespace
|
|
336
|
+
|
|
337
|
+
void installGlue_rnsvg() {
|
|
338
|
+
auto &glue = libraryGlue();
|
|
339
|
+
glue.svgElement = svgElement;
|
|
340
|
+
glue.components.push_back(concreteComponentDescriptorProvider<RNSVGSvgViewComponentDescriptor>());
|
|
341
|
+
glue.components.push_back(concreteComponentDescriptorProvider<ConcreteComponentDescriptor<LinearGradientShadowNode>>());
|
|
342
|
+
glue.components.push_back(concreteComponentDescriptorProvider<ConcreteComponentDescriptor<RadialGradientShadowNode>>());
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
} // namespace ngn
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// The core's writing of react-native-safe-area-context's state, compiled into the host only with
|
|
2
|
+
// the library (cmake/libraries.cmake).
|
|
3
|
+
#include "ngn/library-glue.h"
|
|
4
|
+
|
|
5
|
+
#include <algorithm>
|
|
6
|
+
|
|
7
|
+
#include <react/renderer/components/safeareacontext/Props.h>
|
|
8
|
+
#include <react/renderer/components/safeareacontext/RNCSafeAreaViewState.h>
|
|
9
|
+
#include <react/renderer/core/ConcreteState.h>
|
|
10
|
+
|
|
11
|
+
using namespace facebook::react;
|
|
12
|
+
|
|
13
|
+
namespace ngn {
|
|
14
|
+
|
|
15
|
+
namespace {
|
|
16
|
+
|
|
17
|
+
// How far an edge's margin moves the view for its inset, as RNCSafeAreaViewShadowNode sets it: the
|
|
18
|
+
// inset added to the style's margin, the larger of the two ("maximum"), or nothing ("off").
|
|
19
|
+
float moved(const std::string &mode, float inset, const facebook::yoga::Style::Length &style) {
|
|
20
|
+
float margin = style.value().unwrapOrDefault(0);
|
|
21
|
+
if (mode == "off") {
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
if (mode == "maximum") {
|
|
25
|
+
return std::max(inset, margin) - margin;
|
|
26
|
+
}
|
|
27
|
+
return inset;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
facebook::yoga::Style::Length marginOf(const facebook::yoga::Style &style, facebook::yoga::Edge edge, facebook::yoga::Edge axis) {
|
|
31
|
+
if (style.margin(edge).isDefined()) {
|
|
32
|
+
return style.margin(edge);
|
|
33
|
+
}
|
|
34
|
+
return style.margin(axis).isDefined() ? style.margin(axis) : style.margin(facebook::yoga::Edge::All);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
} // namespace
|
|
38
|
+
|
|
39
|
+
void installGlue_safeareacontext() {
|
|
40
|
+
libraryGlue().safeAreaStates.emplace_back([](const State &state, EdgeInsets insets) {
|
|
41
|
+
const auto *concrete = dynamic_cast<const ConcreteState<RNCSafeAreaViewState> *>(&state);
|
|
42
|
+
if (concrete == nullptr) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
RNCSafeAreaViewState data;
|
|
46
|
+
data.insets = insets;
|
|
47
|
+
concrete->updateState(std::move(data));
|
|
48
|
+
return true;
|
|
49
|
+
});
|
|
50
|
+
// In margin mode the view moves itself by its insets; in padding mode it does not.
|
|
51
|
+
libraryGlue().safeAreaMargins.emplace_back([](const ShadowView &view) -> std::optional<EdgeInsets> {
|
|
52
|
+
const auto *props = dynamic_cast<const RNCSafeAreaViewProps *>(view.props.get());
|
|
53
|
+
const auto *state = dynamic_cast<const ConcreteState<RNCSafeAreaViewState> *>(view.state.get());
|
|
54
|
+
if (props == nullptr || state == nullptr || props->mode != RNCSafeAreaViewMode::Margin) {
|
|
55
|
+
return std::nullopt;
|
|
56
|
+
}
|
|
57
|
+
auto insets = state->getData().insets;
|
|
58
|
+
const auto &style = props->yogaStyle;
|
|
59
|
+
const auto &edges = props->edges;
|
|
60
|
+
using facebook::yoga::Edge;
|
|
61
|
+
return EdgeInsets{
|
|
62
|
+
.left = moved(edges.left, insets.left, marginOf(style, Edge::Left, Edge::Horizontal)),
|
|
63
|
+
.top = moved(edges.top, insets.top, marginOf(style, Edge::Top, Edge::Vertical)),
|
|
64
|
+
.right = moved(edges.right, insets.right, marginOf(style, Edge::Right, Edge::Horizontal)),
|
|
65
|
+
.bottom = moved(edges.bottom, insets.bottom, marginOf(style, Edge::Bottom, Edge::Vertical)),
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
} // namespace ngn
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Evaluated on react-native-worklets' UI runtime as it starts (react-native-worklets.cpp).
|
|
2
|
+
//
|
|
3
|
+
// The library's UI runtime asks the host for a frame at the end of every frame it flushes, whether
|
|
4
|
+
// or not anything waits for one, so a display link that serves it never stops. Here the request
|
|
5
|
+
// that ends a frame which queued no work is parked instead, and asking for a frame or queueing a
|
|
6
|
+
// microtask wakes it. A finalizer does not: Reanimated's mappers queue one every frame. Work that
|
|
7
|
+
// runs outside a frame (a job sent to the UI runtime, a gesture's event), which can change a shared
|
|
8
|
+
// value its mappers read, wakes it through `__ngnWakeFrames`, which the host calls after it. A
|
|
9
|
+
// still app then takes no frames.
|
|
10
|
+
//
|
|
11
|
+
// The runtime may set its queue up after this runs, replacing the functions wrapped here, so they
|
|
12
|
+
// are wrapped again whenever the loop asks for a frame and finds them unwrapped.
|
|
13
|
+
(function parkIdleFrames(global) {
|
|
14
|
+
if (global.__ngnIdleFramesParked) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
global.__ngnIdleFramesParked = true;
|
|
18
|
+
var nativeRequest = global.__nativeRequestAnimationFrame;
|
|
19
|
+
var parked = null;
|
|
20
|
+
// Until the queue is set up, every request goes through.
|
|
21
|
+
var work = true;
|
|
22
|
+
|
|
23
|
+
function wake() {
|
|
24
|
+
work = true;
|
|
25
|
+
if (parked !== null) {
|
|
26
|
+
var callback = parked;
|
|
27
|
+
parked = null;
|
|
28
|
+
work = false;
|
|
29
|
+
nativeRequest(callback);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function waking(name) {
|
|
34
|
+
var original = global[name];
|
|
35
|
+
if (typeof original !== 'function' || original.__ngnWakes) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
var wrapped = function () {
|
|
39
|
+
var result = original.apply(this, arguments);
|
|
40
|
+
wake();
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
wrapped.__ngnWakes = true;
|
|
44
|
+
global[name] = wrapped;
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function wrapAll() {
|
|
49
|
+
var any = waking('requestAnimationFrame');
|
|
50
|
+
any = waking('queueMicrotask') || any;
|
|
51
|
+
return any;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
global.__ngnWakeFrames = wake;
|
|
55
|
+
|
|
56
|
+
// The loop's own request for the next frame.
|
|
57
|
+
global.__nativeRequestAnimationFrame = function (callback) {
|
|
58
|
+
// Freshly set up: this frame is the loop's first, and goes through.
|
|
59
|
+
if (wrapAll()) {
|
|
60
|
+
work = true;
|
|
61
|
+
}
|
|
62
|
+
if (work) {
|
|
63
|
+
work = false;
|
|
64
|
+
nativeRequest(callback);
|
|
65
|
+
} else {
|
|
66
|
+
parked = callback;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
wrapAll();
|
|
70
|
+
})(globalThis);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#include "ngn/library-glue.h"
|
|
2
|
+
|
|
3
|
+
namespace ngn {
|
|
4
|
+
|
|
5
|
+
LibraryGlue &libraryGlue() {
|
|
6
|
+
static LibraryGlue glue;
|
|
7
|
+
return glue;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
std::optional<HeaderBar> headerBar(const facebook::react::Props &props) {
|
|
11
|
+
const auto &read = libraryGlue().headerBar;
|
|
12
|
+
return read ? read(props) : std::nullopt;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
std::optional<std::string> headerItemType(const facebook::react::Props &props) {
|
|
16
|
+
const auto &read = libraryGlue().headerItemType;
|
|
17
|
+
return read ? read(props) : std::nullopt;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
std::optional<SearchBarConfig> searchBarConfig(const facebook::react::Props &props) {
|
|
21
|
+
const auto &read = libraryGlue().searchBarConfig;
|
|
22
|
+
return read ? read(props) : std::nullopt;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
std::optional<TabScreen> tabScreen(const facebook::react::Props &props) {
|
|
26
|
+
const auto &read = libraryGlue().tabScreen;
|
|
27
|
+
return read ? read(props) : std::nullopt;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
std::optional<TabsRequest> tabsRequest(const facebook::react::Props &props) {
|
|
31
|
+
const auto &read = libraryGlue().tabsRequest;
|
|
32
|
+
return read ? read(props) : std::nullopt;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
} // namespace ngn
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#include "ngn/live-regions.h"
|
|
2
|
+
|
|
3
|
+
#include <react/renderer/components/view/ViewProps.h>
|
|
4
|
+
|
|
5
|
+
using namespace facebook::react;
|
|
6
|
+
|
|
7
|
+
namespace ngn {
|
|
8
|
+
|
|
9
|
+
namespace {
|
|
10
|
+
|
|
11
|
+
const ViewProps *viewProps(const ShadowView &view) {
|
|
12
|
+
return dynamic_cast<const ViewProps *>(view.props.get());
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
bool hidden(const ViewProps &props) {
|
|
16
|
+
return props.accessibilityElementsHidden ||
|
|
17
|
+
props.importantForAccessibility == ImportantForAccessibility::NoHideDescendants;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
void append(std::string &out, const std::string &text) {
|
|
21
|
+
if (text.empty()) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (!out.empty()) {
|
|
25
|
+
out += ' ';
|
|
26
|
+
}
|
|
27
|
+
out += text;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
} // namespace
|
|
31
|
+
|
|
32
|
+
LiveRegions::LiveRegions(const ViewTree &tree, TextOf textOf) : tree_(tree), textOf_(std::move(textOf)) {}
|
|
33
|
+
|
|
34
|
+
void LiveRegions::update(const ShadowView &view) {
|
|
35
|
+
const auto *props = viewProps(view);
|
|
36
|
+
auto live = props ? props->accessibilityLiveRegion : AccessibilityLiveRegion::None;
|
|
37
|
+
if (live == AccessibilityLiveRegion::None) {
|
|
38
|
+
regions_.erase(view.tag);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
auto priority = live == AccessibilityLiveRegion::Assertive ? AnnouncementPriority::High : AnnouncementPriority::Medium;
|
|
42
|
+
auto [it, added] = regions_.try_emplace(view.tag, Region{view.surfaceId, priority, "", true});
|
|
43
|
+
it->second.priority = priority;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
void LiveRegions::remove(Tag tag) {
|
|
47
|
+
regions_.erase(tag);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
std::vector<Announcement> LiveRegions::didMount(SurfaceId surfaceId) {
|
|
51
|
+
std::vector<Announcement> said;
|
|
52
|
+
for (auto &[tag, region] : regions_) {
|
|
53
|
+
if (region.surfaceId != surfaceId || !tree_.contains(tag)) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
// A hidden region, or one under a hidden view or a covered screen, says nothing, and what it
|
|
57
|
+
// held stays the text its next change is compared with.
|
|
58
|
+
if (hiddenAt(tag)) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
auto text = textOf(tag);
|
|
62
|
+
bool news = !region.fresh && !text.empty() && text != region.text;
|
|
63
|
+
region.fresh = false;
|
|
64
|
+
region.text = text;
|
|
65
|
+
if (news) {
|
|
66
|
+
said.push_back({text, region.priority});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return said;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
bool LiveRegions::hiddenAt(Tag tag) const {
|
|
73
|
+
for (const auto *node = tree_.find(tag); node != nullptr; node = tree_.find(node->parent)) {
|
|
74
|
+
// A covered screen (an unselected tab, a screen under a pushed one) is out of the
|
|
75
|
+
// accessibility tree, as a hidden view is.
|
|
76
|
+
if (tree_.covered(node->view.tag)) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
if (const auto *props = viewProps(node->view); props && hidden(*props)) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
std::string LiveRegions::textOf(Tag tag) const {
|
|
87
|
+
const auto *node = tree_.find(tag);
|
|
88
|
+
if (node == nullptr) {
|
|
89
|
+
return "";
|
|
90
|
+
}
|
|
91
|
+
if (const auto *props = viewProps(node->view); props && !props->accessibilityLabel.empty()) {
|
|
92
|
+
return props->accessibilityLabel;
|
|
93
|
+
}
|
|
94
|
+
std::string out;
|
|
95
|
+
append(out, textOf_(node->view));
|
|
96
|
+
for (auto child : node->children) {
|
|
97
|
+
collect(child, out);
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
void LiveRegions::collect(Tag tag, std::string &out) const {
|
|
103
|
+
const auto *node = tree_.find(tag);
|
|
104
|
+
// A covered screen inside a shown region (an unselected tab's) is not read out with it.
|
|
105
|
+
if (node == nullptr || tree_.covered(tag)) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const auto *props = viewProps(node->view);
|
|
109
|
+
if (props && hidden(*props)) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (props && !props->accessibilityLabel.empty()) {
|
|
113
|
+
append(out, props->accessibilityLabel);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
append(out, textOf_(node->view));
|
|
117
|
+
for (auto child : node->children) {
|
|
118
|
+
collect(child, out);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
} // namespace ngn
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#include "ngn/module-registry.h"
|
|
2
|
+
|
|
3
|
+
#include "ngn/library-glue.h"
|
|
4
|
+
|
|
5
|
+
#include <ReactCommon/CxxTurboModuleUtils.h>
|
|
6
|
+
|
|
7
|
+
using namespace facebook::react;
|
|
8
|
+
|
|
9
|
+
namespace ngn {
|
|
10
|
+
|
|
11
|
+
void ModuleRegistry::add(const std::string &name, Factory factory) {
|
|
12
|
+
factories_[name] = std::move(factory);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
void ModuleRegistry::addProvider(std::shared_ptr<ModuleProvider> provider) {
|
|
16
|
+
providers_.push_back(std::move(provider));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
std::shared_ptr<TurboModule> ModuleRegistry::module(
|
|
20
|
+
const std::string &name,
|
|
21
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) const {
|
|
22
|
+
for (const auto &provider : providers_) {
|
|
23
|
+
if (auto module = provider->module(name, jsInvoker)) {
|
|
24
|
+
return module;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (auto it = factories_.find(name); it != factories_.end()) {
|
|
28
|
+
return it->second(jsInvoker);
|
|
29
|
+
}
|
|
30
|
+
const auto &glue = libraryGlue().modules;
|
|
31
|
+
if (auto it = glue.find(name); it != glue.end()) {
|
|
32
|
+
return it->second(jsInvoker);
|
|
33
|
+
}
|
|
34
|
+
// Autolinked libraries' and the app's own modules, which register themselves as they load, the
|
|
35
|
+
// way React Native's iOS host finds a C++ TurboModule.
|
|
36
|
+
auto &linked = globalExportedCxxTurboModuleMap();
|
|
37
|
+
if (auto it = linked.find(name); it != linked.end()) {
|
|
38
|
+
return it->second(jsInvoker);
|
|
39
|
+
}
|
|
40
|
+
return nullptr;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// The registry must outlive the ReactHost it is given to.
|
|
44
|
+
TurboModuleProviders ModuleRegistry::providers() const {
|
|
45
|
+
return {[this](const std::string &name, const std::shared_ptr<CallInvoker> &jsInvoker) {
|
|
46
|
+
return module(name, jsInvoker);
|
|
47
|
+
}};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
} // namespace ngn
|