@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,161 @@
|
|
|
1
|
+
// The platform controls a desktop host draws, as Fabric components: `<native-button>`
|
|
2
|
+
// (NgNativeButton), `<switch>` (Switch), `<activity-indicator>` (ActivityIndicatorView),
|
|
3
|
+
// `<segmented-control>` (RNCSegmentedControl), `<date-time-picker>` (RNDateTimePicker) and
|
|
4
|
+
// `<search-field>` (`@ng-native/expo`'s NgNativeSearchField view).
|
|
5
|
+
//
|
|
6
|
+
// Every control has the same props class, the union of what the elements commit, and measures its
|
|
7
|
+
// intrinsic size for Yoga as a toolkit draws it at its `controlSize`. A toolkit measures on its UI
|
|
8
|
+
// thread only, so layout reads the sizes the ControlSizes in the ContextContainer holds
|
|
9
|
+
// (control-sizes.h). A size the app sets in its style wins, as it does for any leaf.
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include "ngn/desktop-props.h"
|
|
13
|
+
|
|
14
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
15
|
+
#include <react/renderer/components/view/ViewEventEmitter.h>
|
|
16
|
+
#include <react/renderer/components/view/ViewProps.h>
|
|
17
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
18
|
+
#include <react/renderer/core/LayoutConstraints.h>
|
|
19
|
+
#include <react/renderer/graphics/Color.h>
|
|
20
|
+
#include <react/utils/ContextContainer.h>
|
|
21
|
+
|
|
22
|
+
#include <optional>
|
|
23
|
+
#include <string>
|
|
24
|
+
#include <vector>
|
|
25
|
+
|
|
26
|
+
namespace ngn {
|
|
27
|
+
|
|
28
|
+
enum class ControlKind { Button, Switch, ActivityIndicator, SegmentedControl, DatePicker, SearchField };
|
|
29
|
+
|
|
30
|
+
// AppKit's control sizes, and UIKit's on iOS 26 and later.
|
|
31
|
+
enum class ControlSize { Mini, Small, Regular, Large };
|
|
32
|
+
|
|
33
|
+
class NativeControlProps final : public facebook::react::ViewProps, public HasDesktopProps {
|
|
34
|
+
public:
|
|
35
|
+
NativeControlProps() = default;
|
|
36
|
+
NativeControlProps(
|
|
37
|
+
const facebook::react::PropsParserContext &context,
|
|
38
|
+
const NativeControlProps &sourceProps,
|
|
39
|
+
const facebook::react::RawProps &rawProps);
|
|
40
|
+
|
|
41
|
+
ControlSize controlSize{ControlSize::Regular};
|
|
42
|
+
// False for `enabled: false` or `disabled: true`, whichever the element commits.
|
|
43
|
+
bool enabled{true};
|
|
44
|
+
|
|
45
|
+
// Button.
|
|
46
|
+
std::string title;
|
|
47
|
+
// `default`, `cancel`, `destructive` or `plain`.
|
|
48
|
+
std::string kind{"default"};
|
|
49
|
+
std::string sfSymbol;
|
|
50
|
+
|
|
51
|
+
// Switch.
|
|
52
|
+
bool value{false};
|
|
53
|
+
|
|
54
|
+
// Activity indicator.
|
|
55
|
+
bool animating{true};
|
|
56
|
+
bool hidesWhenStopped{true};
|
|
57
|
+
// `small` or `large`.
|
|
58
|
+
std::string size{"small"};
|
|
59
|
+
facebook::react::SharedColor color;
|
|
60
|
+
|
|
61
|
+
// Segmented control.
|
|
62
|
+
std::vector<std::string> values;
|
|
63
|
+
int selectedIndex{-1};
|
|
64
|
+
bool momentary{false};
|
|
65
|
+
|
|
66
|
+
// Date picker: milliseconds since the epoch.
|
|
67
|
+
std::optional<double> date;
|
|
68
|
+
std::optional<double> minimumDate;
|
|
69
|
+
std::optional<double> maximumDate;
|
|
70
|
+
// `date`, `time`, `datetime` or `countdown`.
|
|
71
|
+
std::string mode{"date"};
|
|
72
|
+
// `default`, `spinner`, `compact` or `inline`.
|
|
73
|
+
std::string display{"default"};
|
|
74
|
+
|
|
75
|
+
// Search field: the text JavaScript holds, and the keystroke it answers (React Native's text
|
|
76
|
+
// input rule: a text older than what has been typed since is skipped).
|
|
77
|
+
std::string text;
|
|
78
|
+
int mostRecentEventCount{0};
|
|
79
|
+
std::string placeholder;
|
|
80
|
+
std::string autoCapitalize;
|
|
81
|
+
facebook::react::SharedColor tintColor;
|
|
82
|
+
// The face, size, weight (CSS's 100 to 900) and slant the field's CSS resolves to; unset is the
|
|
83
|
+
// control's own font.
|
|
84
|
+
std::string fontFamily;
|
|
85
|
+
std::optional<double> fontSize;
|
|
86
|
+
std::optional<int> fontWeight;
|
|
87
|
+
bool italic{false};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// How big a toolkit draws a control. Called on the UI thread only, by ControlSizes.
|
|
91
|
+
class ControlMeasurer {
|
|
92
|
+
public:
|
|
93
|
+
virtual ~ControlMeasurer() = default;
|
|
94
|
+
virtual facebook::react::Size measure(ControlKind kind, const NativeControlProps &props) const = 0;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// A control's state: how many times a measurement made after its layout has asked for another.
|
|
98
|
+
// Each one is a state update, which lays the control out again with the size (control-sizes.h).
|
|
99
|
+
struct NativeControlState {
|
|
100
|
+
int measured{0};
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// The size layout gives a control: the one ControlSizes holds for its inputs (control-sizes.cpp).
|
|
104
|
+
facebook::react::Size measureControl(
|
|
105
|
+
const facebook::react::ShadowNode &node,
|
|
106
|
+
ControlKind kind,
|
|
107
|
+
const facebook::react::ContextContainer *context);
|
|
108
|
+
|
|
109
|
+
// The control a Fabric component name is, if it is one.
|
|
110
|
+
std::optional<ControlKind> controlKind(std::string_view componentName);
|
|
111
|
+
|
|
112
|
+
extern const char NativeButtonComponentName[];
|
|
113
|
+
extern const char SwitchControlComponentName[];
|
|
114
|
+
extern const char ActivityIndicatorControlComponentName[];
|
|
115
|
+
extern const char SegmentedControlComponentName[];
|
|
116
|
+
extern const char DatePickerComponentName[];
|
|
117
|
+
extern const char SearchFieldComponentName[];
|
|
118
|
+
|
|
119
|
+
template <const char *Name, ControlKind Kind>
|
|
120
|
+
class NativeControlShadowNode final : public facebook::react::ConcreteViewShadowNode<
|
|
121
|
+
Name,
|
|
122
|
+
NativeControlProps,
|
|
123
|
+
facebook::react::ViewEventEmitter,
|
|
124
|
+
NativeControlState> {
|
|
125
|
+
using Base = facebook::react::
|
|
126
|
+
ConcreteViewShadowNode<Name, NativeControlProps, facebook::react::ViewEventEmitter, NativeControlState>;
|
|
127
|
+
|
|
128
|
+
public:
|
|
129
|
+
using Base::Base;
|
|
130
|
+
|
|
131
|
+
static facebook::react::ShadowNodeTraits BaseTraits() {
|
|
132
|
+
auto traits = Base::BaseTraits();
|
|
133
|
+
traits.set(facebook::react::ShadowNodeTraits::Trait::LeafYogaNode);
|
|
134
|
+
traits.set(facebook::react::ShadowNodeTraits::Trait::MeasurableYogaNode);
|
|
135
|
+
return traits;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
facebook::react::Size measureContent(
|
|
139
|
+
const facebook::react::LayoutContext &layoutContext,
|
|
140
|
+
const facebook::react::LayoutConstraints &layoutConstraints) const override {
|
|
141
|
+
const auto &context = this->getContextContainer();
|
|
142
|
+
return layoutConstraints.clamp(measureControl(*this, Kind, context.get()));
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
template <const char *Name, ControlKind Kind>
|
|
147
|
+
using NativeControlComponentDescriptor =
|
|
148
|
+
facebook::react::ConcreteComponentDescriptor<NativeControlShadowNode<Name, Kind>>;
|
|
149
|
+
|
|
150
|
+
using NativeButtonComponentDescriptor = NativeControlComponentDescriptor<NativeButtonComponentName, ControlKind::Button>;
|
|
151
|
+
using SwitchControlComponentDescriptor =
|
|
152
|
+
NativeControlComponentDescriptor<SwitchControlComponentName, ControlKind::Switch>;
|
|
153
|
+
using ActivityIndicatorControlComponentDescriptor =
|
|
154
|
+
NativeControlComponentDescriptor<ActivityIndicatorControlComponentName, ControlKind::ActivityIndicator>;
|
|
155
|
+
using SegmentedControlComponentDescriptor =
|
|
156
|
+
NativeControlComponentDescriptor<SegmentedControlComponentName, ControlKind::SegmentedControl>;
|
|
157
|
+
using DatePickerComponentDescriptor = NativeControlComponentDescriptor<DatePickerComponentName, ControlKind::DatePicker>;
|
|
158
|
+
using SearchFieldComponentDescriptor =
|
|
159
|
+
NativeControlComponentDescriptor<SearchFieldComponentName, ControlKind::SearchField>;
|
|
160
|
+
|
|
161
|
+
} // namespace ngn
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// The shape every core module takes: methods over folly::dynamic, with callbacks and promises as
|
|
2
|
+
// plain functions, and events sent through an emitter. The module's logic is then ordinary C++
|
|
3
|
+
// that the core tests call directly, without a JavaScript engine; `turboModule` adapts it to
|
|
4
|
+
// React Native's TurboModule for the runtime.
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include "ngn/module-registry.h"
|
|
8
|
+
|
|
9
|
+
#include <ReactCommon/CallInvoker.h>
|
|
10
|
+
#include <ReactCommon/TurboModule.h>
|
|
11
|
+
#include <folly/dynamic.h>
|
|
12
|
+
|
|
13
|
+
#include <functional>
|
|
14
|
+
#include <map>
|
|
15
|
+
#include <memory>
|
|
16
|
+
#include <mutex>
|
|
17
|
+
#include <string>
|
|
18
|
+
#include <vector>
|
|
19
|
+
|
|
20
|
+
namespace ngn {
|
|
21
|
+
|
|
22
|
+
// A JavaScript function argument. Called with the array of arguments to pass it; safe from any
|
|
23
|
+
// thread (the call is queued onto the JavaScript thread).
|
|
24
|
+
using JsCallback = std::function<void(folly::dynamic arguments)>;
|
|
25
|
+
|
|
26
|
+
struct JsPromise {
|
|
27
|
+
std::function<void(folly::dynamic value)> resolve;
|
|
28
|
+
std::function<void(const std::string &message)> reject;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
class NativeModule {
|
|
32
|
+
public:
|
|
33
|
+
using Sync = std::function<folly::dynamic(const folly::dynamic &args)>;
|
|
34
|
+
// `callbacks` are the function arguments, in order; their places in `args` hold null.
|
|
35
|
+
using Async = std::function<void(const folly::dynamic &args, std::vector<JsCallback> callbacks)>;
|
|
36
|
+
using Promise = std::function<void(const folly::dynamic &args, JsPromise promise)>;
|
|
37
|
+
|
|
38
|
+
// Starts something that calls `callback` again and again (a watch), and answers how to stop it.
|
|
39
|
+
// Throws when it cannot start. JavaScript gets a promise of `{remove()}`, as expo-location's
|
|
40
|
+
// watchPositionAsync answers, or its rejection.
|
|
41
|
+
using Subscribe = std::function<std::function<void()>(const folly::dynamic &args, JsCallback callback)>;
|
|
42
|
+
|
|
43
|
+
struct Method {
|
|
44
|
+
enum class Kind { Sync, Async, Promise, Subscription } kind;
|
|
45
|
+
Sync sync;
|
|
46
|
+
Async async;
|
|
47
|
+
Promise promise;
|
|
48
|
+
Subscribe subscribe;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
explicit NativeModule(std::string name) : name_(std::move(name)) {}
|
|
52
|
+
virtual ~NativeModule() = default;
|
|
53
|
+
NativeModule(const NativeModule &) = delete;
|
|
54
|
+
NativeModule &operator=(const NativeModule &) = delete;
|
|
55
|
+
|
|
56
|
+
const std::string &name() const {
|
|
57
|
+
return name_;
|
|
58
|
+
}
|
|
59
|
+
const std::map<std::string, Method> &methods() const {
|
|
60
|
+
return methods_;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Where events go: RCTDeviceEventEmitter in the runtime, a recorder in tests. Any thread.
|
|
64
|
+
using Emitter = std::function<void(const std::string &event, folly::dynamic body)>;
|
|
65
|
+
void setEmitter(Emitter emitter);
|
|
66
|
+
|
|
67
|
+
// A property as JavaScript reads it off the module (an Expo module's `isEnabled`), read once per
|
|
68
|
+
// runtime, as a TurboModule keeps what it first answers. Null for one the module does not have.
|
|
69
|
+
folly::dynamic property(const std::string &name) const;
|
|
70
|
+
const std::map<std::string, std::function<folly::dynamic()>> &properties() const {
|
|
71
|
+
return properties_;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Calls a method as JavaScript would. For tests; the TurboModule calls the same functions.
|
|
75
|
+
folly::dynamic call(const std::string &method, const folly::dynamic &args = folly::dynamic::array()) const;
|
|
76
|
+
void callWithCallbacks(const std::string &method, const folly::dynamic &args, std::vector<JsCallback> callbacks) const;
|
|
77
|
+
void callWithPromise(const std::string &method, const folly::dynamic &args, JsPromise promise) const;
|
|
78
|
+
// The stop function, which does nothing after its first call.
|
|
79
|
+
std::function<void()> subscribe(const std::string &method, const folly::dynamic &args, JsCallback callback) const;
|
|
80
|
+
|
|
81
|
+
protected:
|
|
82
|
+
void sync(const std::string &method, Sync fn);
|
|
83
|
+
void async(const std::string &method, Async fn);
|
|
84
|
+
void promise(const std::string &method, Promise fn);
|
|
85
|
+
// The callback is the first function argument; its place in `args` holds null.
|
|
86
|
+
void subscription(const std::string &method, Subscribe fn);
|
|
87
|
+
// The listener bookkeeping every event-emitting module answers; events go out regardless.
|
|
88
|
+
void listeners();
|
|
89
|
+
void property(const std::string &name, std::function<folly::dynamic()> fn);
|
|
90
|
+
// Constants as getConstants returns them.
|
|
91
|
+
void constants(std::function<folly::dynamic()> fn);
|
|
92
|
+
void emit(const std::string &event, folly::dynamic body) const;
|
|
93
|
+
|
|
94
|
+
private:
|
|
95
|
+
std::string name_;
|
|
96
|
+
std::map<std::string, Method> methods_;
|
|
97
|
+
std::map<std::string, std::function<folly::dynamic()>> properties_;
|
|
98
|
+
mutable std::mutex emitterMutex_;
|
|
99
|
+
Emitter emitter_;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
std::shared_ptr<facebook::react::TurboModule> turboModule(
|
|
103
|
+
std::shared_ptr<NativeModule> module,
|
|
104
|
+
const std::shared_ptr<facebook::react::CallInvoker> &jsInvoker);
|
|
105
|
+
|
|
106
|
+
// Registers a core module: one instance per runtime, made on first use.
|
|
107
|
+
void addModule(ModuleRegistry ®istry, const std::string &name, std::function<std::shared_ptr<NativeModule>()> make);
|
|
108
|
+
|
|
109
|
+
} // namespace ngn
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// NgNativeNetwork: what @ng-native/expo's Network calls on expo-network, over a PathMonitor, which
|
|
2
|
+
// the AppKit backend implements with Network.framework's nw_path_monitor.
|
|
3
|
+
//
|
|
4
|
+
// - getNetworkStateAsync(): {type, isConnected, isInternetReachable}, with expo-network's type
|
|
5
|
+
// names (WIFI, ETHERNET, CELLULAR, OTHER, NONE). It answers once the monitor has reported the
|
|
6
|
+
// first path, which it does at once.
|
|
7
|
+
// - `ngNativeNetwork` on DeviceEventEmitter with the same state each time it changes, which the
|
|
8
|
+
// JS adapter turns into addNetworkStateListener's events.
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#include "ngn/native-module.h"
|
|
12
|
+
|
|
13
|
+
#include <functional>
|
|
14
|
+
#include <memory>
|
|
15
|
+
|
|
16
|
+
namespace ngn {
|
|
17
|
+
|
|
18
|
+
// The route to the network the OS would use now.
|
|
19
|
+
struct NetworkPath {
|
|
20
|
+
// A route exists (nw_path_status_satisfied).
|
|
21
|
+
bool satisfied{false};
|
|
22
|
+
// The interface types the path uses.
|
|
23
|
+
bool wifi{false};
|
|
24
|
+
bool ethernet{false};
|
|
25
|
+
bool cellular{false};
|
|
26
|
+
bool other{false};
|
|
27
|
+
bool operator==(const NetworkPath &) const = default;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
class PathMonitor {
|
|
31
|
+
public:
|
|
32
|
+
virtual ~PathMonitor() = default;
|
|
33
|
+
// Reports the path now and on each change, on any thread but one call at a time, in the order
|
|
34
|
+
// the paths changed, until the answer is called. The module relies on that order for its
|
|
35
|
+
// events. The answer may use the monitor: the module keeps it until the answer returns.
|
|
36
|
+
virtual std::function<void()> watch(std::function<void(const NetworkPath &)> changed) = 0;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// expo-network's NetworkState for a path.
|
|
40
|
+
folly::dynamic networkStateOf(const NetworkPath &path);
|
|
41
|
+
|
|
42
|
+
std::shared_ptr<NativeModule> makeNetworkModule(std::shared_ptr<PathMonitor> monitor);
|
|
43
|
+
|
|
44
|
+
} // namespace ngn
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// The network interface: HTTP and WebSocket clients, which a backend implements over the OS's own
|
|
2
|
+
// (NSURLSession on macOS). Everything above them, React Native's Networking and WebSocket modules
|
|
3
|
+
// and the dev server connection, is core code shared by every backend.
|
|
4
|
+
//
|
|
5
|
+
// Callbacks may arrive on any thread, but each request's or connection's arrive in order.
|
|
6
|
+
#pragma once
|
|
7
|
+
|
|
8
|
+
#include <react/http/IHttpClient.h>
|
|
9
|
+
#include <react/http/IWebSocketClient.h>
|
|
10
|
+
|
|
11
|
+
#include <cstdint>
|
|
12
|
+
#include <functional>
|
|
13
|
+
#include <memory>
|
|
14
|
+
#include <string>
|
|
15
|
+
#include <utility>
|
|
16
|
+
#include <vector>
|
|
17
|
+
|
|
18
|
+
namespace ngn {
|
|
19
|
+
|
|
20
|
+
using Headers = std::vector<std::pair<std::string, std::string>>;
|
|
21
|
+
|
|
22
|
+
struct HttpRequest {
|
|
23
|
+
std::string method{"GET"};
|
|
24
|
+
std::string url;
|
|
25
|
+
Headers headers;
|
|
26
|
+
// The body's bytes; empty for none.
|
|
27
|
+
std::string body;
|
|
28
|
+
// Zero for the client's default.
|
|
29
|
+
uint32_t timeoutMs{0};
|
|
30
|
+
// Whether the OS's cookie store applies to the request and takes its Set-Cookie headers.
|
|
31
|
+
bool withCredentials{true};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
struct HttpResponse {
|
|
35
|
+
uint16_t status{0};
|
|
36
|
+
Headers headers;
|
|
37
|
+
// Where the response came from, after any redirects.
|
|
38
|
+
std::string url;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
struct HttpCallbacks {
|
|
42
|
+
std::function<void(int64_t sent, int64_t total)> onUploadProgress;
|
|
43
|
+
std::function<void(const HttpResponse &response)> onResponse;
|
|
44
|
+
// Each chunk of the body as it arrives. `expected` is the length the response announced, or -1.
|
|
45
|
+
std::function<void(std::string chunk, int64_t expected)> onData;
|
|
46
|
+
// The last call for a request. An empty error is success.
|
|
47
|
+
std::function<void(const std::string &error, bool timedOut)> onComplete;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
class HttpTask {
|
|
51
|
+
public:
|
|
52
|
+
virtual ~HttpTask() = default;
|
|
53
|
+
// No callback runs after cancel returns, onComplete included.
|
|
54
|
+
virtual void cancel() = 0;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
class Http {
|
|
58
|
+
public:
|
|
59
|
+
virtual ~Http() = default;
|
|
60
|
+
virtual std::unique_ptr<HttpTask> send(HttpRequest request, HttpCallbacks callbacks) = 0;
|
|
61
|
+
// Empties the cookie store requests share.
|
|
62
|
+
virtual void clearCookies(std::function<void(bool cleared)> done) = 0;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
struct WebSocketCallbacks {
|
|
66
|
+
// `protocol` is the subprotocol the server chose, or empty.
|
|
67
|
+
std::function<void(const std::string &protocol)> onOpen;
|
|
68
|
+
std::function<void(const std::string &text)> onText;
|
|
69
|
+
std::function<void(const std::string &bytes)> onBinary;
|
|
70
|
+
// The connection closed after it opened.
|
|
71
|
+
std::function<void(int code, const std::string &reason)> onClose;
|
|
72
|
+
// The connection failed, before or after it opened. Nothing follows it.
|
|
73
|
+
std::function<void(const std::string &message)> onError;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
class WebSocketConnection {
|
|
77
|
+
public:
|
|
78
|
+
virtual ~WebSocketConnection() = default;
|
|
79
|
+
virtual void sendText(const std::string &text) = 0;
|
|
80
|
+
virtual void sendBinary(const std::string &bytes) = 0;
|
|
81
|
+
virtual void ping() = 0;
|
|
82
|
+
virtual void close(int code, const std::string &reason) = 0;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
class WebSockets {
|
|
86
|
+
public:
|
|
87
|
+
virtual ~WebSockets() = default;
|
|
88
|
+
virtual std::unique_ptr<WebSocketConnection> connect(
|
|
89
|
+
const std::string &url,
|
|
90
|
+
const std::vector<std::string> &protocols,
|
|
91
|
+
const Headers &headers,
|
|
92
|
+
WebSocketCallbacks callbacks) = 0;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// React Native's own client interfaces over these, for what ReactCxxPlatform drives itself: the
|
|
96
|
+
// bundle download, the packager connection and the inspector.
|
|
97
|
+
facebook::react::HttpClientFactory httpClientFactory(std::shared_ptr<Http> http);
|
|
98
|
+
facebook::react::WebSocketClientFactory webSocketClientFactory(std::shared_ptr<WebSockets> webSockets);
|
|
99
|
+
|
|
100
|
+
} // namespace ngn
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// Local notifications and the Dock badge on the desktop: `NgNativeNotifications`, expo-notifications'
|
|
2
|
+
// methods over the OS's notification centre (UNUserNotificationCenter on macOS).
|
|
3
|
+
//
|
|
4
|
+
// The host contract:
|
|
5
|
+
// - getPermissionsAsync() and requestPermissionsAsync() answer Expo's permission response
|
|
6
|
+
// `{ status: 'granted' | 'denied' | 'undetermined', granted, canAskAgain, expires: 'never' }`.
|
|
7
|
+
// Only requestPermissionsAsync asks the user, and only while the answer is undetermined. A host
|
|
8
|
+
// that cannot post notifications at all (a bare binary with no bundle identifier) answers denied
|
|
9
|
+
// with canAskAgain false.
|
|
10
|
+
// - scheduleNotificationAsync({ identifier?, content, trigger }) resolves to the identifier.
|
|
11
|
+
// `content` takes title, subtitle, body, data, sound (true or a name) and badge; `trigger` is
|
|
12
|
+
// null (now), `{ type: 'timeInterval', seconds, repeats }`, `{ type: 'date', date }` (ms since
|
|
13
|
+
// the epoch: a Date does not cross a TurboModule), `{ type: 'daily', hour, minute }`,
|
|
14
|
+
// `{ type: 'weekly', weekday, hour, minute }` (weekday 1 is Sunday), `{ type: 'monthly', day,
|
|
15
|
+
// hour, minute }`, `{ type: 'yearly', month, day, hour, minute }` (month 0 is January) or
|
|
16
|
+
// `{ type: 'calendar', repeats, year?, month?, day?, weekday?, hour?, minute?, second? }`.
|
|
17
|
+
// A trigger it cannot read rejects. Without permission (or where the build cannot post) it
|
|
18
|
+
// resolves null and schedules nothing: the permission status says why.
|
|
19
|
+
// - getAllScheduledNotificationsAsync() answers `{ identifier, content, trigger }` with the trigger
|
|
20
|
+
// as reported: `{ type: 'timeInterval', seconds, repeats }`, `{ type: 'date', value, repeats:
|
|
21
|
+
// false }` or `{ type: 'calendar', repeats, dateComponents }`.
|
|
22
|
+
// - cancelScheduledNotificationAsync(id), cancelAllScheduledNotificationsAsync(),
|
|
23
|
+
// getPresentedNotificationsAsync(), dismissNotificationAsync(id), dismissAllNotificationsAsync(),
|
|
24
|
+
// getNextTriggerDateAsync(trigger) (ms or null), getLastNotificationResponseAsync().
|
|
25
|
+
// - getBadgeCountAsync() and setBadgeCountAsync(count): the Dock badge, the count as its label and
|
|
26
|
+
// none at 0. It needs no permission. A delivered notification with `content.badge` sets it too.
|
|
27
|
+
// - `ngNativeNotifications` on DeviceEventEmitter: `{ type: 'received', notification }` as one is
|
|
28
|
+
// delivered while the app runs, and `{ type: 'response', response }` when the user clicks one,
|
|
29
|
+
// with `response = { actionIdentifier: 'expo.modules.notifications.actions.DEFAULT',
|
|
30
|
+
// notification }` and `notification = { date, request }`. A remote notification's request has
|
|
31
|
+
// the trigger `{ type: 'push', payload }`, the APNs payload, as on iOS. `{ type: 'token', token }`
|
|
32
|
+
// when the OS hands the app a new device token while it runs.
|
|
33
|
+
// - getDevicePushTokenAsync() registers with APNs and resolves `{ type: 'macos', data }`, the
|
|
34
|
+
// token in hex, or rejects with why the OS refused (an app signed without the
|
|
35
|
+
// `aps-environment` entitlement, or no network). unregisterForNotificationsAsync() unregisters.
|
|
36
|
+
#pragma once
|
|
37
|
+
|
|
38
|
+
#include "ngn/host-state.h"
|
|
39
|
+
#include "ngn/native-module.h"
|
|
40
|
+
|
|
41
|
+
#include <folly/dynamic.h>
|
|
42
|
+
|
|
43
|
+
#include <functional>
|
|
44
|
+
#include <map>
|
|
45
|
+
#include <memory>
|
|
46
|
+
#include <mutex>
|
|
47
|
+
#include <optional>
|
|
48
|
+
#include <string>
|
|
49
|
+
#include <variant>
|
|
50
|
+
#include <vector>
|
|
51
|
+
|
|
52
|
+
namespace ngn {
|
|
53
|
+
|
|
54
|
+
struct NotificationTrigger {
|
|
55
|
+
enum class Kind { Now, Interval, Date, Calendar, Push };
|
|
56
|
+
Kind kind{Kind::Now};
|
|
57
|
+
double seconds{0};
|
|
58
|
+
// Date: ms since the epoch.
|
|
59
|
+
double date{0};
|
|
60
|
+
bool repeats{false};
|
|
61
|
+
// Calendar: the components that must match, in the user's calendar and time zone. Months are
|
|
62
|
+
// 1 to 12 and weekdays 1 (Sunday) to 7, as NSDateComponents has them.
|
|
63
|
+
std::map<std::string, int> components;
|
|
64
|
+
// Push: the APNs payload as it came.
|
|
65
|
+
folly::dynamic payload = nullptr;
|
|
66
|
+
bool operator==(const NotificationTrigger &) const = default;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
struct NotificationRequest {
|
|
70
|
+
std::string identifier;
|
|
71
|
+
std::string title;
|
|
72
|
+
std::string subtitle;
|
|
73
|
+
std::string body;
|
|
74
|
+
folly::dynamic data = folly::dynamic::object();
|
|
75
|
+
// Empty for none, "default" for the default sound, or a sound's name.
|
|
76
|
+
std::string sound;
|
|
77
|
+
std::optional<int> badge;
|
|
78
|
+
NotificationTrigger trigger;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// The request in `args[0]` (scheduleNotificationAsync's), or why it cannot be read.
|
|
82
|
+
std::variant<NotificationRequest, std::string> parseNotificationRequest(const folly::dynamic &request);
|
|
83
|
+
// The trigger alone (getNextTriggerDateAsync's argument).
|
|
84
|
+
std::variant<NotificationTrigger, std::string> parseNotificationTrigger(const folly::dynamic &trigger);
|
|
85
|
+
// As getAllScheduledNotificationsAsync reports it.
|
|
86
|
+
folly::dynamic notificationRequestJson(const NotificationRequest &request);
|
|
87
|
+
// The Dock badge's label for a count: none at 0 or below.
|
|
88
|
+
std::string badgeLabel(int count);
|
|
89
|
+
|
|
90
|
+
// A remote notification's request from its APNs payload: the alert's title, subtitle and body
|
|
91
|
+
// (an alert that is a string is the body), its sound and badge, and the payload as its trigger's.
|
|
92
|
+
NotificationRequest remoteNotificationRequest(const std::string &identifier, const folly::dynamic &payload);
|
|
93
|
+
// Whether a payload has nothing to show (no alert): the OS's notification centre never presents
|
|
94
|
+
// it, so the app hears it only from the application delegate.
|
|
95
|
+
bool silentPush(const folly::dynamic &payload);
|
|
96
|
+
|
|
97
|
+
enum class NotificationAuthorization { NotDetermined, Denied, Authorized };
|
|
98
|
+
folly::dynamic permissionResponse(NotificationAuthorization authorization, bool canPost);
|
|
99
|
+
|
|
100
|
+
// The OS's notification centre. Callbacks may come on any thread.
|
|
101
|
+
class NotificationCenter {
|
|
102
|
+
public:
|
|
103
|
+
virtual ~NotificationCenter() = default;
|
|
104
|
+
// False where the process cannot post notifications at all.
|
|
105
|
+
virtual bool canPost() = 0;
|
|
106
|
+
virtual void authorization(std::function<void(NotificationAuthorization)> done) = 0;
|
|
107
|
+
virtual void requestAuthorization(std::function<void(NotificationAuthorization)> done) = 0;
|
|
108
|
+
virtual void add(const NotificationRequest &request, std::function<void(std::optional<std::string> error)> done) = 0;
|
|
109
|
+
virtual void pending(std::function<void(std::vector<NotificationRequest>)> done) = 0;
|
|
110
|
+
// Delivered ones with their delivery date (ms since the epoch).
|
|
111
|
+
virtual void delivered(std::function<void(std::vector<std::pair<double, NotificationRequest>>)> done) = 0;
|
|
112
|
+
virtual void removePending(const std::vector<std::string> &identifiers) = 0;
|
|
113
|
+
virtual void removeAllPending() = 0;
|
|
114
|
+
virtual void removeDelivered(const std::vector<std::string> &identifiers) = 0;
|
|
115
|
+
virtual void removeAllDelivered() = 0;
|
|
116
|
+
// When the trigger would next fire (ms), in the user's calendar; nothing if never.
|
|
117
|
+
virtual std::optional<double> nextDate(const NotificationTrigger &trigger) = 0;
|
|
118
|
+
virtual int badge() = 0;
|
|
119
|
+
virtual void setBadge(int count) = 0;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// Registration with the OS's push service (APNs). Answers come to PushTokens.
|
|
123
|
+
class PushRegistrar {
|
|
124
|
+
public:
|
|
125
|
+
virtual ~PushRegistrar() = default;
|
|
126
|
+
virtual void registerForRemoteNotifications() = 0;
|
|
127
|
+
virtual void unregisterForRemoteNotifications() = 0;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
class NotificationEvents;
|
|
131
|
+
|
|
132
|
+
// The device's push token: asked for once however many callers wait, answered from what the OS
|
|
133
|
+
// reported last, and its rolls sent out as `token` events. Any thread.
|
|
134
|
+
class PushTokens {
|
|
135
|
+
public:
|
|
136
|
+
using Answer = std::function<void(std::optional<std::string> token, std::string error)>;
|
|
137
|
+
PushTokens(std::shared_ptr<PushRegistrar> registrar, std::shared_ptr<NotificationEvents> events);
|
|
138
|
+
// The token in hex, registering first when there is none.
|
|
139
|
+
void request(Answer answer);
|
|
140
|
+
// The OS's answers to a registration.
|
|
141
|
+
void registered(const std::string &deviceToken);
|
|
142
|
+
void failed(const std::string &message);
|
|
143
|
+
void unregister();
|
|
144
|
+
|
|
145
|
+
private:
|
|
146
|
+
std::shared_ptr<PushRegistrar> registrar_;
|
|
147
|
+
std::shared_ptr<NotificationEvents> events_;
|
|
148
|
+
std::mutex mutex_;
|
|
149
|
+
std::optional<std::string> token_;
|
|
150
|
+
std::vector<Answer> waiting_;
|
|
151
|
+
bool registering_{false};
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// A device token's bytes as the hex APNs servers are given.
|
|
155
|
+
std::string pushTokenHex(const std::string &deviceToken);
|
|
156
|
+
// Why a registration failed, said for the app: the missing entitlement named, with what to do.
|
|
157
|
+
std::string pushFailure(const std::string &message);
|
|
158
|
+
|
|
159
|
+
// What the backend reports as notifications arrive and are clicked, kept for the app's modules:
|
|
160
|
+
// the response that launched the app waits for getLastNotificationResponseAsync.
|
|
161
|
+
class NotificationEvents {
|
|
162
|
+
public:
|
|
163
|
+
void received(double date, const NotificationRequest &request);
|
|
164
|
+
void responded(double date, const NotificationRequest &request);
|
|
165
|
+
// A new device token, in hex, while the app runs.
|
|
166
|
+
void tokenChanged(const std::string &token);
|
|
167
|
+
std::optional<folly::dynamic> lastResponse() const;
|
|
168
|
+
std::shared_ptr<void> listen(std::function<void(const folly::dynamic &event)> listener);
|
|
169
|
+
|
|
170
|
+
private:
|
|
171
|
+
void send(const folly::dynamic &event);
|
|
172
|
+
mutable std::mutex mutex_;
|
|
173
|
+
std::optional<folly::dynamic> lastResponse_;
|
|
174
|
+
// A dropped handle waits for its listener's call in progress, so a module going with a reload
|
|
175
|
+
// is never called after.
|
|
176
|
+
Listeners<folly::dynamic> listeners_;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// `push` absent (a host that cannot register) rejects getDevicePushTokenAsync.
|
|
180
|
+
std::shared_ptr<NativeModule> makeNotificationsModule(
|
|
181
|
+
std::shared_ptr<NotificationCenter> center,
|
|
182
|
+
std::shared_ptr<NotificationEvents> events,
|
|
183
|
+
std::shared_ptr<PushTokens> push = nullptr);
|
|
184
|
+
|
|
185
|
+
} // namespace ngn
|