@ng-native/desktop 0.23.0 → 0.25.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/bin/package.mjs +65 -9
- package/bin/prebuilt.mjs +25 -4
- package/native/CMakeLists.txt +7 -2
- package/native/appkit/CMakeLists.txt +39 -5
- package/native/appkit/appkit-backend.mm +28 -3
- package/native/appkit/camera-sheet.h +59 -0
- package/native/appkit/camera-sheet.mm +344 -0
- package/native/appkit/camera-view.mm +5 -1
- package/native/appkit/camera.h +22 -0
- package/native/appkit/camera.mm +203 -69
- package/native/appkit/cg-canvas.h +8 -1
- package/native/appkit/cg-canvas.mm +166 -21
- package/native/appkit/header-toolbar.mm +4 -1
- package/native/appkit/host-view.mm +29 -1
- package/native/appkit/image-view.mm +31 -2
- package/native/appkit/main.mm +29 -69
- package/native/appkit/photo-library.mm +6 -6
- package/native/appkit/scroll-view.mm +57 -16
- package/native/appkit/scrollers.h +22 -2
- package/native/appkit/scrollers.mm +221 -2
- package/native/appkit/split-view.h +4 -0
- package/native/appkit/split-view.mm +57 -3
- package/native/appkit/surface-view.mm +5 -1
- package/native/appkit/svg-view.h +2 -1
- package/native/appkit/svg-view.mm +49 -3
- package/native/appkit/tab-walk.h +31 -0
- package/native/appkit/tab-walk.mm +64 -0
- package/native/appkit/text-input-field.h +5 -0
- package/native/appkit/text-input-field.mm +101 -20
- package/native/appkit/text-layout.h +7 -1
- package/native/appkit/text-layout.mm +161 -30
- package/native/appkit/web-view-component.h +4 -3
- package/native/appkit/web-view-component.mm +8 -2
- package/native/appkit/web-view.mm +7 -0
- package/native/cmake/react-native.cmake +9 -0
- package/native/cmake/runtime-dependencies.cmake +21 -0
- package/native/core/include/ngn/app-menus.h +8 -3
- package/native/core/include/ngn/back-swipe.h +16 -7
- package/native/core/include/ngn/camera.h +103 -9
- package/native/core/include/ngn/core-modules.h +3 -0
- package/native/core/include/ngn/dom-web-view.h +53 -0
- package/native/core/include/ngn/photo-library.h +7 -3
- package/native/core/include/ngn/runtime.h +10 -8
- package/native/core/include/ngn/safe-areas.h +5 -0
- package/native/core/include/ngn/scrollers.h +5 -0
- package/native/core/include/ngn/surface-metrics.h +51 -0
- package/native/core/include/ngn/svg.h +49 -8
- package/native/core/include/ngn/text-input.h +9 -0
- package/native/core/include/ngn/text-measurer.h +11 -0
- package/native/core/include/ngn/web-view.h +6 -2
- package/native/core/src/app-menus.cpp +10 -3
- package/native/core/src/back-swipe.cpp +12 -5
- package/native/core/src/dom-web-view.cpp +45 -0
- package/native/core/src/libraries/rnsvg.cpp +13 -0
- package/native/core/src/modules/app-modules.cpp +24 -15
- package/native/core/src/modules/camera.cpp +203 -23
- package/native/core/src/modules/photo-library.cpp +22 -8
- package/native/core/src/mounting-manager.cpp +4 -0
- package/native/core/src/runtime.cpp +6 -8
- package/native/core/src/safe-areas.cpp +7 -0
- package/native/core/src/scrollers.cpp +11 -0
- package/native/core/src/svg.cpp +324 -17
- package/native/core/src/text-input.cpp +13 -0
- package/native/core/src/text-layout-manager.cpp +13 -0
- package/native/core/src/web-view.cpp +1 -1
- package/native/scripts/build.sh +12 -2
- package/native/scripts/fetch-hermes.sh +70 -0
- package/native/scripts/launch-probe.sh +60 -0
- package/native/scripts/make-prebuilt.mjs +13 -6
- package/native/scripts/prebuilt-host-cache.mjs +1 -1
- package/native/shim/text-platform/react/renderer/textlayoutmanager/TextLayoutManager.h +52 -0
- package/package.json +2 -2
- package/prebuilt.json +6 -6
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
namespace ngn {
|
|
6
6
|
|
|
7
|
-
bool BackSwipe::begin(std::optional<BackSwipeTarget> target, double width) {
|
|
7
|
+
bool BackSwipe::begin(std::optional<BackSwipeTarget> target, double width, bool rightToLeft) {
|
|
8
8
|
if (phase_ != Phase::Idle || !target || width <= 0) {
|
|
9
9
|
return false;
|
|
10
10
|
}
|
|
11
11
|
phase_ = Phase::Tracking;
|
|
12
12
|
target_ = target;
|
|
13
13
|
width_ = width;
|
|
14
|
+
rightToLeft_ = rightToLeft;
|
|
14
15
|
offset_ = 0;
|
|
15
16
|
lastMove_ = 0;
|
|
16
17
|
return true;
|
|
@@ -21,14 +22,14 @@ BackSwipeFrame BackSwipe::frameAt(double progress, bool belowShown) const {
|
|
|
21
22
|
if (target_ && target_->style == SwipeStyle::Fade) {
|
|
22
23
|
return {.offset = 0, .opacity = 1 - progress, .belowShown = belowShown};
|
|
23
24
|
}
|
|
24
|
-
return {.offset = progress * width_, .opacity = 1, .belowShown = belowShown};
|
|
25
|
+
return {.offset = progress * towardsBack(width_, rightToLeft_), .opacity = 1, .belowShown = belowShown};
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
BackSwipeFrame BackSwipe::moved(double dx) {
|
|
28
29
|
if (phase_ != Phase::Tracking) {
|
|
29
30
|
return rest();
|
|
30
31
|
}
|
|
31
|
-
// The screen stops at its home edge: a move away from back past it does not drag it
|
|
32
|
+
// The screen stops at its home edge: a move away from back past it does not drag it further.
|
|
32
33
|
offset_ = std::clamp(offset_ + dx, 0.0, width_);
|
|
33
34
|
lastMove_ = dx;
|
|
34
35
|
return frameAt(offset_ / width_, offset_ > 0);
|
|
@@ -84,8 +85,14 @@ bool BackSwipe::fingersDown() {
|
|
|
84
85
|
return true;
|
|
85
86
|
}
|
|
86
87
|
|
|
87
|
-
|
|
88
|
-
return
|
|
88
|
+
double towardsBack(double right, bool rightToLeft) {
|
|
89
|
+
return rightToLeft ? -right : right;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
SwipeBounds swipeBounds(bool canGoBack, bool canGoForward, bool rightToLeft) {
|
|
93
|
+
bool canGoLeft = rightToLeft ? canGoBack : canGoForward;
|
|
94
|
+
bool canGoRight = rightToLeft ? canGoForward : canGoBack;
|
|
95
|
+
return {.min = canGoLeft ? -1.0 : 0.0, .max = canGoRight ? 1.0 : 0.0};
|
|
89
96
|
}
|
|
90
97
|
|
|
91
98
|
} // namespace ngn
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#include "ngn/dom-web-view.h"
|
|
2
|
+
|
|
3
|
+
#include "ngn/desktop-view-props.h"
|
|
4
|
+
|
|
5
|
+
#include <react/renderer/core/propsConversions.h>
|
|
6
|
+
|
|
7
|
+
using namespace facebook::react;
|
|
8
|
+
|
|
9
|
+
namespace ngn {
|
|
10
|
+
|
|
11
|
+
const char DomWebViewComponentName[] = "ViewManagerAdapter_ExpoDomWebViewModule";
|
|
12
|
+
|
|
13
|
+
DomWebViewProps::DomWebViewProps(const PropsParserContext &context, const DomWebViewProps &sourceProps, const RawProps &rawProps)
|
|
14
|
+
: ViewProps(context, sourceProps, rawProps),
|
|
15
|
+
HasDesktopProps{parseDesktopProps(context, sourceProps.desktop, rawProps)},
|
|
16
|
+
source(convertRawProp(context, rawProps, "source", sourceProps.source, folly::dynamic(nullptr))),
|
|
17
|
+
injectedJavaScript(convertRawProp(context, rawProps, "injectedJavaScript", sourceProps.injectedJavaScript, {})),
|
|
18
|
+
injectedJavaScriptBeforeContentLoaded(convertRawProp(
|
|
19
|
+
context, rawProps, "injectedJavaScriptBeforeContentLoaded", sourceProps.injectedJavaScriptBeforeContentLoaded, {})),
|
|
20
|
+
injectedJavaScriptObject(
|
|
21
|
+
convertRawProp(context, rawProps, "injectedJavaScriptObject", sourceProps.injectedJavaScriptObject, {})),
|
|
22
|
+
webviewDebuggingEnabled(
|
|
23
|
+
convertRawProp(context, rawProps, "webviewDebuggingEnabled", sourceProps.webviewDebuggingEnabled, false)) {}
|
|
24
|
+
|
|
25
|
+
std::optional<WebViewConfig> domWebViewConfig(const Props &props) {
|
|
26
|
+
const auto *own = dynamic_cast<const DomWebViewProps *>(&props);
|
|
27
|
+
if (own == nullptr) {
|
|
28
|
+
return std::nullopt;
|
|
29
|
+
}
|
|
30
|
+
WebViewConfig config;
|
|
31
|
+
if (const auto *uri = own->source.isObject() ? own->source.get_ptr("uri") : nullptr; uri != nullptr && uri->isString()) {
|
|
32
|
+
config.source.uri = uri->asString();
|
|
33
|
+
}
|
|
34
|
+
config.injectedJavaScript = own->injectedJavaScript;
|
|
35
|
+
config.injectedJavaScriptBeforeContentLoaded = own->injectedJavaScriptBeforeContentLoaded;
|
|
36
|
+
config.injectedJavaScriptForMainFrameOnly = false;
|
|
37
|
+
config.injectedJavaScriptBeforeContentLoadedForMainFrameOnly = false;
|
|
38
|
+
config.injectedJavaScriptObject = own->injectedJavaScriptObject;
|
|
39
|
+
config.messagingEnabled = true;
|
|
40
|
+
config.webviewDebuggingEnabled = own->webviewDebuggingEnabled;
|
|
41
|
+
config.asksApp = false;
|
|
42
|
+
return config;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
} // namespace ngn
|
|
@@ -137,7 +137,9 @@ void common(SvgElement &e, const P &p) {
|
|
|
137
137
|
if (font.isObject()) {
|
|
138
138
|
auto family = font.getDefault("fontFamily", "");
|
|
139
139
|
auto weight = font.getDefault("fontWeight", "");
|
|
140
|
+
auto anchor = font.getDefault("textAnchor", "");
|
|
140
141
|
e.fontFamily = family.isString() ? family.getString() : "";
|
|
142
|
+
e.textAnchor = anchor.isString() ? anchor.getString() : "";
|
|
141
143
|
e.fontWeight = weight.isString() ? weight.getString() : weight.isNumber() ? std::to_string(weight.asInt()) : "";
|
|
142
144
|
}
|
|
143
145
|
}
|
|
@@ -264,6 +266,10 @@ std::optional<SvgElement> svgElement(const Props &props) {
|
|
|
264
266
|
e.uri = p->src.uri;
|
|
265
267
|
e.align = p->align;
|
|
266
268
|
e.meetOrSlice = p->meetOrSlice;
|
|
269
|
+
} else if (const auto *p = dynamic_cast<const RNSVGForeignObjectProps *>(&props)) {
|
|
270
|
+
e.kind = SvgKind::ForeignObject;
|
|
271
|
+
common(e, *p);
|
|
272
|
+
lengths(e, {{"x", &p->x}, {"y", &p->y}, {"width", &p->width}, {"height", &p->height}});
|
|
267
273
|
} else if (const auto *p = dynamic_cast<const RNSVGTextProps *>(&props)) {
|
|
268
274
|
e.kind = SvgKind::Text;
|
|
269
275
|
common(e, *p);
|
|
@@ -273,6 +279,13 @@ std::optional<SvgElement> svgElement(const Props &props) {
|
|
|
273
279
|
common(e, *p);
|
|
274
280
|
text(e, *p);
|
|
275
281
|
e.content = p->content;
|
|
282
|
+
} else if (const auto *p = dynamic_cast<const RNSVGTextPathProps *>(&props)) {
|
|
283
|
+
e.kind = SvgKind::TextPath;
|
|
284
|
+
common(e, *p);
|
|
285
|
+
text(e, *p);
|
|
286
|
+
e.href = p->href;
|
|
287
|
+
e.side = p->side;
|
|
288
|
+
lengths(e, {{"startOffset", &p->startOffset}});
|
|
276
289
|
} else if (const auto *p = dynamic_cast<const RNSVGMarkerProps *>(&props)) {
|
|
277
290
|
e.kind = SvgKind::Marker;
|
|
278
291
|
common(e, *p);
|
|
@@ -190,28 +190,35 @@ std::shared_ptr<NativeModule> makeLinking(const CoreModuleServices &s) {
|
|
|
190
190
|
return std::make_shared<Linking>(s);
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
+
namespace {
|
|
194
|
+
|
|
195
|
+
// React Native iOS's keys and defaults: RTL is allowed and left and right swap, until the app
|
|
196
|
+
// says otherwise; the choice persists across launches.
|
|
197
|
+
bool i18nFlag(System &system, const char *key, bool fallback) {
|
|
198
|
+
auto value = system.preference(key);
|
|
199
|
+
return value && value->isBool() ? value->asBool() : fallback;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
} // namespace
|
|
203
|
+
|
|
204
|
+
bool appRightToLeft(System &system) {
|
|
205
|
+
return i18nFlag(system, "RCTI18nUtil_forceRTL", false) ||
|
|
206
|
+
(i18nFlag(system, "RCTI18nUtil_allowRTL", true) && system.facts().rightToLeft);
|
|
207
|
+
}
|
|
208
|
+
|
|
193
209
|
std::shared_ptr<NativeModule> makeI18n(const CoreModuleServices &s) {
|
|
194
210
|
struct I18n : NativeModule {
|
|
195
211
|
explicit I18n(const CoreModuleServices &s) : NativeModule("I18nManager") {
|
|
196
212
|
auto system = s.system;
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
auto flag = [system](const char *key, bool fallback) {
|
|
200
|
-
auto value = system->preference(key);
|
|
201
|
-
return value && value->isBool() ? value->asBool() : fallback;
|
|
202
|
-
};
|
|
203
|
-
constants([system, flag] {
|
|
204
|
-
auto facts = system->facts();
|
|
205
|
-
bool forced = flag("RCTI18nUtil_forceRTL", false);
|
|
206
|
-
bool allowed = flag("RCTI18nUtil_allowRTL", true);
|
|
207
|
-
std::string locale = facts.locale;
|
|
213
|
+
constants([system] {
|
|
214
|
+
std::string locale = system->facts().locale;
|
|
208
215
|
for (auto &c : locale) {
|
|
209
216
|
if (c == '-') {
|
|
210
217
|
c = '_';
|
|
211
218
|
}
|
|
212
219
|
}
|
|
213
|
-
return folly::dynamic::object("isRTL",
|
|
214
|
-
"doLeftAndRightSwapInRTL",
|
|
220
|
+
return folly::dynamic::object("isRTL", appRightToLeft(*system))(
|
|
221
|
+
"doLeftAndRightSwapInRTL", i18nFlag(*system, "RCTI18nUtil_makeRTLFlipLeftAndRightStyles", true))(
|
|
215
222
|
"localeIdentifier", locale);
|
|
216
223
|
});
|
|
217
224
|
auto setter = [system](const char *key) {
|
|
@@ -370,8 +377,10 @@ std::shared_ptr<NativeModule> makeGestureHandlerModule(const CoreModuleServices
|
|
|
370
377
|
// Each call is already queued for the UI thread as it is made.
|
|
371
378
|
sync("flushOperations", [](const folly::dynamic &) { return folly::dynamic(nullptr); });
|
|
372
379
|
// The worklet runtime's `_setGestureStateSync` is not installed: a worklet's state manager
|
|
373
|
-
// reaches the handlers through Reanimated's setGestureState instead (worklet-host.h).
|
|
374
|
-
|
|
380
|
+
// reaches the handlers through Reanimated's setGestureState instead (worklet-host.h). The
|
|
381
|
+
// answer only decides whether the gesture handler warns, telling the app to report a bug,
|
|
382
|
+
// so it says the runtime is ready, as the gesture handler's own web module does.
|
|
383
|
+
sync("installUIRuntimeBindings", [](const folly::dynamic &) { return folly::dynamic(true); });
|
|
375
384
|
}
|
|
376
385
|
|
|
377
386
|
void send(const std::string &event, folly::dynamic body) const {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
#include <algorithm>
|
|
11
11
|
#include <filesystem>
|
|
12
12
|
#include <fstream>
|
|
13
|
+
#include <iterator>
|
|
13
14
|
#include <random>
|
|
14
15
|
|
|
15
16
|
using namespace facebook::react;
|
|
@@ -23,7 +24,8 @@ CameraProps::CameraProps(const PropsParserContext &context, const CameraProps &s
|
|
|
23
24
|
HasDesktopProps{parseDesktopProps(context, sourceProps.desktop, rawProps)},
|
|
24
25
|
facing(convertRawProp(context, rawProps, "facing", sourceProps.facing, std::string{"back"})),
|
|
25
26
|
active(convertRawProp(context, rawProps, "active", sourceProps.active, true)),
|
|
26
|
-
mirror(convertRawProp(context, rawProps, "mirror", sourceProps.mirror, false))
|
|
27
|
+
mirror(convertRawProp(context, rawProps, "mirror", sourceProps.mirror, false)),
|
|
28
|
+
mute(convertRawProp(context, rawProps, "mute", sourceProps.mute, false)) {}
|
|
27
29
|
|
|
28
30
|
void CameraViews::attach(int tag, std::shared_ptr<CameraCapture> capture) {
|
|
29
31
|
std::lock_guard lock(mutex_);
|
|
@@ -33,10 +35,14 @@ void CameraViews::attach(int tag, std::shared_ptr<CameraCapture> capture) {
|
|
|
33
35
|
void CameraViews::detach(int tag) {
|
|
34
36
|
std::lock_guard lock(mutex_);
|
|
35
37
|
captures_.erase(tag);
|
|
38
|
+
muted_.erase(tag);
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
std::shared_ptr<CameraCapture> CameraViews::find(int tag) const {
|
|
41
|
+
std::shared_ptr<CameraCapture> CameraViews::find(int tag, bool *muted) const {
|
|
39
42
|
std::lock_guard lock(mutex_);
|
|
43
|
+
if (muted) {
|
|
44
|
+
*muted = muted_.contains(tag);
|
|
45
|
+
}
|
|
40
46
|
auto found = captures_.find(tag);
|
|
41
47
|
return found == captures_.end() ? nullptr : found->second;
|
|
42
48
|
}
|
|
@@ -52,6 +58,20 @@ CameraMount cameraMount(CameraHardware::Access access, bool hasCamera, bool noPr
|
|
|
52
58
|
return hasCamera ? CameraMount::Start : CameraMount::NoCamera;
|
|
53
59
|
}
|
|
54
60
|
|
|
61
|
+
void CameraViews::mute(int tag, bool muted) {
|
|
62
|
+
std::lock_guard lock(mutex_);
|
|
63
|
+
if (muted) {
|
|
64
|
+
muted_.insert(tag);
|
|
65
|
+
} else {
|
|
66
|
+
muted_.erase(tag);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
bool CameraViews::muted(int tag) const {
|
|
71
|
+
std::lock_guard lock(mutex_);
|
|
72
|
+
return muted_.contains(tag);
|
|
73
|
+
}
|
|
74
|
+
|
|
55
75
|
int chooseCamera(const std::vector<CameraCandidate> &cameras) {
|
|
56
76
|
int other = -1;
|
|
57
77
|
for (size_t i = 0; i < cameras.size(); i++) {
|
|
@@ -77,15 +97,24 @@ std::string cameraMountError(CameraMount mount) {
|
|
|
77
97
|
}
|
|
78
98
|
}
|
|
79
99
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
folly::dynamic permissionOf(CameraHardware::Access access) {
|
|
100
|
+
folly::dynamic cameraPermissionOf(CameraHardware::Access access) {
|
|
83
101
|
using Access = CameraHardware::Access;
|
|
84
102
|
const char *status = access == Access::Granted ? "granted" : access == Access::NotDetermined ? "undetermined" : "denied";
|
|
85
103
|
return folly::dynamic::object("status", status)("granted", access == Access::Granted)("canAskAgain", access == Access::NotDetermined)(
|
|
86
104
|
"expires", "never");
|
|
87
105
|
}
|
|
88
106
|
|
|
107
|
+
void requestCameraPermission(CameraHardware &hardware, bool noPrompts, JsPromise promise) {
|
|
108
|
+
auto access = hardware.access();
|
|
109
|
+
if (noPrompts || access != CameraHardware::Access::NotDetermined) {
|
|
110
|
+
promise.resolve(cameraPermissionOf(access));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
hardware.requestAccess([promise](CameraHardware::Access decided) { promise.resolve(cameraPermissionOf(decided)); });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
namespace {
|
|
117
|
+
|
|
89
118
|
// A new file's name: a random UUID with `extension`, as expo names its pictures and videos.
|
|
90
119
|
std::string newFileName(const std::string &extension) {
|
|
91
120
|
static std::mutex mutex;
|
|
@@ -105,8 +134,157 @@ std::string contentsOf(const std::string &path) {
|
|
|
105
134
|
return {std::istreambuf_iterator<char>(in), {}};
|
|
106
135
|
}
|
|
107
136
|
|
|
137
|
+
// What expo-image-picker's mediaTypes (a MediaType, a list of them, or the deprecated
|
|
138
|
+
// MediaTypeOptions) let the camera take. As on iOS, live photos are photos, and a request that
|
|
139
|
+
// names neither photos nor videos (left out, or an empty list) takes photos.
|
|
140
|
+
struct MediaKinds {
|
|
141
|
+
bool photos{false};
|
|
142
|
+
bool videos{false};
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
MediaKinds mediaKindsOf(const folly::dynamic &options) {
|
|
146
|
+
MediaKinds kinds;
|
|
147
|
+
const auto *types = options.isObject() ? options.get_ptr("mediaTypes") : nullptr;
|
|
148
|
+
auto add = [&kinds](const folly::dynamic &type) {
|
|
149
|
+
if (!type.isString()) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
kinds.photos = kinds.photos || type == "images" || type == "livePhotos" || type == "Images" || type == "All";
|
|
153
|
+
kinds.videos = kinds.videos || type == "videos" || type == "Videos" || type == "All";
|
|
154
|
+
};
|
|
155
|
+
if (types != nullptr && types->isArray()) {
|
|
156
|
+
for (const auto &type : *types) {
|
|
157
|
+
add(type);
|
|
158
|
+
}
|
|
159
|
+
} else if (types != nullptr) {
|
|
160
|
+
add(*types);
|
|
161
|
+
}
|
|
162
|
+
kinds.photos = kinds.photos || !kinds.videos;
|
|
163
|
+
return kinds;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// AVFoundation's session preset for expo-image-picker's videoQuality, which on iOS is
|
|
167
|
+
// UIImagePickerController's QualityType; High for any other value.
|
|
168
|
+
std::string videoPresetOf(const folly::dynamic &options) {
|
|
169
|
+
const auto *quality = options.isObject() ? options.get_ptr("videoQuality") : nullptr;
|
|
170
|
+
if (quality == nullptr || !quality->isNumber()) {
|
|
171
|
+
return "High";
|
|
172
|
+
}
|
|
173
|
+
static const char *const presets[] = {"High", "Medium", "Low", "640x480", "iFrame1280x720", "iFrame960x540"};
|
|
174
|
+
auto value = quality->asDouble();
|
|
175
|
+
for (size_t i = 0; i < std::size(presets); i++) {
|
|
176
|
+
if (value == static_cast<double>(i)) {
|
|
177
|
+
return presets[i];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return "High";
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Shows the sheet, once the microphone is settled, and answers what it took. A video has sound
|
|
184
|
+
// only with the microphone allowed.
|
|
185
|
+
void showPickerCamera(const PickerCamera &camera, const folly::dynamic &options, MediaKinds kinds, bool sound, JsPromise promise) {
|
|
186
|
+
CameraSheetRequest request{.photos = kinds.photos, .videos = kinds.videos};
|
|
187
|
+
request.video.sound = sound;
|
|
188
|
+
bool base64 = false;
|
|
189
|
+
bool exif = false;
|
|
190
|
+
if (options.isObject()) {
|
|
191
|
+
if (const auto *q = options.get_ptr("quality"); q && q->isNumber()) {
|
|
192
|
+
request.photo.quality = std::clamp(q->asDouble(), 0.0, 1.0);
|
|
193
|
+
}
|
|
194
|
+
if (const auto *d = options.get_ptr("videoMaxDuration"); d && d->isNumber()) {
|
|
195
|
+
request.video.maxDuration = std::max(0.0, d->asDouble());
|
|
196
|
+
}
|
|
197
|
+
base64 = options.getDefault("base64", false) == true;
|
|
198
|
+
exif = options.getDefault("exif", false) == true;
|
|
199
|
+
}
|
|
200
|
+
request.video.preset = videoPresetOf(options);
|
|
201
|
+
std::error_code ignored;
|
|
202
|
+
std::filesystem::create_directories(camera.folder, ignored);
|
|
203
|
+
request.photo.path = camera.folder + "/" + newFileName(".jpg");
|
|
204
|
+
request.video.path = camera.folder + "/" + newFileName(".mov");
|
|
205
|
+
auto photoPath = request.photo.path;
|
|
206
|
+
auto videoPath = request.video.path;
|
|
207
|
+
camera.sheet->shoot(request, [promise, photoPath, videoPath, base64, exif](CameraTake take, const std::string &error) {
|
|
208
|
+
if (!error.empty()) {
|
|
209
|
+
promise.reject("ImagePicker: " + error);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (!take.photo && !take.video) {
|
|
213
|
+
promise.resolve(folly::dynamic::object("canceled", true)("assets", nullptr));
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const auto &path = take.video ? videoPath : photoPath;
|
|
217
|
+
std::error_code sizeError;
|
|
218
|
+
auto size = std::filesystem::file_size(path, sizeError);
|
|
219
|
+
folly::dynamic asset = folly::dynamic::object("uri", fileUri(path))("assetId", nullptr)("fileName", nullptr)(
|
|
220
|
+
"fileSize", sizeError ? folly::dynamic(nullptr) : folly::dynamic(static_cast<int64_t>(size)))("exif", nullptr)("base64", nullptr);
|
|
221
|
+
if (take.video) {
|
|
222
|
+
// As iOS answers a recorded video: no EXIF and no base64, whatever was asked.
|
|
223
|
+
asset["type"] = "video";
|
|
224
|
+
asset["width"] = take.video->width;
|
|
225
|
+
asset["height"] = take.video->height;
|
|
226
|
+
asset["mimeType"] = "video/quicktime";
|
|
227
|
+
asset["duration"] = take.video->duration;
|
|
228
|
+
} else {
|
|
229
|
+
asset["type"] = "image";
|
|
230
|
+
asset["width"] = take.photo->width;
|
|
231
|
+
asset["height"] = take.photo->height;
|
|
232
|
+
asset["mimeType"] = "image/jpeg";
|
|
233
|
+
asset["duration"] = nullptr;
|
|
234
|
+
if (exif) {
|
|
235
|
+
asset["exif"] = take.photo->exif;
|
|
236
|
+
}
|
|
237
|
+
if (base64) {
|
|
238
|
+
asset["base64"] = base64Encode(contentsOf(path));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
promise.resolve(folly::dynamic::object("canceled", false)("assets", folly::dynamic::array(std::move(asset))));
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// iOS's words for a request for videos from an app that cannot ask for the microphone.
|
|
246
|
+
constexpr const char *kMissingMicrophone =
|
|
247
|
+
"ImagePicker: Missing microphone permission. Please enable it with the `expo-image-picker` config plugin";
|
|
248
|
+
|
|
108
249
|
} // namespace
|
|
109
250
|
|
|
251
|
+
void launchPickerCamera(const PickerCamera &camera, bool noPrompts, const folly::dynamic &options, JsPromise promise) {
|
|
252
|
+
if (camera.hardware->access() != CameraHardware::Access::Granted) {
|
|
253
|
+
promise.reject("ImagePicker: Missing camera or camera roll permission");
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (noPrompts) {
|
|
257
|
+
promise.resolve(folly::dynamic::object("canceled", true)("assets", nullptr));
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (!camera.hardware->hasCamera()) {
|
|
261
|
+
promise.reject("ImagePicker: this Mac has no camera");
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
auto kinds = mediaKindsOf(options);
|
|
265
|
+
if (!kinds.videos) {
|
|
266
|
+
showPickerCamera(camera, options, kinds, false, std::move(promise));
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
// A video's sound, as iOS's camera has it: asked for when undetermined, and a video recorded with
|
|
270
|
+
// no sound when the microphone is refused. Only an app that cannot ask (no
|
|
271
|
+
// NSMicrophoneUsageDescription, so the request leaves it undetermined) is rejected, as iOS
|
|
272
|
+
// rejects it.
|
|
273
|
+
using Access = AudioInput::Access;
|
|
274
|
+
auto access = camera.microphone ? camera.microphone->access() : Access::Denied;
|
|
275
|
+
if (access != Access::NotDetermined) {
|
|
276
|
+
showPickerCamera(camera, options, kinds, access == Access::Granted, std::move(promise));
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
camera.microphone->requestAccess([camera, options, kinds, promise](Access decided) {
|
|
280
|
+
if (decided == Access::NotDetermined) {
|
|
281
|
+
promise.reject(kMissingMicrophone);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
showPickerCamera(camera, options, kinds, decided == Access::Granted, promise);
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
|
|
110
288
|
std::shared_ptr<NativeModule> makeCameraModule(
|
|
111
289
|
std::shared_ptr<CameraHardware> hardware, std::shared_ptr<CameraViews> views, std::string pictures, bool noPrompts) {
|
|
112
290
|
struct Camera : NativeModule {
|
|
@@ -114,15 +292,10 @@ std::shared_ptr<NativeModule> makeCameraModule(
|
|
|
114
292
|
: NativeModule("NgNativeCamera") {
|
|
115
293
|
using Access = CameraHardware::Access;
|
|
116
294
|
promise("getCameraPermissionsAsync", [hardware](const folly::dynamic &, JsPromise promise) {
|
|
117
|
-
promise.resolve(
|
|
295
|
+
promise.resolve(cameraPermissionOf(hardware->access()));
|
|
118
296
|
});
|
|
119
297
|
promise("requestCameraPermissionsAsync", [hardware, noPrompts](const folly::dynamic &, JsPromise promise) {
|
|
120
|
-
|
|
121
|
-
if (noPrompts || access != Access::NotDetermined) {
|
|
122
|
-
promise.resolve(permissionOf(access));
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
hardware->requestAccess([promise](Access decided) { promise.resolve(permissionOf(decided)); });
|
|
298
|
+
requestCameraPermission(*hardware, noPrompts, std::move(promise));
|
|
126
299
|
});
|
|
127
300
|
promise("isAvailableAsync", [hardware](const folly::dynamic &, JsPromise promise) { promise.resolve(hardware->hasCamera()); });
|
|
128
301
|
promise("takePicture", [hardware, views, pictures](const folly::dynamic &args, JsPromise promise) {
|
|
@@ -137,25 +310,34 @@ std::shared_ptr<NativeModule> makeCameraModule(
|
|
|
137
310
|
promise.reject("Camera is not ready yet. Wait for 'onCameraReady' callback");
|
|
138
311
|
return;
|
|
139
312
|
}
|
|
140
|
-
|
|
313
|
+
CameraPictureRequest request;
|
|
141
314
|
bool base64 = false;
|
|
142
315
|
if (options.isObject()) {
|
|
143
316
|
if (const auto *q = options.get_ptr("quality"); q && q->isNumber()) {
|
|
144
|
-
quality = std::clamp(q->asDouble(), 0.0, 1.0);
|
|
317
|
+
request.quality = std::clamp(q->asDouble(), 0.0, 1.0);
|
|
145
318
|
}
|
|
146
319
|
if (const auto *b = options.get_ptr("base64"); b && b->isBool()) {
|
|
147
320
|
base64 = b->asBool();
|
|
148
321
|
}
|
|
322
|
+
if (const auto *t = options.get_ptr("imageType"); t && !t->isNull()) {
|
|
323
|
+
if (!t->isString() || (t->asString() != "jpg" && t->asString() != "png")) {
|
|
324
|
+
promise.reject("Camera.takePicture: imageType must be 'jpg' or 'png'");
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
request.format = t->asString();
|
|
328
|
+
}
|
|
149
329
|
}
|
|
150
330
|
std::error_code ignored;
|
|
151
331
|
std::filesystem::create_directories(pictures, ignored);
|
|
152
|
-
|
|
153
|
-
|
|
332
|
+
request.path = pictures + "/" + newFileName("." + request.format);
|
|
333
|
+
auto path = request.path;
|
|
334
|
+
auto format = request.format;
|
|
335
|
+
capture->takePicture(request, [promise, path, format, base64](int width, int height, const std::string &error) {
|
|
154
336
|
if (!error.empty()) {
|
|
155
337
|
promise.reject("Camera.takePicture: " + error);
|
|
156
338
|
return;
|
|
157
339
|
}
|
|
158
|
-
folly::dynamic picture = folly::dynamic::object("uri", fileUri(path))("width", width)("height", height)("format",
|
|
340
|
+
folly::dynamic picture = folly::dynamic::object("uri", fileUri(path))("width", width)("height", height)("format", format);
|
|
159
341
|
if (base64) {
|
|
160
342
|
picture["base64"] = base64Encode(contentsOf(path));
|
|
161
343
|
}
|
|
@@ -169,7 +351,8 @@ std::shared_ptr<NativeModule> makeCameraModule(
|
|
|
169
351
|
promise.reject("Camera.record: camera permission has not been granted");
|
|
170
352
|
return;
|
|
171
353
|
}
|
|
172
|
-
|
|
354
|
+
bool muted = false;
|
|
355
|
+
auto capture = views->find(tag, &muted);
|
|
173
356
|
if (!capture) {
|
|
174
357
|
promise.reject("Camera is not ready yet. Wait for 'onCameraReady' callback");
|
|
175
358
|
return;
|
|
@@ -179,7 +362,6 @@ std::shared_ptr<NativeModule> makeCameraModule(
|
|
|
179
362
|
return;
|
|
180
363
|
}
|
|
181
364
|
CameraRecordingRequest request;
|
|
182
|
-
bool mute = false;
|
|
183
365
|
if (options.isObject()) {
|
|
184
366
|
if (const auto *d = options.get_ptr("maxDuration"); d && d->isNumber()) {
|
|
185
367
|
request.maxDuration = std::max(0.0, d->asDouble());
|
|
@@ -187,14 +369,12 @@ std::shared_ptr<NativeModule> makeCameraModule(
|
|
|
187
369
|
if (const auto *f = options.get_ptr("maxFileSize"); f && f->isNumber()) {
|
|
188
370
|
request.maxFileSize = std::max(0.0, f->asDouble());
|
|
189
371
|
}
|
|
190
|
-
if (const auto *m = options.get_ptr("mute"); m && m->isBool()) {
|
|
191
|
-
mute = m->asBool();
|
|
192
|
-
}
|
|
193
372
|
if (const auto *c = options.get_ptr("codec"); c && c->isString()) {
|
|
194
373
|
request.codec = c->asString();
|
|
195
374
|
}
|
|
196
375
|
}
|
|
197
|
-
|
|
376
|
+
// The view's `mute` prop, as on iOS, where record() takes no `mute`.
|
|
377
|
+
request.sound = !muted && hardware->microphoneAllowed();
|
|
198
378
|
std::error_code ignored;
|
|
199
379
|
std::filesystem::create_directories(pictures, ignored);
|
|
200
380
|
request.path = pictures + "/" + newFileName(".mov");
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#include "ngn/photo-library.h"
|
|
2
2
|
|
|
3
|
+
#include "ngn/camera.h"
|
|
4
|
+
|
|
3
5
|
#include <mutex>
|
|
4
6
|
#include <set>
|
|
5
7
|
#include <stdexcept>
|
|
@@ -327,9 +329,9 @@ std::shared_ptr<NativeModule> makeMediaLibraryModule(std::shared_ptr<PhotoLibrar
|
|
|
327
329
|
return std::make_shared<MediaLibrary>(std::move(library), noPrompts, std::move(files));
|
|
328
330
|
}
|
|
329
331
|
|
|
330
|
-
std::shared_ptr<NativeModule> makeImagePickerModule(std::shared_ptr<PhotoLibrary> library, bool noPrompts) {
|
|
332
|
+
std::shared_ptr<NativeModule> makeImagePickerModule(std::shared_ptr<PhotoLibrary> library, bool noPrompts, std::optional<PickerCamera> camera) {
|
|
331
333
|
struct ImagePicker : NativeModule {
|
|
332
|
-
ImagePicker(std::shared_ptr<PhotoLibrary> photos, bool noPrompts) : NativeModule("NgNativeImagePicker") {
|
|
334
|
+
ImagePicker(std::shared_ptr<PhotoLibrary> photos, bool noPrompts, std::optional<PickerCamera> camera) : NativeModule("NgNativeImagePicker") {
|
|
333
335
|
Permissions permissions{photos, noPrompts};
|
|
334
336
|
promise("getMediaLibraryPermissionsAsync", [permissions](const folly::dynamic &args, JsPromise promise) {
|
|
335
337
|
permissions.get(flagArg(args, 0), std::move(promise));
|
|
@@ -337,12 +339,24 @@ std::shared_ptr<NativeModule> makeImagePickerModule(std::shared_ptr<PhotoLibrary
|
|
|
337
339
|
promise("requestMediaLibraryPermissionsAsync", [permissions](const folly::dynamic &args, JsPromise promise) {
|
|
338
340
|
permissions.request(flagArg(args, 0), std::move(promise));
|
|
339
341
|
});
|
|
340
|
-
// No system camera to open on macOS.
|
|
341
|
-
auto noCamera = [](const folly::dynamic &, JsPromise promise) { promise.resolve(permissionOf(Access::Denied)); };
|
|
342
|
-
promise("getCameraPermissionsAsync", noCamera);
|
|
343
|
-
promise("requestCameraPermissionsAsync", noCamera);
|
|
344
342
|
folly::dynamic canceled = folly::dynamic::object("canceled", true)("assets", nullptr);
|
|
345
|
-
|
|
343
|
+
if (camera) {
|
|
344
|
+
promise("getCameraPermissionsAsync", [hardware = camera->hardware](const folly::dynamic &, JsPromise promise) {
|
|
345
|
+
promise.resolve(cameraPermissionOf(hardware->access()));
|
|
346
|
+
});
|
|
347
|
+
promise("requestCameraPermissionsAsync", [hardware = camera->hardware, noPrompts](const folly::dynamic &, JsPromise promise) {
|
|
348
|
+
requestCameraPermission(*hardware, noPrompts, std::move(promise));
|
|
349
|
+
});
|
|
350
|
+
promise("launchCameraAsync", [camera = *camera, noPrompts](const folly::dynamic &args, JsPromise promise) {
|
|
351
|
+
launchPickerCamera(camera, noPrompts, args.empty() ? folly::dynamic(nullptr) : args[0], std::move(promise));
|
|
352
|
+
});
|
|
353
|
+
} else {
|
|
354
|
+
// A host with no camera of its own to show.
|
|
355
|
+
auto noCamera = [](const folly::dynamic &, JsPromise promise) { promise.resolve(permissionOf(Access::Denied)); };
|
|
356
|
+
promise("getCameraPermissionsAsync", noCamera);
|
|
357
|
+
promise("requestCameraPermissionsAsync", noCamera);
|
|
358
|
+
promise("launchCameraAsync", [canceled](const folly::dynamic &, JsPromise promise) { promise.resolve(canceled); });
|
|
359
|
+
}
|
|
346
360
|
promise("launchImageLibraryAsync", [photos, noPrompts, canceled](const folly::dynamic &args, JsPromise promise) {
|
|
347
361
|
if (noPrompts) {
|
|
348
362
|
promise.resolve(canceled);
|
|
@@ -365,7 +379,7 @@ std::shared_ptr<NativeModule> makeImagePickerModule(std::shared_ptr<PhotoLibrary
|
|
|
365
379
|
});
|
|
366
380
|
}
|
|
367
381
|
};
|
|
368
|
-
return std::make_shared<ImagePicker>(std::move(library), noPrompts);
|
|
382
|
+
return std::make_shared<ImagePicker>(std::move(library), noPrompts, std::move(camera));
|
|
369
383
|
}
|
|
370
384
|
|
|
371
385
|
} // namespace ngn
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
#include <chrono>
|
|
7
7
|
|
|
8
8
|
#include "ngn/desktop-modal.h"
|
|
9
|
+
#include "ngn/dom-web-view.h"
|
|
9
10
|
#include "ngn/native-controls.h"
|
|
10
11
|
#include "ngn/split-view.h"
|
|
11
12
|
#include "ngn/apple-authentication.h"
|
|
@@ -70,6 +71,7 @@ MountingManager::MountingManager(
|
|
|
70
71
|
concreteComponentDescriptorProvider<AppleButtonComponentDescriptor>(),
|
|
71
72
|
concreteComponentDescriptorProvider<GlassViewComponentDescriptor>(),
|
|
72
73
|
concreteComponentDescriptorProvider<GlassContainerComponentDescriptor>(),
|
|
74
|
+
concreteComponentDescriptorProvider<DomWebViewComponentDescriptor>(),
|
|
73
75
|
concreteComponentDescriptorProvider<UnimplementedNativeViewComponentDescriptor>(),
|
|
74
76
|
};
|
|
75
77
|
for (auto &provider : expoUIComponentProviders()) {
|
|
@@ -220,12 +222,14 @@ void MountingManager::apply(SurfaceId surfaceId, const ShadowViewMutationList &m
|
|
|
220
222
|
}
|
|
221
223
|
if (old.state != view.state) {
|
|
222
224
|
backend_->updateState(view);
|
|
225
|
+
svgs_.relaidOut(tree_, view.tag);
|
|
223
226
|
if (auto sizes = controlSizes()) {
|
|
224
227
|
sizes->relaidOut(view.tag);
|
|
225
228
|
}
|
|
226
229
|
}
|
|
227
230
|
if (old.layoutMetrics != view.layoutMetrics) {
|
|
228
231
|
backend_->updateLayout(view);
|
|
232
|
+
svgs_.relaidOut(tree_, view.tag);
|
|
229
233
|
}
|
|
230
234
|
break;
|
|
231
235
|
}
|