@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,420 @@
|
|
|
1
|
+
#include "ngn/runtime.h"
|
|
2
|
+
|
|
3
|
+
#include "ngn/worklet-host.h"
|
|
4
|
+
#include "red-box-errors.h"
|
|
5
|
+
|
|
6
|
+
#include <react/featureflags/ReactNativeFeatureFlags.h>
|
|
7
|
+
#include <react/featureflags/ReactNativeFeatureFlagsDefaults.h>
|
|
8
|
+
#include <react/http/IHttpClient.h>
|
|
9
|
+
#include <react/http/IWebSocketClient.h>
|
|
10
|
+
#include <react/logging/DefaultOnJsErrorHandler.h>
|
|
11
|
+
#include <react/renderer/scheduler/Scheduler.h>
|
|
12
|
+
#include <react/renderer/uimanager/UIManager.h>
|
|
13
|
+
#include <react/devsupport/IDevUIDelegate.h>
|
|
14
|
+
#include <react/runtime/ReactHost.h>
|
|
15
|
+
#include <react/utils/RunLoopObserverManager.h>
|
|
16
|
+
|
|
17
|
+
#include <glog/logging.h>
|
|
18
|
+
#include <jsi/JSIDynamic.h>
|
|
19
|
+
|
|
20
|
+
#include <set>
|
|
21
|
+
#include <thread>
|
|
22
|
+
|
|
23
|
+
using namespace facebook::react;
|
|
24
|
+
namespace jsi = facebook::jsi;
|
|
25
|
+
|
|
26
|
+
namespace ngn {
|
|
27
|
+
|
|
28
|
+
namespace {
|
|
29
|
+
|
|
30
|
+
// HermesInstance installs a microtask queue only for bridgeless, which React Native's scheduler
|
|
31
|
+
// needs on its first render. (The same override Basalt makes.)
|
|
32
|
+
class FeatureFlags final : public ReactNativeFeatureFlagsDefaults {
|
|
33
|
+
public:
|
|
34
|
+
bool enableBridgelessArchitecture() override {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// React Native's dev UI as the host has it: the debugger's pause, handed to the runtime's owner.
|
|
40
|
+
// The bundle's download progress and loading view are left to the app (DevLoadingView).
|
|
41
|
+
class DevUI final : public IDevUIDelegate {
|
|
42
|
+
public:
|
|
43
|
+
explicit DevUI(std::function<void(std::function<void()>)> &paused, std::function<void()> &resumed)
|
|
44
|
+
: paused_(paused), resumed_(resumed) {}
|
|
45
|
+
void showDownloadBundleProgress() override {}
|
|
46
|
+
void hideDownloadBundleProgress() override {}
|
|
47
|
+
void showLoadingView(const std::string &, SharedColor, SharedColor) override {}
|
|
48
|
+
void hideLoadingView() override {}
|
|
49
|
+
void showDebuggerOverlay(std::function<void()> &&resume) override {
|
|
50
|
+
if (paused_) {
|
|
51
|
+
paused_(std::move(resume));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
void hideDebuggerOverlay() override {
|
|
55
|
+
if (resumed_) {
|
|
56
|
+
resumed_();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private:
|
|
61
|
+
std::function<void(std::function<void()>)> &paused_;
|
|
62
|
+
std::function<void()> &resumed_;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
LayoutContext context(const SurfaceMetrics &metrics) {
|
|
66
|
+
LayoutContext context;
|
|
67
|
+
context.pointScaleFactor = metrics.pointScale;
|
|
68
|
+
context.fontSizeMultiplier = metrics.fontScale;
|
|
69
|
+
return context;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
} // namespace
|
|
73
|
+
|
|
74
|
+
Runtime::Runtime(
|
|
75
|
+
std::shared_ptr<MountingManager> mounting,
|
|
76
|
+
std::shared_ptr<const TextMeasurer> textMeasurer,
|
|
77
|
+
std::shared_ptr<const ControlMeasurer> controlMeasurer,
|
|
78
|
+
std::shared_ptr<ModuleRegistry> modules,
|
|
79
|
+
NetworkClients clients,
|
|
80
|
+
std::string bundle,
|
|
81
|
+
DebuggerIdentity identity)
|
|
82
|
+
: mounting_(std::move(mounting)),
|
|
83
|
+
textMeasurer_(std::move(textMeasurer)),
|
|
84
|
+
controlMeasurer_(std::move(controlMeasurer)),
|
|
85
|
+
modules_(std::move(modules)),
|
|
86
|
+
clients_(std::move(clients)),
|
|
87
|
+
bundle_(std::move(bundle)),
|
|
88
|
+
identity_(std::move(identity)),
|
|
89
|
+
devServer_(DevServer::fromBundleUrl(bundle_)),
|
|
90
|
+
runLoop_(std::make_shared<RunLoopObserverManager>()),
|
|
91
|
+
// The mounting manager, not this runtime: the reload thread's tasks may run after it is gone.
|
|
92
|
+
reloader_([mounting = mounting_](std::function<void()> task) { mounting->runOnUiThread(std::move(task)); }) {
|
|
93
|
+
// As React Native iOS's surface presenter does after each mount: the UIManager's mount hooks
|
|
94
|
+
// (Reanimated's, which holds its own commits while React's are unmounted, and the observers')
|
|
95
|
+
// learn the views are there. UI thread; skipped while a reload holds the host.
|
|
96
|
+
mounting_->setAfterMountCallback([this](SurfaceId surfaceId) {
|
|
97
|
+
std::unique_lock lock(mutex_, std::try_to_lock);
|
|
98
|
+
if (lock.owns_lock() && host_ && !reloading_) {
|
|
99
|
+
host_->runOnScheduler([surfaceId](Scheduler &scheduler) { scheduler.reportMount(surfaceId); });
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
static bool flagsSet = false;
|
|
103
|
+
if (!flagsSet) {
|
|
104
|
+
ReactNativeFeatureFlags::override(std::make_unique<FeatureFlags>());
|
|
105
|
+
flagsSet = true;
|
|
106
|
+
}
|
|
107
|
+
createHost();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
void Runtime::createHost() {
|
|
111
|
+
auto contextContainer = std::make_shared<ContextContainer>();
|
|
112
|
+
contextContainer->insert(
|
|
113
|
+
HttpClientFactoryKey, clients_.http ? httpClientFactory(clients_.http) : getHttpClientFactory());
|
|
114
|
+
contextContainer->insert(
|
|
115
|
+
WebSocketClientFactoryKey,
|
|
116
|
+
clients_.webSockets ? webSocketClientFactory(clients_.webSockets) : getWebSocketClientFactory());
|
|
117
|
+
installTextMeasurer(*contextContainer, textMeasurer_);
|
|
118
|
+
// Mounts from here on are this instance's (MountingManager::mountedBy).
|
|
119
|
+
mounting_->beginInstance();
|
|
120
|
+
installControlSizes(*contextContainer, mounting_->startControlSizes(controlMeasurer_));
|
|
121
|
+
// react-native-screens' header and tabs descriptors read React Native iOS's image loader from
|
|
122
|
+
// here as they adopt a node, and throw when it is missing. They only keep it, for iOS's own
|
|
123
|
+
// views, so nothing stands in for it.
|
|
124
|
+
contextContainer->insert("RCTImageLoader", std::shared_ptr<void>{});
|
|
125
|
+
|
|
126
|
+
ReactInstanceConfig config;
|
|
127
|
+
config.appId = identity_.appId;
|
|
128
|
+
config.deviceName = identity_.deviceName;
|
|
129
|
+
// Dev mode is what makes ReactHost load from the dev server, connect to /message for reload and
|
|
130
|
+
// set up the HMR client; a bundle on disk runs without it.
|
|
131
|
+
config.enableDevMode = devServer_.has_value();
|
|
132
|
+
// The inspector registers the app with the dev server's inspector proxy (its /json/list), which
|
|
133
|
+
// React Native DevTools connects to. Only with a dev server; Release builds have no debugger.
|
|
134
|
+
#ifdef NGN_INSPECTOR
|
|
135
|
+
config.enableInspector = devServer_.has_value();
|
|
136
|
+
#else
|
|
137
|
+
config.enableInspector = false;
|
|
138
|
+
#endif
|
|
139
|
+
if (devServer_) {
|
|
140
|
+
config.devServerHost = devServer_->host;
|
|
141
|
+
config.devServerPort = devServer_->port;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
host_ = std::make_unique<ReactHost>(
|
|
145
|
+
config,
|
|
146
|
+
mounting_,
|
|
147
|
+
runLoop_,
|
|
148
|
+
contextContainer,
|
|
149
|
+
getDefaultOnJsErrorFunc(),
|
|
150
|
+
[](const std::string &message, unsigned int level) { LOG(INFO) << "[js:" << level << "] " << message; },
|
|
151
|
+
std::make_shared<DevUI>(onDebuggerPaused, onDebuggerResumed),
|
|
152
|
+
modules_->providers(),
|
|
153
|
+
nullptr,
|
|
154
|
+
nullptr,
|
|
155
|
+
devServer_ ? ReactInstance::BindingsInstallFunc([this](jsi::Runtime &runtime) { installErrorListener(runtime); })
|
|
156
|
+
: nullptr);
|
|
157
|
+
// Reanimated reaches the UIManager through here as it installs (worklet-host.h).
|
|
158
|
+
auto *host = host_.get();
|
|
159
|
+
workletHost().runOnScheduler.set([host](std::function<void(Scheduler &)> task) { host->runOnScheduler(std::move(task)); });
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
Runtime::~Runtime() {
|
|
163
|
+
shutdown();
|
|
164
|
+
*alive_ = false;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Before the bundle runs, so the listener is the pipeline's first: LogBox, which an Angular app
|
|
168
|
+
// never draws, prevents the default handling of the errors it takes, but every listener still
|
|
169
|
+
// hears them.
|
|
170
|
+
void Runtime::installErrorListener(jsi::Runtime &runtime) {
|
|
171
|
+
if (onInstanceStart) {
|
|
172
|
+
onInstanceStart();
|
|
173
|
+
}
|
|
174
|
+
auto report = [this](jsi::Runtime &rt, const jsi::Value &error, bool console) {
|
|
175
|
+
if (!error.isObject() || !onJsError) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
auto data = jsi::dynamicFromValue(rt, error);
|
|
180
|
+
if (console) {
|
|
181
|
+
data["source"] = "console";
|
|
182
|
+
}
|
|
183
|
+
onJsError(data);
|
|
184
|
+
} catch (const std::exception &e) {
|
|
185
|
+
LOG(WARNING) << "ngn: an error could not be read for the red box: " << e.what();
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
// Errors the pipeline does not see once the runtime is ready: console.error's and ErrorUtils'.
|
|
189
|
+
try {
|
|
190
|
+
auto install = runtime.evaluateJavaScript(std::make_shared<jsi::StringBuffer>(kRedBoxErrors), "ngn-red-box-errors.js");
|
|
191
|
+
install.asObject(runtime).asFunction(runtime).call(
|
|
192
|
+
runtime,
|
|
193
|
+
jsi::Function::createFromHostFunction(
|
|
194
|
+
runtime,
|
|
195
|
+
jsi::PropNameID::forAscii(runtime, "ngnReportError"),
|
|
196
|
+
1,
|
|
197
|
+
[report](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t count) {
|
|
198
|
+
if (count > 0) {
|
|
199
|
+
report(rt, args[0], true);
|
|
200
|
+
}
|
|
201
|
+
return jsi::Value::undefined();
|
|
202
|
+
}));
|
|
203
|
+
} catch (const std::exception &e) {
|
|
204
|
+
LOG(WARNING) << "ngn: the red box's error hook did not install: " << e.what();
|
|
205
|
+
}
|
|
206
|
+
auto global = runtime.global();
|
|
207
|
+
auto registerListener = global.getProperty(runtime, "RN$registerExceptionListener");
|
|
208
|
+
if (!registerListener.isObject() || !registerListener.asObject(runtime).isFunction(runtime)) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
auto listener = jsi::Function::createFromHostFunction(
|
|
212
|
+
runtime,
|
|
213
|
+
jsi::PropNameID::forAscii(runtime, "ngnRedBox"),
|
|
214
|
+
1,
|
|
215
|
+
[report](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t count) {
|
|
216
|
+
if (count > 0) {
|
|
217
|
+
report(rt, args[0], false);
|
|
218
|
+
}
|
|
219
|
+
return jsi::Value::undefined();
|
|
220
|
+
});
|
|
221
|
+
registerListener.asObject(runtime).asFunction(runtime).call(runtime, std::move(listener));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
void Runtime::openDebugger() {
|
|
225
|
+
std::lock_guard lock(mutex_);
|
|
226
|
+
if (host_ && devServer_) {
|
|
227
|
+
host_->openDebugger();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
bool Runtime::loadBundle() {
|
|
232
|
+
std::lock_guard lock(mutex_);
|
|
233
|
+
if (!host_) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
// With dev mode on, ReactHost downloads the source path through the dev server helper, which
|
|
237
|
+
// takes the bundle URL as it is.
|
|
238
|
+
direction_.instanceStarted();
|
|
239
|
+
return devServer_ ? host_->loadScript("", bundle_) : host_->loadScript(bundle_, bundle_);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
void Runtime::startSurface(SurfaceId surfaceId, const std::string &moduleName, const SurfaceMetrics &metrics) {
|
|
243
|
+
std::lock_guard book(surfacesMutex_);
|
|
244
|
+
if (!surfaces_.start(surfaceId, {moduleName, metrics})) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
std::lock_guard lock(mutex_);
|
|
248
|
+
if (host_) {
|
|
249
|
+
host_->startSurface(surfaceId, moduleName, folly::dynamic::object(), surfaceConstraints(metrics, direction_.rightToLeft()), context(metrics));
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
void Runtime::stopSurface(SurfaceId surfaceId) {
|
|
254
|
+
std::lock_guard book(surfacesMutex_);
|
|
255
|
+
if (!surfaces_.stop(surfaceId)) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
std::lock_guard lock(mutex_);
|
|
259
|
+
if (host_) {
|
|
260
|
+
host_->stopSurface(surfaceId);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
void Runtime::updateSurface(SurfaceId surfaceId, const SurfaceMetrics &metrics) {
|
|
265
|
+
std::lock_guard book(surfacesMutex_);
|
|
266
|
+
// During a reload the restarted surface takes the metrics recorded here.
|
|
267
|
+
if (!surfaces_.update(surfaceId, [&](Surface &surface) { surface.metrics = metrics; })) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
std::lock_guard lock(mutex_);
|
|
271
|
+
if (host_) {
|
|
272
|
+
host_->setSurfaceConstraints(surfaceId, surfaceConstraints(metrics, direction_.rightToLeft()), context(metrics));
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
std::optional<SheetNode> Runtime::sheetNode(SurfaceId surfaceId, Tag tag) {
|
|
277
|
+
std::unique_lock lock(mutex_, std::try_to_lock);
|
|
278
|
+
std::optional<SheetNode> found;
|
|
279
|
+
if (!lock.owns_lock() || !host_ || reloading_) {
|
|
280
|
+
return found;
|
|
281
|
+
}
|
|
282
|
+
host_->runOnScheduler([&](Scheduler &scheduler) {
|
|
283
|
+
scheduler.getUIManager()->getShadowTreeRegistry().visit(surfaceId, [&](const ShadowTree &tree) {
|
|
284
|
+
std::function<const ShadowNode *(const ShadowNode &)> find = [&](const ShadowNode &node) -> const ShadowNode * {
|
|
285
|
+
if (node.getTag() == tag) {
|
|
286
|
+
return &node;
|
|
287
|
+
}
|
|
288
|
+
for (const auto &child : node.getChildren()) {
|
|
289
|
+
if (const auto *hit = find(*child)) {
|
|
290
|
+
return hit;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return nullptr;
|
|
294
|
+
};
|
|
295
|
+
auto root = tree.getCurrentRevision().rootShadowNode;
|
|
296
|
+
if (const auto *node = root ? find(*root) : nullptr) {
|
|
297
|
+
found = ngn::sheetNode(*node);
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
return found;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
void Runtime::animationTick() {
|
|
305
|
+
// A frame skipped while a reload holds the host is no loss; reading host_ without the lock is.
|
|
306
|
+
std::unique_lock lock(mutex_, std::try_to_lock);
|
|
307
|
+
if (lock.owns_lock() && host_ && !reloading_) {
|
|
308
|
+
host_->runOnScheduler([](Scheduler &scheduler) { scheduler.animationTick(); });
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
void Runtime::beat() {
|
|
313
|
+
if (!reloading_) {
|
|
314
|
+
runLoop_->onRender();
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
void Runtime::reload(std::function<void(bool)> done) {
|
|
319
|
+
{
|
|
320
|
+
std::lock_guard book(surfacesMutex_);
|
|
321
|
+
if (!surfaces_.beginReload()) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
reloading_ = true;
|
|
325
|
+
}
|
|
326
|
+
// Tearing down waits for the JS thread and the download blocks, so neither runs on the UI
|
|
327
|
+
// thread, whose queue the mounting of the stopped surfaces still needs. A reload asked for while
|
|
328
|
+
// the last one's thread is still ending waits its turn and starts from the UI queue. Once
|
|
329
|
+
// shutdown has begun, no run starts: the bundle never loads, and `done` gets false.
|
|
330
|
+
auto loaded = std::make_shared<bool>(false);
|
|
331
|
+
reloader_.start([this, loaded] {
|
|
332
|
+
bool restarted = false;
|
|
333
|
+
{
|
|
334
|
+
std::lock_guard lock(mutex_);
|
|
335
|
+
if (host_) {
|
|
336
|
+
host_->stopAllSurfaces();
|
|
337
|
+
workletHost().runOnScheduler.set(nullptr);
|
|
338
|
+
host_.reset();
|
|
339
|
+
createHost();
|
|
340
|
+
direction_.instanceStarted();
|
|
341
|
+
*loaded = devServer_ ? host_->loadScript("", bundle_) : host_->loadScript(bundle_, bundle_);
|
|
342
|
+
restarted = true;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
// Brings the new runtime to the surfaces the book has, which the UI thread may change
|
|
346
|
+
// meanwhile, until they match and the reload ends. mutex_ is never held while the book's lock
|
|
347
|
+
// is taken, which the UI thread takes first.
|
|
348
|
+
std::set<SurfaceId> started;
|
|
349
|
+
while (true) {
|
|
350
|
+
std::optional<SurfaceBook<Surface>::Step> step;
|
|
351
|
+
{
|
|
352
|
+
std::lock_guard book(surfacesMutex_);
|
|
353
|
+
if (!restarted) {
|
|
354
|
+
for (const auto &[id, surface] : surfaces_.surfaces()) {
|
|
355
|
+
started.insert(id);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
step = surfaces_.settle(started);
|
|
359
|
+
if (!step) {
|
|
360
|
+
reloading_ = false;
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
std::lock_guard lock(mutex_);
|
|
365
|
+
for (const auto &[surfaceId, surface] : step->start) {
|
|
366
|
+
host_->startSurface(
|
|
367
|
+
surfaceId, surface.moduleName, folly::dynamic::object(), surfaceConstraints(surface.metrics, direction_.rightToLeft()), context(surface.metrics));
|
|
368
|
+
started.insert(surfaceId);
|
|
369
|
+
}
|
|
370
|
+
// A surface resized after the reload started it takes its size now.
|
|
371
|
+
for (const auto &[surfaceId, surface] : step->update) {
|
|
372
|
+
host_->setSurfaceConstraints(surfaceId, surfaceConstraints(surface.metrics, direction_.rightToLeft()), context(surface.metrics));
|
|
373
|
+
}
|
|
374
|
+
for (auto surfaceId : step->stop) {
|
|
375
|
+
host_->stopSurface(surfaceId);
|
|
376
|
+
started.erase(surfaceId);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}, [done = std::move(done), loaded](bool ran) {
|
|
380
|
+
// On the UI queue once the run's thread has been joined (reload-thread.h), so `done` may reload
|
|
381
|
+
// again or destroy this runtime; it touches neither itself.
|
|
382
|
+
if (done) {
|
|
383
|
+
done(ran && *loaded);
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
void Runtime::reload(std::string bundle, std::function<void(bool)> done) {
|
|
389
|
+
if (devServer_) {
|
|
390
|
+
if (done) {
|
|
391
|
+
done(false);
|
|
392
|
+
}
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
{
|
|
396
|
+
std::lock_guard lock(mutex_);
|
|
397
|
+
bundle_ = std::move(bundle);
|
|
398
|
+
}
|
|
399
|
+
reload(std::move(done));
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
void Runtime::shutdown() {
|
|
403
|
+
// A reload still running holds this runtime: none starts from now (one waiting its turn is
|
|
404
|
+
// dropped), and the one running is joined, its `done` run, before the teardown.
|
|
405
|
+
auto alive = alive_;
|
|
406
|
+
// The mounting manager, not this runtime: a `done` that close runs may destroy this runtime.
|
|
407
|
+
reloader_.close([mounting = mounting_] { mounting->serviceUiThread(); });
|
|
408
|
+
// A reload's `done` that close ran may have destroyed this runtime.
|
|
409
|
+
if (!*alive) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
std::lock_guard lock(mutex_);
|
|
413
|
+
if (host_) {
|
|
414
|
+
workletHost().runOnScheduler.set(nullptr);
|
|
415
|
+
host_->stopAllSurfaces();
|
|
416
|
+
host_.reset();
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
} // namespace ngn
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
#include "ngn/safe-areas.h"
|
|
2
|
+
|
|
3
|
+
#include "ngn/library-glue.h"
|
|
4
|
+
|
|
5
|
+
#include <algorithm>
|
|
6
|
+
#include <string_view>
|
|
7
|
+
|
|
8
|
+
namespace ngn {
|
|
9
|
+
|
|
10
|
+
EdgeInsets insetsWithin(const ContainerInsets &container, const Rect &frame) {
|
|
11
|
+
auto clamp = [](double v) { return static_cast<facebook::react::Float>(std::max(0.0, v)); };
|
|
12
|
+
return EdgeInsets{
|
|
13
|
+
.left = clamp(container.insets.left - frame.origin.x),
|
|
14
|
+
.top = clamp(container.insets.top - frame.origin.y),
|
|
15
|
+
.right = clamp(container.insets.right - (container.size.width - frame.origin.x - frame.size.width)),
|
|
16
|
+
.bottom = clamp(container.insets.bottom - (container.size.height - frame.origin.y - frame.size.height)),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
double titlebarLeading(double minX, double maxX, double width, bool rightToLeft) {
|
|
21
|
+
if (maxX <= 0 || minX >= width) {
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
return rightToLeft ? width - minX : maxX;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
void SafeAreas::created(const ShadowView &view) {
|
|
28
|
+
std::string_view name = view.componentName;
|
|
29
|
+
if (name == "RNCSafeAreaProvider") {
|
|
30
|
+
tracked_[view.tag] = Tracked{.kind = Kind::Provider};
|
|
31
|
+
} else if (name == "RNCSafeAreaView" || name == "RNSSafeAreaView") {
|
|
32
|
+
tracked_[view.tag] = Tracked{.kind = Kind::View};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
void SafeAreas::deleted(Tag tag) {
|
|
37
|
+
tracked_.erase(tag);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
void SafeAreas::setContainer(Tag root, const ContainerInsets &metrics) {
|
|
41
|
+
containers_[root] = metrics;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
void SafeAreas::removeContainer(Tag root) {
|
|
45
|
+
containers_.erase(root);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
bool SafeAreas::settle(const ViewTree &tree) {
|
|
49
|
+
bool told = false;
|
|
50
|
+
for (auto &[tag, tracked] : tracked_) {
|
|
51
|
+
// The container the view is in: the nearest ancestor with metrics.
|
|
52
|
+
const ContainerInsets *container = nullptr;
|
|
53
|
+
Tag root = -1;
|
|
54
|
+
for (Tag at = tag; at != -1;) {
|
|
55
|
+
if (auto it = containers_.find(at); it != containers_.end()) {
|
|
56
|
+
container = &it->second;
|
|
57
|
+
root = at;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
const auto *node = tree.find(at);
|
|
61
|
+
at = node == nullptr ? -1 : node->parent;
|
|
62
|
+
}
|
|
63
|
+
const auto *node = tree.find(tag);
|
|
64
|
+
auto origin = container == nullptr ? std::nullopt : tree.originIn(tag, root);
|
|
65
|
+
if (node == nullptr || !origin) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
Rect frame{*origin, node->view.layoutMetrics.frame.size};
|
|
69
|
+
// A view that moves itself by its insets is measured from where it would be without them, as
|
|
70
|
+
// iOS measures it against its provider; from where the margin put it, it would be told it is
|
|
71
|
+
// clear, drop the margin, and move back.
|
|
72
|
+
Rect unmoved = frame;
|
|
73
|
+
if (auto margin = tracked.kind == Kind::View ? appliedMargin(*node) : std::nullopt) {
|
|
74
|
+
unmoved.origin.x -= margin->left;
|
|
75
|
+
unmoved.origin.y -= margin->top;
|
|
76
|
+
unmoved.size.width += margin->left + margin->right;
|
|
77
|
+
unmoved.size.height += margin->top + margin->bottom;
|
|
78
|
+
}
|
|
79
|
+
auto insets = insetsWithin(*container, unmoved);
|
|
80
|
+
bool changed = !tracked.known || insets != tracked.insets ||
|
|
81
|
+
(tracked.kind == Kind::Provider && (frame != tracked.frame || container->titlebarLeading != tracked.titlebarLeading));
|
|
82
|
+
if (!changed) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
told = true;
|
|
86
|
+
tracked.known = true;
|
|
87
|
+
tracked.insets = insets;
|
|
88
|
+
tracked.frame = frame;
|
|
89
|
+
tracked.titlebarLeading = container->titlebarLeading;
|
|
90
|
+
if (tracked.kind == Kind::Provider) {
|
|
91
|
+
emitInsetsChange(*node, insets, frame, container->titlebarLeading);
|
|
92
|
+
} else {
|
|
93
|
+
setStateInsets(*node, insets);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return told;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
void SafeAreas::emitInsetsChange(const ViewTree::Node &provider, EdgeInsets insets, Rect frame, double titlebarLeading) {
|
|
100
|
+
if (!provider.view.eventEmitter) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
provider.view.eventEmitter->dispatchEvent(
|
|
104
|
+
"insetsChange",
|
|
105
|
+
folly::dynamic::object(
|
|
106
|
+
"insets",
|
|
107
|
+
folly::dynamic::object("top", insets.top)("right", insets.right)("bottom", insets.bottom)("left", insets.left))(
|
|
108
|
+
"frame",
|
|
109
|
+
folly::dynamic::object("x", frame.origin.x)("y", frame.origin.y)("width", frame.size.width)(
|
|
110
|
+
"height", frame.size.height))("titlebarLeading", titlebarLeading));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
void SafeAreas::setStateInsets(const ViewTree::Node &view, EdgeInsets insets) {
|
|
114
|
+
if (!view.view.state) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
for (const auto &set : libraryGlue().safeAreaStates) {
|
|
118
|
+
if (set(*view.view.state, insets)) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
} // namespace ngn
|
|
125
|
+
|
|
126
|
+
namespace ngn {
|
|
127
|
+
|
|
128
|
+
std::optional<EdgeInsets> SafeAreas::appliedMargin(const ViewTree::Node &view) const {
|
|
129
|
+
for (const auto &read : libraryGlue().safeAreaMargins) {
|
|
130
|
+
if (auto margin = read(view.view)) {
|
|
131
|
+
return margin;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return std::nullopt;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
} // namespace ngn
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#include "ngn/screen-presentation.h"
|
|
2
|
+
|
|
3
|
+
#include <react/renderer/core/propsConversions.h>
|
|
4
|
+
|
|
5
|
+
using namespace facebook::react;
|
|
6
|
+
|
|
7
|
+
namespace ngn {
|
|
8
|
+
|
|
9
|
+
ScreenProps::ScreenProps(const PropsParserContext &context, const ScreenProps &sourceProps, const RawProps &rawProps)
|
|
10
|
+
: ViewProps(context, sourceProps, rawProps),
|
|
11
|
+
stackPresentation(
|
|
12
|
+
convertRawProp(context, rawProps, "stackPresentation", sourceProps.stackPresentation, std::string{"push"})),
|
|
13
|
+
anchor(convertRawProp(context, rawProps, "anchor", sourceProps.anchor, 0)),
|
|
14
|
+
gestureEnabled(convertRawProp(context, rawProps, "gestureEnabled", sourceProps.gestureEnabled, true)),
|
|
15
|
+
stackAnimation(
|
|
16
|
+
convertRawProp(context, rawProps, "stackAnimation", sourceProps.stackAnimation, std::string{"default"})) {}
|
|
17
|
+
|
|
18
|
+
std::optional<ModalPresentation> screenPresentation(const Props &props) {
|
|
19
|
+
const auto *screen = dynamic_cast<const ScreenProps *>(&props);
|
|
20
|
+
if (screen == nullptr || screen->stackPresentation == "push" || screen->stackPresentation.empty()) {
|
|
21
|
+
return std::nullopt;
|
|
22
|
+
}
|
|
23
|
+
if (screen->anchor != 0) {
|
|
24
|
+
return ModalPresentation::Popover;
|
|
25
|
+
}
|
|
26
|
+
const auto &how = screen->stackPresentation;
|
|
27
|
+
if (how == "modal" || how == "formSheet" || how == "pageSheet") {
|
|
28
|
+
return ModalPresentation::Sheet;
|
|
29
|
+
}
|
|
30
|
+
return ModalPresentation::Cover;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
SheetChrome sheetChrome(const HeaderBar &header, ModalPresentation presentation) {
|
|
34
|
+
SheetChrome chrome{.label = header.title};
|
|
35
|
+
if (presentation != ModalPresentation::Sheet || header.hidden) {
|
|
36
|
+
return chrome;
|
|
37
|
+
}
|
|
38
|
+
chrome.heading = header.title;
|
|
39
|
+
auto add = [&](const std::vector<BarButton> &items, bool left) {
|
|
40
|
+
for (const auto &item : items) {
|
|
41
|
+
// A fixed space has nothing to press.
|
|
42
|
+
if (item.spacing || (item.title.empty() && item.accessibilityLabel.empty())) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
chrome.buttons.push_back(SheetButton{
|
|
46
|
+
.id = item.id,
|
|
47
|
+
.title = item.title.empty() ? item.accessibilityLabel : item.title,
|
|
48
|
+
.cancel = left && chrome.buttons.empty(),
|
|
49
|
+
.disabled = item.disabled});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
add(header.left, true);
|
|
53
|
+
size_t left = chrome.buttons.size();
|
|
54
|
+
add(header.right, false);
|
|
55
|
+
if (chrome.buttons.size() > left) {
|
|
56
|
+
chrome.buttons.back().isDefault = true;
|
|
57
|
+
}
|
|
58
|
+
return chrome;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
} // namespace ngn
|