@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
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
#import "camera-sheet.h"
|
|
2
|
+
|
|
3
|
+
#import "photo-library.h"
|
|
4
|
+
#import "system-access.h"
|
|
5
|
+
|
|
6
|
+
#import <ImageIO/ImageIO.h>
|
|
7
|
+
#import <QuartzCore/QuartzCore.h>
|
|
8
|
+
|
|
9
|
+
#include <cmath>
|
|
10
|
+
|
|
11
|
+
namespace {
|
|
12
|
+
|
|
13
|
+
// The bar under the preview that holds the buttons, and the room around them.
|
|
14
|
+
constexpr CGFloat kBar = 52;
|
|
15
|
+
constexpr CGFloat kInset = 20;
|
|
16
|
+
|
|
17
|
+
// The time recorded as iOS's camera shows it, hours, minutes and seconds.
|
|
18
|
+
NSString *elapsedText(double seconds) {
|
|
19
|
+
auto whole = static_cast<long>(std::floor(std::max(0.0, seconds)));
|
|
20
|
+
return [NSString stringWithFormat:@"%02ld:%02ld:%02ld", whole / 3600, whole / 60 % 60, whole % 60];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
} // namespace
|
|
24
|
+
|
|
25
|
+
@implementation NGNCameraSheet {
|
|
26
|
+
std::shared_ptr<ngn::appkit::SessionCapture> _capture;
|
|
27
|
+
ngn::CameraSheetRequest _request;
|
|
28
|
+
CameraSheetDone _done;
|
|
29
|
+
BOOL _running;
|
|
30
|
+
// A photo is being taken, a recording runs, or one is being stopped.
|
|
31
|
+
BOOL _taking;
|
|
32
|
+
BOOL _recording;
|
|
33
|
+
BOOL _stopping;
|
|
34
|
+
CFTimeInterval _recordingSince;
|
|
35
|
+
NSTimer *_clock;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
- (instancetype)initWithCapture:(std::shared_ptr<ngn::appkit::SessionCapture>)capture
|
|
39
|
+
request:(ngn::CameraSheetRequest)request
|
|
40
|
+
done:(CameraSheetDone)done {
|
|
41
|
+
if ((self = [super initWithNibName:nil bundle:nil])) {
|
|
42
|
+
_capture = std::move(capture);
|
|
43
|
+
_request = std::move(request);
|
|
44
|
+
_done = std::move(done);
|
|
45
|
+
// Photo mode first, as iOS's camera opens, unless only videos are asked for.
|
|
46
|
+
_videoMode = _request.videos && !_request.photos;
|
|
47
|
+
}
|
|
48
|
+
return self;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
- (void)loadView {
|
|
52
|
+
NSView *view = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 780, 560)];
|
|
53
|
+
|
|
54
|
+
_preview = [AVCaptureVideoPreviewLayer layerWithSession:_capture->session()];
|
|
55
|
+
_preview.videoGravity = AVLayerVideoGravityResizeAspectFill;
|
|
56
|
+
_preview.backgroundColor = NSColor.blackColor.CGColor;
|
|
57
|
+
// Mirrored, as a camera facing the user is shown on a Mac; the photo and the movie are not.
|
|
58
|
+
AVCaptureConnection *connection = _preview.connection;
|
|
59
|
+
if (connection.isVideoMirroringSupported) {
|
|
60
|
+
connection.automaticallyAdjustsVideoMirroring = NO;
|
|
61
|
+
connection.videoMirrored = YES;
|
|
62
|
+
}
|
|
63
|
+
NSView *preview = [[NSView alloc] initWithFrame:NSMakeRect(0, kBar, 780, 560 - kBar)];
|
|
64
|
+
preview.layer = _preview;
|
|
65
|
+
preview.wantsLayer = YES;
|
|
66
|
+
// Filled, the picture overflows the preview on one side, and must not cover the buttons' bar.
|
|
67
|
+
// AppKit sets the layer's masksToBounds from this.
|
|
68
|
+
preview.clipsToBounds = YES;
|
|
69
|
+
preview.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
|
70
|
+
[preview setAccessibilityElement:YES];
|
|
71
|
+
[preview setAccessibilityRole:NSAccessibilityImageRole];
|
|
72
|
+
[preview setAccessibilityLabel:@"Camera preview"];
|
|
73
|
+
[view addSubview:preview];
|
|
74
|
+
|
|
75
|
+
// The shutter is the default button, rightmost, as a dialog's action is; Cancel is beside it.
|
|
76
|
+
// Both are as wide as the widest title either takes, so they stay put as the shutter's changes.
|
|
77
|
+
_shutter = [NSButton buttonWithTitle:@"" target:self action:nil];
|
|
78
|
+
_shutter.keyEquivalent = @"\r";
|
|
79
|
+
_shutter.enabled = NO;
|
|
80
|
+
_cancelButton = [NSButton buttonWithTitle:@"Cancel" target:self action:@selector(cancel:)];
|
|
81
|
+
_cancelButton.keyEquivalent = @"\x1b";
|
|
82
|
+
CGFloat width = 0;
|
|
83
|
+
for (NSString *title in @[ @"Take Photo", @"Record", @"Stop", @"Cancel" ]) {
|
|
84
|
+
_shutter.title = title;
|
|
85
|
+
[_shutter sizeToFit];
|
|
86
|
+
width = std::max(width, _shutter.frame.size.width);
|
|
87
|
+
}
|
|
88
|
+
[_cancelButton sizeToFit];
|
|
89
|
+
CGFloat y = (kBar - _shutter.frame.size.height) / 2;
|
|
90
|
+
_shutter.frame = NSMakeRect(780 - kInset - width, y, width, _shutter.frame.size.height);
|
|
91
|
+
_cancelButton.frame = NSMakeRect(NSMinX(_shutter.frame) - 12 - width, y, width, _cancelButton.frame.size.height);
|
|
92
|
+
for (NSButton *button in @[ _shutter, _cancelButton ]) {
|
|
93
|
+
button.autoresizingMask = NSViewMinXMargin | NSViewMaxYMargin;
|
|
94
|
+
[view addSubview:button];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
_elapsed = [NSTextField labelWithString:elapsedText(0)];
|
|
98
|
+
_elapsed.font = [NSFont monospacedDigitSystemFontOfSize:NSFont.systemFontSize weight:NSFontWeightRegular];
|
|
99
|
+
[_elapsed sizeToFit];
|
|
100
|
+
_elapsed.frame = NSMakeRect((780 - _elapsed.frame.size.width) / 2, (kBar - _elapsed.frame.size.height) / 2, _elapsed.frame.size.width,
|
|
101
|
+
_elapsed.frame.size.height);
|
|
102
|
+
_elapsed.autoresizingMask = NSViewMinXMargin | NSViewMaxXMargin | NSViewMaxYMargin;
|
|
103
|
+
[_elapsed setAccessibilityLabel:@"Time recorded"];
|
|
104
|
+
[view addSubview:_elapsed];
|
|
105
|
+
|
|
106
|
+
if (_request.photos && _request.videos) {
|
|
107
|
+
_modeSwitch = [NSSegmentedControl segmentedControlWithLabels:@[ @"Photo", @"Video" ]
|
|
108
|
+
trackingMode:NSSegmentSwitchTrackingSelectOne
|
|
109
|
+
target:self
|
|
110
|
+
action:@selector(switchMode:)];
|
|
111
|
+
[_modeSwitch sizeToFit];
|
|
112
|
+
_modeSwitch.frame = NSMakeRect(kInset, (kBar - _modeSwitch.frame.size.height) / 2, _modeSwitch.frame.size.width, _modeSwitch.frame.size.height);
|
|
113
|
+
_modeSwitch.autoresizingMask = NSViewMaxXMargin | NSViewMaxYMargin;
|
|
114
|
+
[_modeSwitch setAccessibilityLabel:@"Camera mode"];
|
|
115
|
+
[view addSubview:_modeSwitch];
|
|
116
|
+
}
|
|
117
|
+
self.view = view;
|
|
118
|
+
[self refresh];
|
|
119
|
+
if (_videoMode) {
|
|
120
|
+
_capture->prepareRecording(_request.video);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Puts the controls in step with the mode and what is under way.
|
|
125
|
+
- (void)refresh {
|
|
126
|
+
if (!self.viewLoaded) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
BOOL answered = !_done;
|
|
130
|
+
if (_videoMode) {
|
|
131
|
+
_shutter.title = _recording ? @"Stop" : @"Record";
|
|
132
|
+
_shutter.action = @selector(record:);
|
|
133
|
+
} else {
|
|
134
|
+
_shutter.title = @"Take Photo";
|
|
135
|
+
_shutter.action = @selector(takePhoto:);
|
|
136
|
+
}
|
|
137
|
+
_shutter.enabled = _running && !answered && !_taking && !_stopping;
|
|
138
|
+
_elapsed.hidden = !_videoMode;
|
|
139
|
+
_modeSwitch.selectedSegment = _videoMode ? 1 : 0;
|
|
140
|
+
_modeSwitch.enabled = !answered && !_taking && !_recording && !_stopping;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
- (void)cameraRunning {
|
|
144
|
+
_running = YES;
|
|
145
|
+
[self refresh];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
- (void)switchMode:(id)sender {
|
|
149
|
+
// Fixed while recording or once answered: the switch goes back to the mode in use.
|
|
150
|
+
BOOL video = _modeSwitch.selectedSegment == 1;
|
|
151
|
+
if (_modeSwitch.enabled && video != _videoMode) {
|
|
152
|
+
_videoMode = video;
|
|
153
|
+
// The camera is set up for video as the mode changes, as iOS's is, so Record starts at once.
|
|
154
|
+
if (_videoMode) {
|
|
155
|
+
_capture->prepareRecording(_request.video);
|
|
156
|
+
} else {
|
|
157
|
+
_capture->unprepareRecording();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
[self refresh];
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
- (void)takePhoto:(id)sender {
|
|
164
|
+
// Disabled until the camera runs, while a photo is taken, and once answered.
|
|
165
|
+
if (_videoMode || !_shutter.enabled) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
_taking = YES;
|
|
169
|
+
[self refresh];
|
|
170
|
+
NGNCameraSheet *sheet = self;
|
|
171
|
+
ngn::CameraPictureRequest request = _request.photo;
|
|
172
|
+
_capture->capturePhoto([sheet, request](CGImageRef image, NSDictionary *metadata, const std::string &error) {
|
|
173
|
+
std::optional<ngn::CameraShot> shot;
|
|
174
|
+
std::string failure = error;
|
|
175
|
+
if (image != nullptr) {
|
|
176
|
+
if (ngn::appkit::writePicture(image, request)) {
|
|
177
|
+
shot = ngn::CameraShot{.width = static_cast<int>(CGImageGetWidth(image)), .height = static_cast<int>(CGImageGetHeight(image))};
|
|
178
|
+
} else {
|
|
179
|
+
failure = "the picture could not be saved";
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
NSDictionary *exif = metadata[(__bridge NSString *)kCGImagePropertyExifDictionary];
|
|
183
|
+
// Decided on the main queue, where a cancel is too: a photo answered after a cancel is not
|
|
184
|
+
// kept.
|
|
185
|
+
std::string path = request.path;
|
|
186
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
187
|
+
if (![sheet finish:{.photo = shot} exif:exif error:failure] && shot) {
|
|
188
|
+
[NSFileManager.defaultManager removeItemAtPath:@(path.c_str()) error:nil];
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
- (void)record:(id)sender {
|
|
195
|
+
if (!_videoMode || !_shutter.enabled) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (_recording) {
|
|
199
|
+
_stopping = YES;
|
|
200
|
+
[self refresh];
|
|
201
|
+
_capture->stopRecording();
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
_recording = YES;
|
|
205
|
+
_recordingSince = CACurrentMediaTime();
|
|
206
|
+
_elapsed.stringValue = elapsedText(0);
|
|
207
|
+
__weak NGNCameraSheet *weakSheet = self;
|
|
208
|
+
_clock = [NSTimer scheduledTimerWithTimeInterval:0.25
|
|
209
|
+
repeats:YES
|
|
210
|
+
block:^(NSTimer *timer) {
|
|
211
|
+
[weakSheet showElapsed];
|
|
212
|
+
}];
|
|
213
|
+
[self refresh];
|
|
214
|
+
NGNCameraSheet *sheet = self;
|
|
215
|
+
_capture->startRecording(_request.video, [sheet](const std::string &error) {
|
|
216
|
+
std::string failure = error;
|
|
217
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
218
|
+
[sheet recordingEnded:failure];
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
- (void)showElapsed {
|
|
224
|
+
_elapsed.stringValue = elapsedText(CACurrentMediaTime() - _recordingSince);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// The movie is finished: at Stop, at the request's limit, or as the sheet went another way.
|
|
228
|
+
- (void)recordingEnded:(std::string)error {
|
|
229
|
+
_recording = NO;
|
|
230
|
+
_stopping = NO;
|
|
231
|
+
[_clock invalidate];
|
|
232
|
+
_clock = nil;
|
|
233
|
+
NSString *path = @(_request.video.path.c_str());
|
|
234
|
+
if (!_done) {
|
|
235
|
+
// Cancelled while it recorded: nothing answers for the movie.
|
|
236
|
+
[NSFileManager.defaultManager removeItemAtPath:path error:nil];
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (!error.empty()) {
|
|
240
|
+
// Whatever of it was written is no movie.
|
|
241
|
+
[NSFileManager.defaultManager removeItemAtPath:path error:nil];
|
|
242
|
+
[self finish:{} exif:nil error:error];
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
auto clip = ngn::appkit::movieClip(_request.video.path);
|
|
246
|
+
if (!clip) {
|
|
247
|
+
[NSFileManager.defaultManager removeItemAtPath:path error:nil];
|
|
248
|
+
[self finish:{} exif:nil error:"the video could not be read"];
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
[self finish:{.video = clip} exif:nil error:""];
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
- (void)cancel:(id)sender {
|
|
255
|
+
[self finish:{} exif:nil error:""];
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// The window going another way (its parent closed, say) is a cancel.
|
|
259
|
+
- (void)viewDidDisappear {
|
|
260
|
+
[super viewDidDisappear];
|
|
261
|
+
[self finish:{} exif:nil error:""];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Answers once, stops the camera (and with it a recording) and lets the sheet go; NO when it was
|
|
265
|
+
// answered already.
|
|
266
|
+
- (BOOL)finish:(ngn::CameraTake)take exif:(NSDictionary *)exif error:(std::string)error {
|
|
267
|
+
if (!_done) {
|
|
268
|
+
return NO;
|
|
269
|
+
}
|
|
270
|
+
auto done = std::move(_done);
|
|
271
|
+
_done = nullptr;
|
|
272
|
+
[self refresh];
|
|
273
|
+
_capture->stop();
|
|
274
|
+
NSWindow *window = self.viewLoaded ? self.view.window : nil;
|
|
275
|
+
if (window.sheetParent != nil) {
|
|
276
|
+
[window.sheetParent endSheet:window];
|
|
277
|
+
}
|
|
278
|
+
done(std::move(take), exif, error);
|
|
279
|
+
return YES;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
@end
|
|
283
|
+
|
|
284
|
+
namespace ngn::appkit {
|
|
285
|
+
|
|
286
|
+
NSWindow *windowForSheet() {
|
|
287
|
+
if (NSApp.keyWindow != nil) {
|
|
288
|
+
return NSApp.keyWindow;
|
|
289
|
+
}
|
|
290
|
+
if (NSApp.mainWindow != nil) {
|
|
291
|
+
return NSApp.mainWindow;
|
|
292
|
+
}
|
|
293
|
+
// An app that is not active has neither, as just after the OS asked for the microphone in a
|
|
294
|
+
// window of its own: its front window that can hold a sheet.
|
|
295
|
+
for (NSWindow *window in NSApp.orderedWindows) {
|
|
296
|
+
if (window.visible && window.sheetParent == nil && window.attachedSheet == nil && window.canBecomeMainWindow) {
|
|
297
|
+
return window;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return nil;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
namespace {
|
|
304
|
+
|
|
305
|
+
class SheetCamera final : public CameraSheet {
|
|
306
|
+
public:
|
|
307
|
+
void shoot(const CameraSheetRequest &request, std::function<void(CameraTake, const std::string &)> done) override {
|
|
308
|
+
auto answer = std::make_shared<std::function<void(CameraTake, const std::string &)>>(std::move(done));
|
|
309
|
+
CameraSheetRequest asked = request;
|
|
310
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
311
|
+
NSWindow *window = windowForSheet();
|
|
312
|
+
if (window == nil) {
|
|
313
|
+
(*answer)({}, "");
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
auto controller = std::make_shared<NGNCameraSheet *>(nil);
|
|
317
|
+
std::string error;
|
|
318
|
+
auto capture = startCapture(cameraFor("front"), error, [controller] { [*controller cameraRunning]; });
|
|
319
|
+
if (!capture) {
|
|
320
|
+
(*answer)({}, error);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
NGNCameraSheet *sheet = [[NGNCameraSheet alloc] initWithCapture:capture
|
|
324
|
+
request:asked
|
|
325
|
+
done:[answer, controller](CameraTake take, NSDictionary *exif, const std::string &failure) {
|
|
326
|
+
*controller = nil;
|
|
327
|
+
if (take.photo) {
|
|
328
|
+
take.photo->exif = dynamicFrom(exif);
|
|
329
|
+
}
|
|
330
|
+
(*answer)(std::move(take), failure);
|
|
331
|
+
}];
|
|
332
|
+
*controller = sheet;
|
|
333
|
+
[window beginSheet:pickerSheet(sheet, window) completionHandler:nil];
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
} // namespace
|
|
339
|
+
|
|
340
|
+
std::shared_ptr<CameraSheet> makeCameraSheet() {
|
|
341
|
+
return std::make_shared<SheetCamera>();
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
} // namespace ngn::appkit
|
|
@@ -51,9 +51,13 @@ bool gNoPrompts = false;
|
|
|
51
51
|
_preview.frame = self.bounds;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
// Starts or stops the camera as `active` and the permission say
|
|
54
|
+
// Starts or stops the camera as `active` and the permission say, and passes `mute` on for the
|
|
55
|
+
// recordings NgNativeCamera starts. Set first, so the camera is never attached without it.
|
|
55
56
|
- (void)follow {
|
|
56
57
|
auto props = std::dynamic_pointer_cast<const ngn::CameraProps>(self.props);
|
|
58
|
+
if (props && gViews) {
|
|
59
|
+
gViews->mute(static_cast<int>(self.reactTag), props->mute);
|
|
60
|
+
}
|
|
57
61
|
if (!props || !gHardware || !self.eventEmitter) {
|
|
58
62
|
return;
|
|
59
63
|
}
|
package/native/appkit/camera.h
CHANGED
|
@@ -9,12 +9,20 @@
|
|
|
9
9
|
|
|
10
10
|
#include <functional>
|
|
11
11
|
#include <memory>
|
|
12
|
+
#include <optional>
|
|
12
13
|
#include <string>
|
|
13
14
|
|
|
14
15
|
namespace ngn::appkit {
|
|
15
16
|
|
|
16
17
|
std::shared_ptr<CameraHardware> makeCameraHardware();
|
|
17
18
|
|
|
19
|
+
// Writes `image` to the request's path as its format asks: a JPEG at its quality, or a PNG.
|
|
20
|
+
bool writePicture(CGImageRef image, const CameraPictureRequest &request);
|
|
21
|
+
|
|
22
|
+
// A movie's size as it plays and its length in milliseconds, read as expo-image-picker reads a
|
|
23
|
+
// video's on iOS; nothing for a file with no video.
|
|
24
|
+
std::optional<CameraClip> movieClip(const std::string &path);
|
|
25
|
+
|
|
18
26
|
// The camera a view facing `facing` uses: the built-in one, else the first there is; nil on a Mac
|
|
19
27
|
// with none.
|
|
20
28
|
AVCaptureDevice *cameraFor(const std::string &facing);
|
|
@@ -22,13 +30,27 @@ AVCaptureDevice *cameraFor(const std::string &facing);
|
|
|
22
30
|
// A capture session with a photo output. Starting and stopping run on a queue of the capture's
|
|
23
31
|
// own, since AVCaptureSession's startRunning and stopRunning block while the camera comes up or
|
|
24
32
|
// goes down, which can take a second (a Continuity Camera longer).
|
|
33
|
+
// A still's image (owned by the capture, valid during the call) and the camera's metadata, or
|
|
34
|
+
// a null image and why. On whatever thread the photo output answers on.
|
|
35
|
+
using PhotoDone = std::function<void(CGImageRef image, NSDictionary *metadata, const std::string &error)>;
|
|
36
|
+
|
|
25
37
|
class SessionCapture : public CameraCapture {
|
|
26
38
|
public:
|
|
27
39
|
virtual AVCaptureSession *session() const = 0;
|
|
40
|
+
// Takes a still from the running session.
|
|
41
|
+
virtual void capturePhoto(PhotoDone done) = 0;
|
|
42
|
+
// A still written as `request` asks (writePicture).
|
|
43
|
+
void takePicture(const CameraPictureRequest &request, std::function<void(int, int, const std::string &)> done) final;
|
|
28
44
|
// Starts the session, then calls `running` on the main thread.
|
|
29
45
|
virtual void start(std::function<void()> running) = 0;
|
|
30
46
|
// Stops it, without waiting. Going away stops it too.
|
|
31
47
|
virtual void stop() = 0;
|
|
48
|
+
// Sets the session up for startRecording(request) ahead of it (its preset, the movie output and,
|
|
49
|
+
// with sound, the microphone), since the camera takes a moment to reconfigure. Nothing while a
|
|
50
|
+
// recording runs; a recording takes the setup down when it ends.
|
|
51
|
+
virtual void prepareRecording(const CameraRecordingRequest &request) = 0;
|
|
52
|
+
// Takes a prepared setup down, putting the session's preset back. Nothing while a recording runs.
|
|
53
|
+
virtual void unprepareRecording() = 0;
|
|
32
54
|
};
|
|
33
55
|
// A capture session on `device`, started (`running` is called on the main thread once it is), or
|
|
34
56
|
// null with `error` set: never without the camera allowed, so it never prompts.
|