@ng-native/desktop 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/native/CMakeLists.txt +3 -2
- package/native/appkit/CMakeLists.txt +25 -4
- 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/main.mm +29 -69
- package/native/appkit/photo-library.mm +6 -6
- 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 +1 -1
- package/native/appkit/text-layout.mm +16 -8
- 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/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/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/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 +20 -13
- 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/svg.cpp +324 -17
- package/native/core/src/text-input.cpp +13 -0
- package/native/core/src/web-view.cpp +1 -1
- package/native/scripts/build.sh +5 -1
- package/native/scripts/launch-probe.sh +60 -0
- package/package.json +2 -2
- package/prebuilt.json +6 -6
|
@@ -55,6 +55,30 @@ struct FoundationCharacters final : ngn::TextCharacters {
|
|
|
55
55
|
mutable std::size_t convertedSize_{0};
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
+
// A placeholder in `font` and `color` (nil is the system's placeholder colour), aligned and
|
|
59
|
+
// directed as the text is, the way React Native iOS gives it the text's paragraph style. Nil when
|
|
60
|
+
// there is no placeholder.
|
|
61
|
+
NSAttributedString *placeholderString(
|
|
62
|
+
NSString *placeholder,
|
|
63
|
+
NSFont *font,
|
|
64
|
+
NSColor *color,
|
|
65
|
+
NSTextAlignment alignment,
|
|
66
|
+
NSWritingDirection direction) {
|
|
67
|
+
if (placeholder.length == 0) {
|
|
68
|
+
return nil;
|
|
69
|
+
}
|
|
70
|
+
NSMutableParagraphStyle *style = [NSParagraphStyle.defaultParagraphStyle mutableCopy];
|
|
71
|
+
style.alignment = alignment;
|
|
72
|
+
style.baseWritingDirection = direction;
|
|
73
|
+
return [[NSAttributedString alloc]
|
|
74
|
+
initWithString:placeholder
|
|
75
|
+
attributes:@{
|
|
76
|
+
NSFontAttributeName : font ? font : [NSFont systemFontOfSize:NSFont.systemFontSize],
|
|
77
|
+
NSForegroundColorAttributeName : color ? color : NSColor.placeholderTextColor,
|
|
78
|
+
NSParagraphStyleAttributeName : style,
|
|
79
|
+
}];
|
|
80
|
+
}
|
|
81
|
+
|
|
58
82
|
} // namespace
|
|
59
83
|
|
|
60
84
|
NSString *NGNFitReplacement(NSString *current, NSRange range, NSString *replacement, const TextInputOptions &options) {
|
|
@@ -113,6 +137,7 @@ NSDictionary<NSTextCheckingOptionKey, id> *NGNTextCheckingOptions(
|
|
|
113
137
|
|
|
114
138
|
@interface NGNTextField ()
|
|
115
139
|
- (void)controlDidBecomeFirstResponder;
|
|
140
|
+
- (void)controlDidEndEditing;
|
|
116
141
|
@end
|
|
117
142
|
|
|
118
143
|
// The two controls a field swaps between. AppKit's secure field editor takes only an
|
|
@@ -126,6 +151,10 @@ NSDictionary<NSTextCheckingOptionKey, id> *NGNTextCheckingOptions(
|
|
|
126
151
|
[self.box controlDidBecomeFirstResponder]; \
|
|
127
152
|
return YES; \
|
|
128
153
|
} \
|
|
154
|
+
-(void)textDidEndEditing : (NSNotification *)note { \
|
|
155
|
+
[super textDidEndEditing:note]; \
|
|
156
|
+
[self.box controlDidEndEditing]; \
|
|
157
|
+
} \
|
|
129
158
|
-(BOOL)textView : (NSTextView *)textView shouldChangeTextInRange : (NSRange)range replacementString \
|
|
130
159
|
: (NSString *)string { \
|
|
131
160
|
static const TextInputOptions none{}; \
|
|
@@ -219,10 +248,16 @@ NGN_FIELD_CELL_METHODS
|
|
|
219
248
|
TextInputOptions _options;
|
|
220
249
|
NSRange _pendingSelection;
|
|
221
250
|
BOOL _autoFocused;
|
|
251
|
+
NSString *_placeholder;
|
|
252
|
+
NSColor *_placeholderColor;
|
|
253
|
+
NSTextAlignment _alignment;
|
|
254
|
+
NSWritingDirection _writingDirection;
|
|
222
255
|
}
|
|
223
256
|
|
|
224
257
|
- (instancetype)initWithFrame:(NSRect)frame {
|
|
225
258
|
if ((self = [super initWithFrame:frame])) {
|
|
259
|
+
_alignment = NSTextAlignmentNatural;
|
|
260
|
+
_writingDirection = NSWritingDirectionNatural;
|
|
226
261
|
_pendingSelection = NSMakeRange(NSNotFound, 0);
|
|
227
262
|
NGNPlainField *control = [[NGNPlainField alloc] initWithFrame:self.bounds];
|
|
228
263
|
control.box = self;
|
|
@@ -290,7 +325,8 @@ NGN_FIELD_CELL_METHODS
|
|
|
290
325
|
control.autoresizingMask = old.autoresizingMask;
|
|
291
326
|
control.font = old.font;
|
|
292
327
|
control.textColor = old.textColor;
|
|
293
|
-
control.alignment =
|
|
328
|
+
control.alignment = _alignment;
|
|
329
|
+
control.baseWritingDirection = _writingDirection;
|
|
294
330
|
control.placeholderAttributedString = old.placeholderAttributedString;
|
|
295
331
|
control.editable = old.editable;
|
|
296
332
|
control.selectable = old.selectable;
|
|
@@ -318,17 +354,44 @@ NGN_FIELD_CELL_METHODS
|
|
|
318
354
|
}
|
|
319
355
|
|
|
320
356
|
- (void)setPlaceholder:(NSString *)placeholder color:(NSColor *)color {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
357
|
+
_placeholder = [placeholder copy];
|
|
358
|
+
_placeholderColor = color;
|
|
359
|
+
_control.placeholderAttributedString =
|
|
360
|
+
placeholderString(placeholder, _control.font, color, _alignment, _writingDirection);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
- (void)setTextAlignment:(NSTextAlignment)alignment writingDirection:(NSWritingDirection)direction {
|
|
364
|
+
BOOL changed = alignment != _alignment || direction != _writingDirection;
|
|
365
|
+
_alignment = alignment;
|
|
366
|
+
_writingDirection = direction;
|
|
367
|
+
// Setting a control's alignment while it edits ends the editing, so the field editor takes it
|
|
368
|
+
// now, and the control as the editing ends (the field editor takes the control's as it starts).
|
|
369
|
+
// An editing aborted tells the control nothing, so a control out of step is put right on the
|
|
370
|
+
// next request, though the request has not changed.
|
|
371
|
+
if (NSText *editor = _control.currentEditor) {
|
|
372
|
+
if (changed) {
|
|
373
|
+
editor.alignment = alignment;
|
|
374
|
+
editor.baseWritingDirection = direction;
|
|
375
|
+
}
|
|
376
|
+
} else {
|
|
377
|
+
[self alignControl];
|
|
324
378
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
379
|
+
if (changed) {
|
|
380
|
+
[self setPlaceholder:_placeholder color:_placeholderColor];
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
- (void)alignControl {
|
|
385
|
+
if (_control.alignment != _alignment) {
|
|
386
|
+
_control.alignment = _alignment;
|
|
387
|
+
}
|
|
388
|
+
if (_control.baseWritingDirection != _writingDirection) {
|
|
389
|
+
_control.baseWritingDirection = _writingDirection;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
- (void)controlDidEndEditing {
|
|
394
|
+
[self alignControl];
|
|
332
395
|
}
|
|
333
396
|
|
|
334
397
|
- (void)selectRange:(NSRange)range {
|
|
@@ -369,6 +432,18 @@ NGN_FIELD_CELL_METHODS
|
|
|
369
432
|
TextInputOptions _options;
|
|
370
433
|
BOOL _autoFocused;
|
|
371
434
|
BOOL _inserting;
|
|
435
|
+
NSString *_placeholderText;
|
|
436
|
+
NSColor *_placeholderColor;
|
|
437
|
+
NSTextAlignment _textAlignment;
|
|
438
|
+
NSWritingDirection _writingDirection;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
- (instancetype)initWithFrame:(NSRect)frame textContainer:(NSTextContainer *)container {
|
|
442
|
+
if ((self = [super initWithFrame:frame textContainer:container])) {
|
|
443
|
+
_textAlignment = NSTextAlignmentNatural;
|
|
444
|
+
_writingDirection = NSWritingDirectionNatural;
|
|
445
|
+
}
|
|
446
|
+
return self;
|
|
372
447
|
}
|
|
373
448
|
|
|
374
449
|
- (void)applyOptions:(const TextInputOptions &)options {
|
|
@@ -376,16 +451,22 @@ NGN_FIELD_CELL_METHODS
|
|
|
376
451
|
NGNApplyTextOptions(self, _options);
|
|
377
452
|
}
|
|
378
453
|
|
|
379
|
-
- (void)
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
next = [[NSAttributedString alloc]
|
|
383
|
-
initWithString:placeholder
|
|
384
|
-
attributes:@{
|
|
385
|
-
NSFontAttributeName : self.font ? self.font : [NSFont systemFontOfSize:NSFont.systemFontSize],
|
|
386
|
-
NSForegroundColorAttributeName : color ? color : NSColor.placeholderTextColor,
|
|
387
|
-
}];
|
|
454
|
+
- (void)setTextAlignment:(NSTextAlignment)alignment writingDirection:(NSWritingDirection)direction {
|
|
455
|
+
if (alignment == _textAlignment && direction == _writingDirection) {
|
|
456
|
+
return;
|
|
388
457
|
}
|
|
458
|
+
_textAlignment = alignment;
|
|
459
|
+
_writingDirection = direction;
|
|
460
|
+
// The text there is now, and what is typed or set later (a plain text view's typing attributes).
|
|
461
|
+
self.alignment = alignment;
|
|
462
|
+
self.baseWritingDirection = direction;
|
|
463
|
+
[self setPlaceholder:_placeholderText color:_placeholderColor];
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
- (void)setPlaceholder:(NSString *)placeholder color:(NSColor *)color {
|
|
467
|
+
_placeholderText = [placeholder copy];
|
|
468
|
+
_placeholderColor = color;
|
|
469
|
+
NSAttributedString *next = placeholderString(placeholder, self.font, color, _textAlignment, _writingDirection);
|
|
389
470
|
if (![next isEqualToAttributedString:_placeholder] && !(next == nil && _placeholder == nil)) {
|
|
390
471
|
_placeholder = [next copy];
|
|
391
472
|
self.needsDisplay = YES;
|
|
@@ -16,7 +16,7 @@ struct TextLine {
|
|
|
16
16
|
CTLineRef line; // owned by the layout
|
|
17
17
|
CGPoint origin; // baseline origin, y measured from the top of the text box
|
|
18
18
|
CGFloat width;
|
|
19
|
-
bool rightToLeft{false}; // its paragraph runs right to left, so
|
|
19
|
+
bool rightToLeft{false}; // its paragraph runs right to left, so a justified last line is on the right
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
struct TextLayout {
|
|
@@ -86,14 +86,22 @@ CTFontRef makeFont(const TextAttributes &a) {
|
|
|
86
86
|
return (CTFontRef)CFBridgingRetain(font);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
// A fragment's alignment as React Native iOS resolves it (RCTResolveTextAlignment): in a
|
|
90
|
+
// right-to-left layout, natural and start go right, end goes left, and left and right swap. Text
|
|
91
|
+
// with no alignment follows the layout's direction too, not its own script, as TextKit's natural
|
|
92
|
+
// alignment follows the app's direction on iOS: a Hebrew paragraph in a left-to-right layout is on
|
|
93
|
+
// the left.
|
|
94
|
+
CTTextAlignment ctAlignment(std::optional<TextAlignment> alignment, std::optional<LayoutDirection> layoutDirection) {
|
|
95
|
+
bool rightToLeft = layoutDirection == LayoutDirection::RightToLeft;
|
|
96
|
+
CTTextAlignment start = rightToLeft ? kCTTextAlignmentRight : kCTTextAlignmentLeft;
|
|
97
|
+
CTTextAlignment end = rightToLeft ? kCTTextAlignmentLeft : kCTTextAlignmentRight;
|
|
90
98
|
switch (alignment.value_or(TextAlignment::Natural)) {
|
|
91
|
-
case TextAlignment::Left: return kCTTextAlignmentLeft;
|
|
92
99
|
case TextAlignment::Center: return kCTTextAlignmentCenter;
|
|
93
|
-
case TextAlignment::Right: return kCTTextAlignmentRight;
|
|
94
100
|
case TextAlignment::Justified: return kCTTextAlignmentJustified;
|
|
95
|
-
case TextAlignment::
|
|
96
|
-
|
|
101
|
+
case TextAlignment::Left: return start;
|
|
102
|
+
case TextAlignment::Right:
|
|
103
|
+
case TextAlignment::End: return end;
|
|
104
|
+
default: return start;
|
|
97
105
|
}
|
|
98
106
|
}
|
|
99
107
|
|
|
@@ -312,7 +320,7 @@ CFAttributedStringRef makeAttributedString(const AttributedString &attributedStr
|
|
|
312
320
|
|
|
313
321
|
// Paragraph style: alignment, and lineHeight as a fixed line box (as React Native iOS does),
|
|
314
322
|
// with the glyphs centred in it through a baseline offset applied at draw time.
|
|
315
|
-
CTTextAlignment alignment = ctAlignment(a.alignment);
|
|
323
|
+
CTTextAlignment alignment = ctAlignment(a.alignment, a.layoutDirection);
|
|
316
324
|
CTWritingDirection direction = ctWritingDirection(a.baseWritingDirection);
|
|
317
325
|
CGFloat lineHeight = 0;
|
|
318
326
|
if (!std::isnan(a.lineHeight) && a.lineHeight > 0) {
|
|
@@ -454,8 +462,8 @@ void drawText(const TextLayout &layout, CGContextRef context, CGPoint origin, CG
|
|
|
454
462
|
x = (boxWidth - l.width) / 2;
|
|
455
463
|
} else if (alignment == kCTTextAlignmentRight) {
|
|
456
464
|
x = boxWidth - l.width;
|
|
457
|
-
} else if (
|
|
458
|
-
//
|
|
465
|
+
} else if (alignment == kCTTextAlignmentJustified && l.rightToLeft) {
|
|
466
|
+
// A justified paragraph's last line follows the paragraph's direction.
|
|
459
467
|
x = boxWidth - l.width;
|
|
460
468
|
}
|
|
461
469
|
CGContextSetTextPosition(context, origin.x + x, origin.y + l.origin.y);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
// RNCWebView's mounted view on macOS: an NGNView holding an
|
|
2
|
-
// configured from the library's props through the glue
|
|
3
|
-
//
|
|
1
|
+
// RNCWebView's mounted view on macOS, and Expo's DOM web view's: an NGNView holding an
|
|
2
|
+
// NGNWebViewController's WKWebView, configured from the library's props through the glue
|
|
3
|
+
// (libraryGlue().webViewConfig) or from Expo's (domWebViewConfig, dom-web-view.h), its events sent
|
|
4
|
+
// through the view's event emitter and its commands handed to the controller.
|
|
4
5
|
#pragma once
|
|
5
6
|
|
|
6
7
|
#import "host-view.h"
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
#import "web-view.h"
|
|
4
4
|
|
|
5
|
+
#include "ngn/dom-web-view.h"
|
|
5
6
|
#include "ngn/library-glue.h"
|
|
6
7
|
|
|
7
8
|
@implementation NGNWebView {
|
|
@@ -32,8 +33,13 @@
|
|
|
32
33
|
|
|
33
34
|
- (void)updateProps:(const facebook::react::Props::Shared &)props {
|
|
34
35
|
[super updateProps:props];
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
if (!props) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
auto config = ngn::domWebViewConfig(*props);
|
|
40
|
+
if (auto &glue = ngn::libraryGlue(); !config && glue.webViewConfig) {
|
|
41
|
+
config = glue.webViewConfig(*props);
|
|
42
|
+
}
|
|
37
43
|
if (!config) {
|
|
38
44
|
return;
|
|
39
45
|
}
|
|
@@ -289,6 +289,13 @@ bool sameScripts(const WebViewConfig &a, const WebViewConfig &b) {
|
|
|
289
289
|
return;
|
|
290
290
|
}
|
|
291
291
|
auto step = _config ? ngn::navigationStep(*_config, url, topFrame, str(type)) : ngn::NavigationStep::AskApp;
|
|
292
|
+
if (step == ngn::NavigationStep::Allow) {
|
|
293
|
+
if (topFrame) {
|
|
294
|
+
[self send:"loadingStart" extra:folly::dynamic::object("url", url)("navigationType", str(type))];
|
|
295
|
+
}
|
|
296
|
+
decisionHandler(WKNavigationActionPolicyAllow);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
292
299
|
if (step != ngn::NavigationStep::AskApp) {
|
|
293
300
|
decisionHandler(WKNavigationActionPolicyCancel);
|
|
294
301
|
if (step == ngn::NavigationStep::OpenExternally && _openExternally) {
|
|
@@ -44,9 +44,10 @@ KeyChord parseChord(const folly::dynamic &chord);
|
|
|
44
44
|
enum class NavigationDirection { Back, Forward };
|
|
45
45
|
enum class NavigationInput { MouseButton4, MouseButton5, SwipeLeft, SwipeRight };
|
|
46
46
|
|
|
47
|
-
// The OS's back and forward inputs: mouse buttons 4 and 5, a swipe (right goes back
|
|
48
|
-
//
|
|
49
|
-
|
|
47
|
+
// The OS's back and forward inputs: mouse buttons 4 and 5, a swipe (right goes back in a
|
|
48
|
+
// left-to-right layout and left in a right-to-left one, as a page follows the fingers and as Safari
|
|
49
|
+
// swaps them), and Cmd-[ and Cmd-]. Cmd-Left stays with text editing.
|
|
50
|
+
std::optional<NavigationDirection> navigationFor(NavigationInput input, bool rightToLeft = false);
|
|
50
51
|
std::optional<NavigationDirection> navigationFor(const KeyChord &chord);
|
|
51
52
|
|
|
52
53
|
// A window's back and forward history, as the app's router reports it (`setHistory`): the titles
|
|
@@ -82,6 +83,10 @@ struct HistoryMenuItem {
|
|
|
82
83
|
};
|
|
83
84
|
std::vector<HistoryMenuItem> historyMenu(const WindowHistory &history, NavigationDirection direction);
|
|
84
85
|
|
|
86
|
+
// Which chevron a point `x` across the pair (`width` wide) is on: back leads, so it is the left
|
|
87
|
+
// one, and the right one in a right-to-left layout.
|
|
88
|
+
NavigationDirection chevronAt(double x, double width, bool rightToLeft);
|
|
89
|
+
|
|
85
90
|
class MenuBackend {
|
|
86
91
|
public:
|
|
87
92
|
virtual ~MenuBackend() = default;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// An interactive back swipe on a native stack, the same on every toolkit: as two fingers move
|
|
2
|
-
// towards back
|
|
2
|
+
// towards back (right in a left-to-right layout, left in a right-to-left one, as Safari and Finder
|
|
3
|
+
// swipe), the screen in front follows them and the screen below it shows; released past
|
|
3
4
|
// the threshold it goes back, released early it slides home. A forward swipe has no page to drag
|
|
4
5
|
// in, so it completes and then swaps (navigationFor in app-menus.h).
|
|
5
6
|
//
|
|
@@ -29,7 +30,8 @@ struct BackSwipeTarget {
|
|
|
29
30
|
|
|
30
31
|
// What the toolkit draws at one moment of a swipe.
|
|
31
32
|
struct BackSwipeFrame {
|
|
32
|
-
// How far
|
|
33
|
+
// How far the top screen has moved, in points: right in a left-to-right layout, left (negative)
|
|
34
|
+
// in a right-to-left one.
|
|
33
35
|
double offset{0};
|
|
34
36
|
// The top screen's opacity.
|
|
35
37
|
double opacity{1};
|
|
@@ -59,15 +61,16 @@ class BackSwipe {
|
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
// Fingers began a sideways scroll in a window `width` wide whose front stack can go back to
|
|
62
|
-
// `target
|
|
63
|
-
|
|
64
|
+
// `target`, laid out right to left or not. False, and nothing to draw, without a target or while
|
|
65
|
+
// another swipe runs.
|
|
66
|
+
bool begin(std::optional<BackSwipeTarget> target, double width, bool rightToLeft = false);
|
|
64
67
|
// The fingers moved `dx` points towards back (negative away from it). The frame to draw.
|
|
65
68
|
BackSwipeFrame moved(double dx);
|
|
66
69
|
// The fingers lifted. True when the swipe goes back: past a third of the width, or flicked
|
|
67
70
|
// towards back (its last move at least kFlick points) past a tenth. Otherwise, or when the OS
|
|
68
71
|
// cancelled the scroll, it returns.
|
|
69
72
|
bool lifted(bool cancelled = false);
|
|
70
|
-
// Where the swipe settles once lifted: off
|
|
73
|
+
// Where the swipe settles once lifted: off towards back (or faded out) when leaving, home when
|
|
71
74
|
// returning.
|
|
72
75
|
BackSwipeFrame settled() const;
|
|
73
76
|
// The return animation finished: the swipe is over, and the toolkit draws `rest()`.
|
|
@@ -96,17 +99,23 @@ class BackSwipe {
|
|
|
96
99
|
Phase phase_{Phase::Idle};
|
|
97
100
|
std::optional<BackSwipeTarget> target_;
|
|
98
101
|
double width_{0};
|
|
102
|
+
bool rightToLeft_{false};
|
|
99
103
|
double offset_{0};
|
|
100
104
|
double lastMove_{0};
|
|
101
105
|
};
|
|
102
106
|
|
|
107
|
+
// How far fingers that moved `right` points to the right went towards back: back is to the right
|
|
108
|
+
// in a left-to-right layout and to the left in a right-to-left one.
|
|
109
|
+
double towardsBack(double right, bool rightToLeft);
|
|
110
|
+
|
|
103
111
|
// The range a swipe tracker may move in, as AppKit's trackSwipeEvent takes it: -1 lets the fingers
|
|
104
|
-
// go
|
|
112
|
+
// go left, 1 right, and 0 shuts that way. Right goes back in a left-to-right layout, and forward in
|
|
113
|
+
// a right-to-left one.
|
|
105
114
|
struct SwipeBounds {
|
|
106
115
|
double min{0};
|
|
107
116
|
double max{0};
|
|
108
117
|
bool operator==(const SwipeBounds &) const = default;
|
|
109
118
|
};
|
|
110
|
-
SwipeBounds swipeBounds(bool canGoBack, bool canGoForward);
|
|
119
|
+
SwipeBounds swipeBounds(bool canGoBack, bool canGoForward, bool rightToLeft = false);
|
|
111
120
|
|
|
112
121
|
} // namespace ngn
|
|
@@ -7,19 +7,23 @@
|
|
|
7
7
|
// an undetermined permission is asked, and only when the app's Info.plist explains why; with
|
|
8
8
|
// `noPrompts` (NGN_NO_PROMPTS=1) nothing is.
|
|
9
9
|
// - isAvailableAsync(): whether the Mac has a camera.
|
|
10
|
-
// - takePicture(tag, options): expo's picture, {uri, width, height, format
|
|
11
|
-
//
|
|
10
|
+
// - takePicture(tag, options): expo's picture, {uri, width, height, format, base64?}, in
|
|
11
|
+
// `<caches>/Camera`, from the view `tag` once its camera runs: a JPEG at `quality`, or with
|
|
12
|
+
// `imageType: 'png'` a PNG (lossless, so `quality` does nothing), as on iOS. Another imageType
|
|
13
|
+
// is refused.
|
|
12
14
|
// - record(tag, options): expo's recording, {uri}, a QuickTime movie in `<caches>/Camera` from the
|
|
13
15
|
// view `tag`, once it stops: stopRecording(tag), `maxDuration` seconds or `maxFileSize` bytes
|
|
14
|
-
// reached, or the view going. It has sound unless `mute`, and only with the
|
|
15
|
-
// (as on iOS, a recording without the microphone permission has none; nothing
|
|
16
|
-
//
|
|
16
|
+
// reached, or the view going. It has sound unless the view has `mute`, and only with the
|
|
17
|
+
// microphone allowed (as on iOS, a recording without the microphone permission has none; nothing
|
|
18
|
+
// is asked). The view's `mute` as the recording starts holds until it stops; like iOS, record()
|
|
19
|
+
// takes no `mute` of its own. One recording a view at a time.
|
|
17
20
|
//
|
|
18
21
|
// A view starts its camera when it mounts with the camera allowed and present: it sends
|
|
19
22
|
// `cameraReady`, and `mountError` ({message}, expo-camera's words) when the permission is not
|
|
20
23
|
// granted or the Mac has no camera. It asks for the permission first when it can.
|
|
21
24
|
#pragma once
|
|
22
25
|
|
|
26
|
+
#include "ngn/audio.h"
|
|
23
27
|
#include "ngn/desktop-props.h"
|
|
24
28
|
#include "ngn/native-module.h"
|
|
25
29
|
|
|
@@ -32,6 +36,8 @@
|
|
|
32
36
|
#include <map>
|
|
33
37
|
#include <memory>
|
|
34
38
|
#include <mutex>
|
|
39
|
+
#include <optional>
|
|
40
|
+
#include <set>
|
|
35
41
|
#include <string>
|
|
36
42
|
#include <vector>
|
|
37
43
|
|
|
@@ -50,6 +56,8 @@ class CameraProps final : public facebook::react::ViewProps, public HasDesktopPr
|
|
|
50
56
|
std::string facing{"back"};
|
|
51
57
|
bool active{true};
|
|
52
58
|
bool mirror{false};
|
|
59
|
+
// expo-camera's `mute`: the view records without sound.
|
|
60
|
+
bool mute{false};
|
|
53
61
|
};
|
|
54
62
|
|
|
55
63
|
using CameraShadowNode = facebook::react::ConcreteViewShadowNode<CameraComponentName, CameraProps, facebook::react::ViewEventEmitter>;
|
|
@@ -68,6 +76,15 @@ class CameraHardware {
|
|
|
68
76
|
virtual bool microphoneAllowed() = 0;
|
|
69
77
|
};
|
|
70
78
|
|
|
79
|
+
// What a picture is asked for.
|
|
80
|
+
struct CameraPictureRequest {
|
|
81
|
+
std::string path;
|
|
82
|
+
// 0 to 1, for a JPEG.
|
|
83
|
+
double quality{1};
|
|
84
|
+
// expo-camera's PictureFormat: "jpg" or "png".
|
|
85
|
+
std::string format{"jpg"};
|
|
86
|
+
};
|
|
87
|
+
|
|
71
88
|
// What a recording is asked for.
|
|
72
89
|
struct CameraRecordingRequest {
|
|
73
90
|
std::string path;
|
|
@@ -77,14 +94,17 @@ struct CameraRecordingRequest {
|
|
|
77
94
|
bool sound{true};
|
|
78
95
|
// expo-camera's VideoCodec ("avc1", "hvc1", "jpeg", "apcn", "ap4h"), or empty for the default.
|
|
79
96
|
std::string codec;
|
|
97
|
+
// The session preset the movie is recorded at, AVFoundation's name for it without its prefix
|
|
98
|
+
// (High, Medium, Low, 640x480, iFrame1280x720, iFrame960x540); empty for High.
|
|
99
|
+
std::string preset;
|
|
80
100
|
};
|
|
81
101
|
|
|
82
102
|
// A view's running camera.
|
|
83
103
|
class CameraCapture {
|
|
84
104
|
public:
|
|
85
105
|
virtual ~CameraCapture() = default;
|
|
86
|
-
// Writes
|
|
87
|
-
virtual void takePicture(
|
|
106
|
+
// Writes the picture `request` asks for; answers its size, or why not. Any thread.
|
|
107
|
+
virtual void takePicture(const CameraPictureRequest &request, std::function<void(int width, int height, const std::string &error)> done) = 0;
|
|
88
108
|
// Records a movie until stopRecording or a limit; `done` gets why not, or empty once the file
|
|
89
109
|
// is finished. Any thread.
|
|
90
110
|
virtual void startRecording(const CameraRecordingRequest &request, std::function<void(const std::string &error)> done) = 0;
|
|
@@ -92,16 +112,22 @@ class CameraCapture {
|
|
|
92
112
|
virtual bool recording() const = 0;
|
|
93
113
|
};
|
|
94
114
|
|
|
95
|
-
// The running cameras by view tag, shared by the views and
|
|
115
|
+
// The running cameras by view tag, and the views with `mute`, shared by the views and
|
|
116
|
+
// NgNativeCamera. A view sets its `mute` as its props change; detaching forgets both. Any thread.
|
|
96
117
|
class CameraViews {
|
|
97
118
|
public:
|
|
98
119
|
void attach(int tag, std::shared_ptr<CameraCapture> capture);
|
|
99
120
|
void detach(int tag);
|
|
100
|
-
|
|
121
|
+
// With `muted`, also whether the view has `mute`, read under the same lock, so a view that
|
|
122
|
+
// detaches meanwhile cannot leave its camera without its mute.
|
|
123
|
+
std::shared_ptr<CameraCapture> find(int tag, bool *muted = nullptr) const;
|
|
124
|
+
void mute(int tag, bool muted);
|
|
125
|
+
bool muted(int tag) const;
|
|
101
126
|
|
|
102
127
|
private:
|
|
103
128
|
mutable std::mutex mutex_;
|
|
104
129
|
std::map<int, std::shared_ptr<CameraCapture>> captures_;
|
|
130
|
+
std::set<int> muted_;
|
|
105
131
|
};
|
|
106
132
|
|
|
107
133
|
// A camera the host could start: the Mac's own, and whether it is suspended (a MacBook's with the
|
|
@@ -122,6 +148,74 @@ CameraMount cameraMount(CameraHardware::Access access, bool hasCamera, bool noPr
|
|
|
122
148
|
// expo-camera's mountError message for a mount that cannot start, or empty.
|
|
123
149
|
std::string cameraMountError(CameraMount mount);
|
|
124
150
|
|
|
151
|
+
// A picture the host's camera sheet took: its size, and the camera's EXIF (an object, or null).
|
|
152
|
+
struct CameraShot {
|
|
153
|
+
int width{0};
|
|
154
|
+
int height{0};
|
|
155
|
+
folly::dynamic exif{nullptr};
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// A movie the host's camera sheet recorded: its size as it plays, and its length in milliseconds.
|
|
159
|
+
struct CameraClip {
|
|
160
|
+
int width{0};
|
|
161
|
+
int height{0};
|
|
162
|
+
double duration{0};
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// What the sheet is asked for: a photo, a video, or either, with a switch between them.
|
|
166
|
+
struct CameraSheetRequest {
|
|
167
|
+
bool photos{true};
|
|
168
|
+
bool videos{false};
|
|
169
|
+
CameraPictureRequest photo;
|
|
170
|
+
CameraRecordingRequest video;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// What the sheet took: a photo or a video, or neither when the user cancelled.
|
|
174
|
+
struct CameraTake {
|
|
175
|
+
std::optional<CameraShot> photo;
|
|
176
|
+
std::optional<CameraClip> video;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// The host's own camera for expo-image-picker's launchCameraAsync: macOS has no system camera
|
|
180
|
+
// screen like iOS's UIImagePickerController, so the host shows the camera's preview and a shutter
|
|
181
|
+
// itself.
|
|
182
|
+
class CameraSheet {
|
|
183
|
+
public:
|
|
184
|
+
virtual ~CameraSheet() = default;
|
|
185
|
+
// Shows the camera; once the user takes a photo or records a video, writes it as `request` asks
|
|
186
|
+
// and answers it. Answers neither and no error when they cancel or there is no window to show it
|
|
187
|
+
// on, and an error when the camera fails. Only with the camera allowed and present. Any thread.
|
|
188
|
+
virtual void shoot(const CameraSheetRequest &request, std::function<void(CameraTake, const std::string &error)> done) = 0;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// What NgNativeImagePicker's camera half needs: the permission and the device, the microphone a
|
|
192
|
+
// video's sound comes from, the sheet, and the folder its photos and videos go in
|
|
193
|
+
// (`<caches>/ImagePicker`, as on iOS).
|
|
194
|
+
struct PickerCamera {
|
|
195
|
+
std::shared_ptr<CameraHardware> hardware;
|
|
196
|
+
std::shared_ptr<AudioInput> microphone;
|
|
197
|
+
std::shared_ptr<CameraSheet> sheet;
|
|
198
|
+
std::string folder;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// expo's camera permission response, asked as NgNativeCamera asks it: only when undetermined, and
|
|
202
|
+
// never with `noPrompts`.
|
|
203
|
+
folly::dynamic cameraPermissionOf(CameraHardware::Access access);
|
|
204
|
+
void requestCameraPermission(CameraHardware &hardware, bool noPrompts, JsPromise promise);
|
|
205
|
+
|
|
206
|
+
// expo-image-picker's launchCameraAsync(options) over `camera`, shaped as iOS shapes a camera
|
|
207
|
+
// shot (no assetId and no fileName):
|
|
208
|
+
// - a photo, a JPEG at `quality` (1 by default), with base64 and exif only when asked;
|
|
209
|
+
// - with `mediaTypes` asking for videos, a QuickTime movie (`video/quicktime`) recorded at
|
|
210
|
+
// `videoQuality` (UIImagePickerControllerQualityType, High by default) for at most
|
|
211
|
+
// `videoMaxDuration` seconds (0, the default, for no limit), with its duration in milliseconds.
|
|
212
|
+
// Videos alone show a record button; videos and photos, a switch between the two.
|
|
213
|
+
// Rejected without the camera permission, as iOS does, or on a Mac with no camera. A request for
|
|
214
|
+
// videos asks for the microphone when it is undetermined; refused, the video has no sound, as iOS's
|
|
215
|
+
// camera records it. Only an app that cannot ask (no NSMicrophoneUsageDescription) is rejected,
|
|
216
|
+
// with iOS's message. Canceled with `noPrompts`, which shows no sheet.
|
|
217
|
+
void launchPickerCamera(const PickerCamera &camera, bool noPrompts, const folly::dynamic &options, JsPromise promise);
|
|
218
|
+
|
|
125
219
|
std::shared_ptr<NativeModule> makeCameraModule(
|
|
126
220
|
std::shared_ptr<CameraHardware> hardware, std::shared_ptr<CameraViews> views, std::string pictures, bool noPrompts);
|
|
127
221
|
|
|
@@ -61,6 +61,9 @@ std::shared_ptr<NativeModule> makeAppearance(const CoreModuleServices &services)
|
|
|
61
61
|
std::shared_ptr<NativeModule> makeAccessibilityManager(const CoreModuleServices &services);
|
|
62
62
|
std::shared_ptr<NativeModule> makeLinking(const CoreModuleServices &services);
|
|
63
63
|
std::shared_ptr<NativeModule> makeI18n(const CoreModuleServices &services);
|
|
64
|
+
// What I18nManager's isRTL answers, and the direction each surface lays out from: the system's,
|
|
65
|
+
// unless the app turned right to left off (allowRTL) or forced it on (forceRTL).
|
|
66
|
+
bool appRightToLeft(System &system);
|
|
64
67
|
std::shared_ptr<NativeModule> makeAlertManager(const CoreModuleServices &services);
|
|
65
68
|
std::shared_ptr<NativeModule> makeClipboard(const CoreModuleServices &services);
|
|
66
69
|
std::shared_ptr<NativeModule> makeSettingsManager(const CoreModuleServices &services);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// `<dom-component>` on a desktop host: @expo/dom-webview's view (ViewManagerAdapter_ExpoDomWebViewModule,
|
|
2
|
+
// the component @ng-native/expo's `<dom-component>` commits) as a Fabric component of the desktop's
|
|
3
|
+
// own, drawn by the same web view as react-native-webview's RNCWebView (web-view.h).
|
|
4
|
+
//
|
|
5
|
+
// The core reads Expo's props into a WebViewConfig (domWebViewConfig): `source` ({uri}),
|
|
6
|
+
// `injectedJavaScript`, `injectedJavaScriptBeforeContentLoaded`, `injectedJavaScriptObject` and
|
|
7
|
+
// `webviewDebuggingEnabled`. As in Expo's iOS view, the page always has
|
|
8
|
+
// window.ReactNativeWebView.postMessage, each message is the `message` event ({url, title, data}),
|
|
9
|
+
// the injected scripts run in every frame, and a navigation goes ahead without asking the app.
|
|
10
|
+
// `injectJavaScript` is the view's command, where Expo's is a function on its view.
|
|
11
|
+
#pragma once
|
|
12
|
+
|
|
13
|
+
#include "ngn/desktop-props.h"
|
|
14
|
+
#include "ngn/web-view.h"
|
|
15
|
+
|
|
16
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
17
|
+
#include <react/renderer/components/view/ViewEventEmitter.h>
|
|
18
|
+
#include <react/renderer/components/view/ViewProps.h>
|
|
19
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
20
|
+
|
|
21
|
+
#include <folly/dynamic.h>
|
|
22
|
+
|
|
23
|
+
#include <optional>
|
|
24
|
+
#include <string>
|
|
25
|
+
|
|
26
|
+
namespace ngn {
|
|
27
|
+
|
|
28
|
+
extern const char DomWebViewComponentName[];
|
|
29
|
+
|
|
30
|
+
class DomWebViewProps final : public facebook::react::ViewProps, public HasDesktopProps {
|
|
31
|
+
public:
|
|
32
|
+
DomWebViewProps() = default;
|
|
33
|
+
DomWebViewProps(
|
|
34
|
+
const facebook::react::PropsParserContext &context,
|
|
35
|
+
const DomWebViewProps &sourceProps,
|
|
36
|
+
const facebook::react::RawProps &rawProps);
|
|
37
|
+
|
|
38
|
+
// {uri}, as Expo's DomWebViewSource.
|
|
39
|
+
folly::dynamic source;
|
|
40
|
+
std::string injectedJavaScript;
|
|
41
|
+
std::string injectedJavaScriptBeforeContentLoaded;
|
|
42
|
+
std::string injectedJavaScriptObject;
|
|
43
|
+
bool webviewDebuggingEnabled{false};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// The web view's config for Expo's DOM web view's props; nothing for another component's.
|
|
47
|
+
std::optional<WebViewConfig> domWebViewConfig(const facebook::react::Props &props);
|
|
48
|
+
|
|
49
|
+
using DomWebViewShadowNode =
|
|
50
|
+
facebook::react::ConcreteViewShadowNode<DomWebViewComponentName, DomWebViewProps, facebook::react::ViewEventEmitter>;
|
|
51
|
+
using DomWebViewComponentDescriptor = facebook::react::ConcreteComponentDescriptor<DomWebViewShadowNode>;
|
|
52
|
+
|
|
53
|
+
} // namespace ngn
|
|
@@ -20,10 +20,12 @@
|
|
|
20
20
|
//
|
|
21
21
|
// NgNativeImagePicker, expo-image-picker's library half: launchImageLibraryAsync(options) ->
|
|
22
22
|
// {canceled, assets}, the system's photo picker over the key window, which needs no permission;
|
|
23
|
-
// get/requestMediaLibraryPermissionsAsync() as above
|
|
24
|
-
//
|
|
23
|
+
// get/requestMediaLibraryPermissionsAsync() as above. Its camera half is the host's own camera
|
|
24
|
+
// sheet (camera.h's launchPickerCamera), since macOS has no system camera screen to open:
|
|
25
|
+
// launchCameraAsync(options) and get/requestCameraPermissionsAsync(), the camera's permission.
|
|
25
26
|
#pragma once
|
|
26
27
|
|
|
28
|
+
#include "ngn/camera.h"
|
|
27
29
|
#include "ngn/file-system.h"
|
|
28
30
|
|
|
29
31
|
#include "ngn/native-module.h"
|
|
@@ -125,6 +127,8 @@ class PhotoLibrary {
|
|
|
125
127
|
PhotoLibrary::Query photoQueryOf(const folly::dynamic &query);
|
|
126
128
|
|
|
127
129
|
std::shared_ptr<NativeModule> makeMediaLibraryModule(std::shared_ptr<PhotoLibrary> library, bool noPrompts, std::shared_ptr<FileAccess> files);
|
|
128
|
-
|
|
130
|
+
// `camera`: the host's own camera for launchCameraAsync; without it the camera permissions answer
|
|
131
|
+
// denied and launchCameraAsync canceled.
|
|
132
|
+
std::shared_ptr<NativeModule> makeImagePickerModule(std::shared_ptr<PhotoLibrary> library, bool noPrompts, std::optional<PickerCamera> camera = std::nullopt);
|
|
129
133
|
|
|
130
134
|
} // namespace ngn
|