@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
|
@@ -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,9 @@ 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
|
+
CGFloat top{0}; // the top of its line box, from the top of the text box
|
|
21
|
+
CGFloat height{0}; // its line box's height
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
struct TextLayout {
|
|
@@ -53,6 +55,10 @@ class CoreTextMeasurer final : public TextMeasurer {
|
|
|
53
55
|
const facebook::react::AttributedString &text,
|
|
54
56
|
const facebook::react::ParagraphAttributes ¶graph,
|
|
55
57
|
facebook::react::Float maxWidth) const override;
|
|
58
|
+
facebook::react::LinesMeasurements lines(
|
|
59
|
+
const facebook::react::AttributedString &text,
|
|
60
|
+
const facebook::react::ParagraphAttributes ¶graph,
|
|
61
|
+
facebook::react::Float width) const override;
|
|
56
62
|
};
|
|
57
63
|
|
|
58
64
|
} // namespace ngn
|
|
@@ -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
|
|
|
@@ -268,6 +276,9 @@ void useFontLibrary(std::shared_ptr<const FontLibrary> library) {
|
|
|
268
276
|
gFontLibrary = std::move(library);
|
|
269
277
|
}
|
|
270
278
|
|
|
279
|
+
// A line through a range of text, in kCTUnderlineStyle's numbers, which Core Text does not draw.
|
|
280
|
+
static const CFStringRef kStrikethroughStyle = CFSTR("NGNStrikethroughStyle");
|
|
281
|
+
|
|
271
282
|
CFAttributedStringRef makeAttributedString(const AttributedString &attributedString) {
|
|
272
283
|
CFMutableAttributedStringRef out = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0);
|
|
273
284
|
CFAttributedStringBeginEditing(out);
|
|
@@ -312,7 +323,7 @@ CFAttributedStringRef makeAttributedString(const AttributedString &attributedStr
|
|
|
312
323
|
|
|
313
324
|
// Paragraph style: alignment, and lineHeight as a fixed line box (as React Native iOS does),
|
|
314
325
|
// with the glyphs centred in it through a baseline offset applied at draw time.
|
|
315
|
-
CTTextAlignment alignment = ctAlignment(a.alignment);
|
|
326
|
+
CTTextAlignment alignment = ctAlignment(a.alignment, a.layoutDirection);
|
|
316
327
|
CTWritingDirection direction = ctWritingDirection(a.baseWritingDirection);
|
|
317
328
|
CGFloat lineHeight = 0;
|
|
318
329
|
if (!std::isnan(a.lineHeight) && a.lineHeight > 0) {
|
|
@@ -328,12 +339,35 @@ CFAttributedStringRef makeAttributedString(const AttributedString &attributedStr
|
|
|
328
339
|
CFAttributedStringSetAttribute(out, range, kCTParagraphStyleAttributeName, style);
|
|
329
340
|
CFRelease(style);
|
|
330
341
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
342
|
+
// Core Text draws an underline, in its style and colour; a line through is drawText's.
|
|
343
|
+
auto line = a.textDecorationLineType.value_or(TextDecorationLineType::None);
|
|
344
|
+
bool under = line == TextDecorationLineType::Underline || line == TextDecorationLineType::UnderlineStrikethrough;
|
|
345
|
+
bool through = line == TextDecorationLineType::Strikethrough || line == TextDecorationLineType::UnderlineStrikethrough;
|
|
346
|
+
if (under || through) {
|
|
347
|
+
auto decoration = a.textDecorationStyle.value_or(TextDecorationStyle::Solid);
|
|
348
|
+
int32_t style = decoration == TextDecorationStyle::Double ? kCTUnderlineStyleDouble : kCTUnderlineStyleSingle;
|
|
349
|
+
if (decoration == TextDecorationStyle::Dotted) {
|
|
350
|
+
style |= kCTUnderlinePatternDot;
|
|
351
|
+
} else if (decoration == TextDecorationStyle::Dashed) {
|
|
352
|
+
style |= kCTUnderlinePatternDash;
|
|
353
|
+
}
|
|
354
|
+
CFNumberRef n = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &style);
|
|
355
|
+
CFAttributedStringSetAttribute(out, range, under ? kCTUnderlineStyleAttributeName : kStrikethroughStyle, n);
|
|
356
|
+
if (under && through) {
|
|
357
|
+
CFAttributedStringSetAttribute(out, range, kStrikethroughStyle, n);
|
|
358
|
+
}
|
|
336
359
|
CFRelease(n);
|
|
360
|
+
if (a.textDecorationColor) {
|
|
361
|
+
// Faded with the text, as its foreground is.
|
|
362
|
+
CGColorRef decorationColor = cgColor(a.textDecorationColor);
|
|
363
|
+
if (!std::isnan(a.opacity)) {
|
|
364
|
+
CGColorRef faded = CGColorCreateCopyWithAlpha(decorationColor, CGColorGetAlpha(decorationColor) * a.opacity);
|
|
365
|
+
CGColorRelease(decorationColor);
|
|
366
|
+
decorationColor = faded;
|
|
367
|
+
}
|
|
368
|
+
CFAttributedStringSetAttribute(out, range, kCTUnderlineColorAttributeName, decorationColor);
|
|
369
|
+
CGColorRelease(decorationColor);
|
|
370
|
+
}
|
|
337
371
|
}
|
|
338
372
|
CFRelease(font);
|
|
339
373
|
}
|
|
@@ -421,7 +455,7 @@ TextLayout layoutText(
|
|
|
421
455
|
if (fixed <= 0) {
|
|
422
456
|
baseline = y + ascent;
|
|
423
457
|
}
|
|
424
|
-
layout.lines.push_back({line, CGPointMake(0, baseline), width, rightToLeftAt(layout.string, r.location, paragraph)});
|
|
458
|
+
layout.lines.push_back({line, CGPointMake(0, baseline), width, rightToLeftAt(layout.string, r.location, paragraph), y, height});
|
|
425
459
|
widest = std::max(widest, width);
|
|
426
460
|
y += height;
|
|
427
461
|
at += count;
|
|
@@ -434,32 +468,91 @@ TextLayout layoutText(
|
|
|
434
468
|
return layout;
|
|
435
469
|
}
|
|
436
470
|
|
|
471
|
+
// Each run's line through, half its font's x-height above the baseline at `baseline`, the
|
|
472
|
+
// underline's thickness and in the underline's colour, or the text's: a double one is two lines,
|
|
473
|
+
// and a dotted or dashed one is stroked in that pattern.
|
|
474
|
+
static void drawStrikethroughs(CTLineRef line, CGContextRef context, CGPoint baseline) {
|
|
475
|
+
CFArrayRef runs = CTLineGetGlyphRuns(line);
|
|
476
|
+
for (CFIndex i = 0; i < CFArrayGetCount(runs); i++) {
|
|
477
|
+
auto run = (CTRunRef)CFArrayGetValueAtIndex(runs, i);
|
|
478
|
+
CFDictionaryRef attributes = CTRunGetAttributes(run);
|
|
479
|
+
auto styleNumber = (CFNumberRef)CFDictionaryGetValue(attributes, kStrikethroughStyle);
|
|
480
|
+
auto font = (CTFontRef)CFDictionaryGetValue(attributes, kCTFontAttributeName);
|
|
481
|
+
if (styleNumber == nullptr || font == nullptr) {
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
int32_t style = 0;
|
|
485
|
+
CFNumberGetValue(styleNumber, kCFNumberSInt32Type, &style);
|
|
486
|
+
auto color = (CGColorRef)CFDictionaryGetValue(attributes, kCTUnderlineColorAttributeName);
|
|
487
|
+
if (color == nullptr) {
|
|
488
|
+
color = (CGColorRef)CFDictionaryGetValue(attributes, kCTForegroundColorAttributeName);
|
|
489
|
+
}
|
|
490
|
+
// The run as drawn: its first glyph's position on the line and its advance, whatever direction
|
|
491
|
+
// the run or the line goes.
|
|
492
|
+
if (CTRunGetGlyphCount(run) == 0) {
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
CGPoint first = CGPointZero;
|
|
496
|
+
CTRunGetPositions(run, CFRangeMake(0, 1), &first);
|
|
497
|
+
CGFloat left = first.x;
|
|
498
|
+
CGFloat width = CTRunGetTypographicBounds(run, CFRangeMake(0, 0), nullptr, nullptr, nullptr);
|
|
499
|
+
CGFloat thickness = std::max<CGFloat>(CTFontGetUnderlineThickness(font), 1);
|
|
500
|
+
CGFloat middle = baseline.y - CTFontGetXHeight(font) / 2;
|
|
501
|
+
bool twice = (style & 0xff) == kCTUnderlineStyleDouble;
|
|
502
|
+
CGContextSaveGState(context);
|
|
503
|
+
if (color != nullptr) {
|
|
504
|
+
CGContextSetStrokeColorWithColor(context, color);
|
|
505
|
+
}
|
|
506
|
+
CGContextSetLineWidth(context, thickness);
|
|
507
|
+
if (style & kCTUnderlinePatternDot) {
|
|
508
|
+
CGFloat dots[] = {thickness, thickness * 2};
|
|
509
|
+
CGContextSetLineDash(context, 0, dots, 2);
|
|
510
|
+
} else if (style & kCTUnderlinePatternDash) {
|
|
511
|
+
CGFloat dashes[] = {thickness * 4, thickness * 2};
|
|
512
|
+
CGContextSetLineDash(context, 0, dashes, 2);
|
|
513
|
+
}
|
|
514
|
+
for (CGFloat y : twice ? std::vector<CGFloat>{middle - thickness, middle + thickness} : std::vector<CGFloat>{middle}) {
|
|
515
|
+
CGContextMoveToPoint(context, baseline.x + left, y);
|
|
516
|
+
CGContextAddLineToPoint(context, baseline.x + left + width, y);
|
|
517
|
+
}
|
|
518
|
+
CGContextStrokePath(context);
|
|
519
|
+
CGContextRestoreGState(context);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// How far right of the box's left edge a line starts: its paragraph's alignment in a box this wide.
|
|
524
|
+
static CGFloat lineOffset(const TextLayout &layout, const TextLine &l, CGFloat boxWidth) {
|
|
525
|
+
CFRange r = CTLineGetStringRange(l.line);
|
|
526
|
+
CTTextAlignment alignment = kCTTextAlignmentNatural;
|
|
527
|
+
CTParagraphStyleRef style = r.length > 0
|
|
528
|
+
? (CTParagraphStyleRef)CFAttributedStringGetAttribute(
|
|
529
|
+
layout.string, r.location, kCTParagraphStyleAttributeName, nullptr)
|
|
530
|
+
: nullptr;
|
|
531
|
+
if (style != nullptr) {
|
|
532
|
+
CTParagraphStyleGetValueForSpecifier(style, kCTParagraphStyleSpecifierAlignment, sizeof(alignment), &alignment);
|
|
533
|
+
}
|
|
534
|
+
CGFloat x = 0;
|
|
535
|
+
if (alignment == kCTTextAlignmentCenter) {
|
|
536
|
+
x = (boxWidth - l.width) / 2;
|
|
537
|
+
} else if (alignment == kCTTextAlignmentRight) {
|
|
538
|
+
x = boxWidth - l.width;
|
|
539
|
+
} else if (alignment == kCTTextAlignmentJustified && l.rightToLeft) {
|
|
540
|
+
// A justified paragraph's last line follows the paragraph's direction.
|
|
541
|
+
x = boxWidth - l.width;
|
|
542
|
+
}
|
|
543
|
+
return x;
|
|
544
|
+
}
|
|
545
|
+
|
|
437
546
|
void drawText(const TextLayout &layout, CGContextRef context, CGPoint origin, CGFloat boxWidth) {
|
|
438
547
|
CGContextSaveGState(context);
|
|
439
548
|
// The view is flipped; glyphs are drawn with an inverted text matrix rather than by flipping
|
|
440
549
|
// the whole context, so line origins stay top-down.
|
|
441
550
|
CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1, -1));
|
|
442
551
|
for (const auto &l : layout.lines) {
|
|
443
|
-
|
|
444
|
-
CTTextAlignment alignment = kCTTextAlignmentNatural;
|
|
445
|
-
CTParagraphStyleRef style = r.length > 0
|
|
446
|
-
? (CTParagraphStyleRef)CFAttributedStringGetAttribute(
|
|
447
|
-
layout.string, r.location, kCTParagraphStyleAttributeName, nullptr)
|
|
448
|
-
: nullptr;
|
|
449
|
-
if (style != nullptr) {
|
|
450
|
-
CTParagraphStyleGetValueForSpecifier(style, kCTParagraphStyleSpecifierAlignment, sizeof(alignment), &alignment);
|
|
451
|
-
}
|
|
452
|
-
CGFloat x = 0;
|
|
453
|
-
if (alignment == kCTTextAlignmentCenter) {
|
|
454
|
-
x = (boxWidth - l.width) / 2;
|
|
455
|
-
} else if (alignment == kCTTextAlignmentRight) {
|
|
456
|
-
x = boxWidth - l.width;
|
|
457
|
-
} else if ((alignment == kCTTextAlignmentNatural || alignment == kCTTextAlignmentJustified) && l.rightToLeft) {
|
|
458
|
-
// Natural follows the paragraph's direction, as does a justified paragraph's last line.
|
|
459
|
-
x = boxWidth - l.width;
|
|
460
|
-
}
|
|
552
|
+
CGFloat x = lineOffset(layout, l, boxWidth);
|
|
461
553
|
CGContextSetTextPosition(context, origin.x + x, origin.y + l.origin.y);
|
|
462
554
|
CTLineDraw(l.line, context);
|
|
555
|
+
drawStrikethroughs(l.line, context, CGPointMake(origin.x + x, origin.y + l.origin.y));
|
|
463
556
|
}
|
|
464
557
|
CGContextRestoreGState(context);
|
|
465
558
|
}
|
|
@@ -474,4 +567,42 @@ facebook::react::Size CoreTextMeasurer::measure(
|
|
|
474
567
|
}
|
|
475
568
|
}
|
|
476
569
|
|
|
570
|
+
LinesMeasurements CoreTextMeasurer::lines(
|
|
571
|
+
const AttributedString &text,
|
|
572
|
+
const ParagraphAttributes ¶graph,
|
|
573
|
+
facebook::react::Float width) const {
|
|
574
|
+
@autoreleasepool {
|
|
575
|
+
// The slack drawing gives the width Yoga rounded (NGNView's drawRect:), so the lines match.
|
|
576
|
+
auto layout = layoutText(text, paragraph, width + 0.5);
|
|
577
|
+
CFStringRef string = layout.string ? CFAttributedStringGetString(layout.string) : nullptr;
|
|
578
|
+
LinesMeasurements lines;
|
|
579
|
+
for (const auto &l : layout.lines) {
|
|
580
|
+
CGFloat ascent = 0, descent = 0, leading = 0;
|
|
581
|
+
CTLineGetTypographicBounds(l.line, &ascent, &descent, &leading);
|
|
582
|
+
CFRange range = CTLineGetStringRange(l.line);
|
|
583
|
+
NSString *lineText = string ? (__bridge NSString *)string : @"";
|
|
584
|
+
lineText = [lineText substringWithRange:NSMakeRange(range.location, range.length)];
|
|
585
|
+
CGFloat capHeight = 0, xHeight = 0;
|
|
586
|
+
CFArrayRef runs = CTLineGetGlyphRuns(l.line);
|
|
587
|
+
if (CFArrayGetCount(runs) > 0) {
|
|
588
|
+
auto font = (CTFontRef)CFDictionaryGetValue(
|
|
589
|
+
CTRunGetAttributes((CTRunRef)CFArrayGetValueAtIndex(runs, 0)), kCTFontAttributeName);
|
|
590
|
+
if (font != nullptr) {
|
|
591
|
+
capHeight = CTFontGetCapHeight(font);
|
|
592
|
+
xHeight = CTFontGetXHeight(font);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
lines.emplace_back(
|
|
596
|
+
std::string(lineText.UTF8String),
|
|
597
|
+
facebook::react::Rect{{static_cast<Float>(lineOffset(layout, l, width)), static_cast<Float>(l.top)}, {static_cast<Float>(l.width), static_cast<Float>(l.height)}},
|
|
598
|
+
static_cast<Float>(descent),
|
|
599
|
+
static_cast<Float>(capHeight),
|
|
600
|
+
static_cast<Float>(l.origin.y - l.top),
|
|
601
|
+
static_cast<Float>(xHeight));
|
|
602
|
+
}
|
|
603
|
+
return lines;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
|
|
477
607
|
} // namespace ngn
|
|
608
|
+
|
|
@@ -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) {
|
|
@@ -19,6 +19,7 @@ include(${REACT_COMMON_DIR}/cmake-utils/internal/react-native-platform-selector.
|
|
|
19
19
|
# read the core's desktop props.
|
|
20
20
|
include_directories(BEFORE SYSTEM
|
|
21
21
|
${CMAKE_CURRENT_LIST_DIR}/../shim/view-platform
|
|
22
|
+
${CMAKE_CURRENT_LIST_DIR}/../shim/text-platform
|
|
22
23
|
${CMAKE_CURRENT_LIST_DIR}/../core/include)
|
|
23
24
|
include_directories(SYSTEM
|
|
24
25
|
${REACT_COMMON_DIR}/react/renderer/graphics/platform/cxx
|
|
@@ -73,6 +74,14 @@ add_library(yoga ALIAS yogacore)
|
|
|
73
74
|
get_target_property(_tlm react_renderer_textlayoutmanager SOURCES)
|
|
74
75
|
list(FILTER _tlm EXCLUDE REGEX "platform/cxx/react/renderer/textlayoutmanager/TextLayoutManager.cpp$")
|
|
75
76
|
set_target_properties(react_renderer_textlayoutmanager PROPERTIES SOURCES "${_tlm}")
|
|
77
|
+
# Its header is the shim's (shim/text-platform), which declares measureLines, in front of the cxx
|
|
78
|
+
# platform's for the target and each one that links it (ParagraphShadowNode's). A directory of its
|
|
79
|
+
# own changes their compile commands, so a build or a compiler cache from before it compiles again.
|
|
80
|
+
foreach(_property INCLUDE_DIRECTORIES INTERFACE_INCLUDE_DIRECTORIES)
|
|
81
|
+
get_target_property(_dirs react_renderer_textlayoutmanager ${_property})
|
|
82
|
+
set_target_properties(react_renderer_textlayoutmanager PROPERTIES
|
|
83
|
+
${_property} "${CMAKE_CURRENT_LIST_DIR}/../shim/text-platform;${_dirs}")
|
|
84
|
+
endforeach()
|
|
76
85
|
|
|
77
86
|
# React Native's component codegen (FBReactNativeSpec), generated by scripts/fetch.sh.
|
|
78
87
|
set(CODEGEN_DIR ${NGN_SOURCES}/codegen)
|
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
# What the runtime half needs beyond the renderer: Hermes, built statically by
|
|
2
2
|
# scripts/build-hermes.sh, and the one OpenSSL call React Native's dev-server helper makes.
|
|
3
3
|
|
|
4
|
+
if(IS_DIRECTORY "${NGN_HERMES_PREBUILT}")
|
|
5
|
+
# React Native's prebuilt Hermes on macOS: a dynamic framework, which the binary finds beside
|
|
6
|
+
# itself in a build and in Contents/Frameworks in a packaged app.
|
|
7
|
+
set(NGN_HERMES_FRAMEWORK ${NGN_HERMES_PREBUILT}/Library/Frameworks/macosx/hermesvm.framework)
|
|
8
|
+
set(NGN_HERMESC ${NGN_HERMES_PREBUILT}/bin/hermesc)
|
|
9
|
+
foreach(alias hermesvm libhermes)
|
|
10
|
+
add_library(hermes-engine::${alias} INTERFACE IMPORTED GLOBAL)
|
|
11
|
+
set_target_properties(hermes-engine::${alias} PROPERTIES
|
|
12
|
+
INTERFACE_LINK_LIBRARIES ${NGN_HERMES_FRAMEWORK}
|
|
13
|
+
INTERFACE_LINK_OPTIONS "LINKER:-rpath,@executable_path;LINKER:-rpath,@executable_path/../Frameworks")
|
|
14
|
+
endforeach()
|
|
15
|
+
include_directories(SYSTEM ${NGN_HERMES_PREBUILT}/include)
|
|
16
|
+
# Without the cache folder's absolute path, which CMake would add for the framework: the binary
|
|
17
|
+
# finds Hermes only beside itself or in its app's Frameworks, wherever it was built.
|
|
18
|
+
set(CMAKE_SKIP_BUILD_RPATH ON)
|
|
19
|
+
# The tests, which never ship, find it where it was fetched, whichever target built first.
|
|
20
|
+
get_filename_component(_hermes_frameworks ${NGN_HERMES_FRAMEWORK} DIRECTORY)
|
|
21
|
+
set(NGN_HERMES_TEST_RPATH "LINKER:-rpath,${_hermes_frameworks}")
|
|
22
|
+
else()
|
|
4
23
|
if(NOT IS_DIRECTORY "${NGN_HERMES_BUILD}")
|
|
5
24
|
message(FATAL_ERROR "NGN_HERMES_BUILD is not set to a directory; build through scripts/build.sh")
|
|
6
25
|
endif()
|
|
26
|
+
set(NGN_HERMESC ${NGN_HERMES_BUILD}/bin/hermesc)
|
|
7
27
|
|
|
8
28
|
# --- Hermes, static ------------------------------------------------------------------------------
|
|
9
29
|
# React Native's CMakeLists link hermes-engine::hermesvm (0.87 and later) or ::libhermes (before).
|
|
@@ -24,6 +44,7 @@ foreach(alias hermesvm libhermes)
|
|
|
24
44
|
endforeach()
|
|
25
45
|
# React Native's hermes targets include <hermes/hermes.h> without a target that carries the path.
|
|
26
46
|
include_directories(SYSTEM ${HERMES_SRC}/API ${HERMES_SRC}/public ${NGN_HERMES_BUILD}/lib/config)
|
|
47
|
+
endif()
|
|
27
48
|
|
|
28
49
|
# --- OpenSSL::Crypto -----------------------------------------------------------------------------
|
|
29
50
|
# ReactCxxPlatform's DevServerHelper hashes a device id with SHA256_Init/Update/Final and nothing
|
|
@@ -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
|