@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
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
#import "symbol-view.h"
|
|
17
17
|
#import "glass-view.h"
|
|
18
18
|
|
|
19
|
+
#include "ngn/dom-web-view.h"
|
|
19
20
|
#include "ngn/glass.h"
|
|
20
21
|
#import "web-view-component.h"
|
|
21
22
|
#import "expo-image-view.h"
|
|
@@ -742,6 +743,25 @@ NSFont *inputFont(const DesktopTextInputProps &p) {
|
|
|
742
743
|
return font;
|
|
743
744
|
}
|
|
744
745
|
|
|
746
|
+
// How a TextInput aligns its text and placeholder (inputAlignment), in a layout running `direction`,
|
|
747
|
+
// and the base writing direction its `writingDirection` sets, natural when unset.
|
|
748
|
+
void alignInput(id field, const DesktopTextInputProps &p, LayoutDirection direction) {
|
|
749
|
+
NSTextAlignment alignment = NSTextAlignmentLeft;
|
|
750
|
+
switch (ngn::inputAlignment(p.textAttributes.alignment, direction)) {
|
|
751
|
+
case TextAlignment::Right: alignment = NSTextAlignmentRight; break;
|
|
752
|
+
case TextAlignment::Center: alignment = NSTextAlignmentCenter; break;
|
|
753
|
+
case TextAlignment::Justified: alignment = NSTextAlignmentJustified; break;
|
|
754
|
+
default: break;
|
|
755
|
+
}
|
|
756
|
+
NSWritingDirection writing = NSWritingDirectionNatural;
|
|
757
|
+
if (p.textAttributes.baseWritingDirection == WritingDirection::LeftToRight) {
|
|
758
|
+
writing = NSWritingDirectionLeftToRight;
|
|
759
|
+
} else if (p.textAttributes.baseWritingDirection == WritingDirection::RightToLeft) {
|
|
760
|
+
writing = NSWritingDirectionRightToLeft;
|
|
761
|
+
}
|
|
762
|
+
[field setTextAlignment:alignment writingDirection:writing];
|
|
763
|
+
}
|
|
764
|
+
|
|
745
765
|
// The `selection` prop, when it is new in this update: React Native iOS applies it only then.
|
|
746
766
|
std::optional<NSRange> newSelection(const Props::Shared &old, const DesktopTextInputProps &p) {
|
|
747
767
|
if (!p.selection) {
|
|
@@ -810,6 +830,7 @@ std::optional<NSRange> newSelection(const Props::Shared &old, const DesktopTextI
|
|
|
810
830
|
field.font = inputFont(*p);
|
|
811
831
|
field.textColor = attrs.foregroundColor ? nsColor(attrs.foregroundColor) : NSColor.textColor;
|
|
812
832
|
[_box setPlaceholder:nsString(p->placeholder) color:p->placeholderTextColor ? nsColor(p->placeholderTextColor) : nil];
|
|
833
|
+
alignInput(_box, *p, self.layoutMetrics.layoutDirection);
|
|
813
834
|
field.editable = p->editable && !p->readOnly;
|
|
814
835
|
[_box applyOptions:ngn::textInputOptions(*p)];
|
|
815
836
|
// The text prop wins only when it is not older than what the field has sent (React Native iOS's
|
|
@@ -827,6 +848,9 @@ std::optional<NSRange> newSelection(const Props::Shared &old, const DesktopTextI
|
|
|
827
848
|
|
|
828
849
|
- (void)updateLayout:(const LayoutMetrics &)metrics {
|
|
829
850
|
[super updateLayout:metrics];
|
|
851
|
+
if (auto p = std::dynamic_pointer_cast<const DesktopTextInputProps>(self.props)) {
|
|
852
|
+
alignInput(_box, *p, metrics.layoutDirection);
|
|
853
|
+
}
|
|
830
854
|
const auto &i = metrics.contentInsets;
|
|
831
855
|
NSRect content = NSMakeRect(
|
|
832
856
|
i.left, i.top, metrics.frame.size.width - i.left - i.right, metrics.frame.size.height - i.top - i.bottom);
|
|
@@ -993,6 +1017,7 @@ std::optional<NSRange> newSelection(const Props::Shared &old, const DesktopTextI
|
|
|
993
1017
|
_text.font = inputFont(*p);
|
|
994
1018
|
_text.textColor = attrs.foregroundColor ? nsColor(attrs.foregroundColor) : NSColor.textColor;
|
|
995
1019
|
[_text setPlaceholder:nsString(p->placeholder) color:p->placeholderTextColor ? nsColor(p->placeholderTextColor) : nil];
|
|
1020
|
+
alignInput(_text, *p, self.layoutMetrics.layoutDirection);
|
|
996
1021
|
_text.editable = p->editable && !p->readOnly;
|
|
997
1022
|
[_text applyOptions:ngn::textInputOptions(*p)];
|
|
998
1023
|
if (ngn::controlledTextIsCurrent(p->mostRecentEventCount, _eventCount, _text.hasMarkedText) && !p->text.empty()) {
|
|
@@ -1010,6 +1035,9 @@ std::optional<NSRange> newSelection(const Props::Shared &old, const DesktopTextI
|
|
|
1010
1035
|
|
|
1011
1036
|
- (void)updateLayout:(const LayoutMetrics &)metrics {
|
|
1012
1037
|
[super updateLayout:metrics];
|
|
1038
|
+
if (auto p = std::dynamic_pointer_cast<const DesktopTextInputProps>(self.props)) {
|
|
1039
|
+
alignInput(_text, *p, metrics.layoutDirection);
|
|
1040
|
+
}
|
|
1013
1041
|
const auto &i = metrics.contentInsets;
|
|
1014
1042
|
_scroll.frame = NSMakeRect(
|
|
1015
1043
|
i.left, i.top, metrics.frame.size.width - i.left - i.right, metrics.frame.size.height - i.top - i.bottom);
|
|
@@ -1190,7 +1218,7 @@ NGNView *NGNMakeView(const ShadowView &view) {
|
|
|
1190
1218
|
if (name == ngn::ExpoImageComponentName) {
|
|
1191
1219
|
return [[NGNExpoImageView alloc] initWithShadowView:view];
|
|
1192
1220
|
}
|
|
1193
|
-
if (name == "RNCWebView") {
|
|
1221
|
+
if (name == "RNCWebView" || name == ngn::DomWebViewComponentName) {
|
|
1194
1222
|
return [[NGNWebView alloc] initWithShadowView:view];
|
|
1195
1223
|
}
|
|
1196
1224
|
if (Class library = libraryViews()[@(view.componentName)]) {
|
package/native/appkit/main.mm
CHANGED
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
#import "image-manipulator.h"
|
|
49
49
|
#import "printing.h"
|
|
50
50
|
#import "expo-image-view.h"
|
|
51
|
+
#import "camera-sheet.h"
|
|
51
52
|
#import "camera-view.h"
|
|
52
53
|
#import "camera.h"
|
|
53
54
|
#import "map-view.h"
|
|
@@ -68,6 +69,7 @@
|
|
|
68
69
|
#import "test-launch.h"
|
|
69
70
|
#import "updates.h"
|
|
70
71
|
#import "surface-view.h"
|
|
72
|
+
#import "tab-walk.h"
|
|
71
73
|
#include "text-layout.h"
|
|
72
74
|
|
|
73
75
|
#include "ngn/app-menus.h"
|
|
@@ -211,71 +213,13 @@ void logFirstFrame(NSWindow *window) {
|
|
|
211
213
|
}
|
|
212
214
|
}
|
|
213
215
|
|
|
214
|
-
//
|
|
215
|
-
// is the container while it is up, wherever the first responder is: Tab stays inside it.
|
|
216
|
-
struct FocusContext {
|
|
217
|
-
NGNSurfaceView *container = nil;
|
|
218
|
-
NGNView *focused = nil;
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
FocusContext focusContext(NSWindow *window) {
|
|
222
|
-
FocusContext context;
|
|
223
|
-
NSResponder *first = window.firstResponder;
|
|
224
|
-
// A field editor stands in for its text field, inside the field's view.
|
|
225
|
-
for (NSView *v = [first isKindOfClass:NSView.class] ? (NSView *)first : nil; v != nil; v = v.superview) {
|
|
226
|
-
if (context.focused == nil && [v isKindOfClass:NGNView.class]) {
|
|
227
|
-
context.focused = (NGNView *)v;
|
|
228
|
-
}
|
|
229
|
-
if ([v isKindOfClass:NGNSurfaceView.class]) {
|
|
230
|
-
context.container = (NGNSurfaceView *)v;
|
|
231
|
-
break;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
if (context.container == nil) {
|
|
235
|
-
context.container =
|
|
236
|
-
[window.contentView isKindOfClass:NGNSurfaceView.class] ? (NGNSurfaceView *)window.contentView : nil;
|
|
237
|
-
}
|
|
238
|
-
NSView *cover = [NGNModalHostView frontCoverIn:window];
|
|
239
|
-
if (cover != nil && ![context.container isDescendantOf:cover]) {
|
|
240
|
-
context.container = (NGNSurfaceView *)cover;
|
|
241
|
-
context.focused = nil;
|
|
242
|
-
}
|
|
243
|
-
return context;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// Tab and Shift-Tab, walked in the core (focus-order.h) over the container the focus is in, in
|
|
247
|
-
// place of AppKit's key-view loop. True when the key is used: the focus moved, or it is inside a
|
|
248
|
-
// sheet, cover or popover, which Tab never leaves.
|
|
216
|
+
// Tab and Shift-Tab (tab-walk.h). True when the key is used.
|
|
249
217
|
bool moveFocus(NSEvent *event) {
|
|
250
|
-
NSWindow *window = event.window;
|
|
251
|
-
auto [container, focused] = focusContext(window);
|
|
252
|
-
if (container == nil) {
|
|
253
|
-
return false;
|
|
254
|
-
}
|
|
255
|
-
bool contained = [NGNModalHostView isPresentationContainer:container];
|
|
256
218
|
// Option-Tab reaches every focusable view, whatever the keyboard navigation setting.
|
|
257
219
|
bool everything = NSApp.isFullKeyboardAccessEnabled || (event.modifierFlags & NSEventModifierFlagOption) != 0;
|
|
258
220
|
auto reach = everything ? ngn::TabReach::All : ngn::TabReach::TextInputs;
|
|
259
221
|
bool backwards = (event.modifierFlags & NSEventModifierFlagShift) != 0;
|
|
260
|
-
|
|
261
|
-
std::optional<Tag> from;
|
|
262
|
-
if (focused != nil) {
|
|
263
|
-
from = static_cast<Tag>(focused.reactTag);
|
|
264
|
-
}
|
|
265
|
-
auto count = ngn::tabOrder(tree, container.rootTag, reach, from).size();
|
|
266
|
-
// A control AppKit will not focus (a button, with keyboard navigation off) passes Tab on.
|
|
267
|
-
for (size_t tries = 0; tries < count; tries++) {
|
|
268
|
-
auto next = ngn::nextInTabOrder(tree, container.rootTag, from, backwards, reach);
|
|
269
|
-
if (!next) {
|
|
270
|
-
return contained;
|
|
271
|
-
}
|
|
272
|
-
NGNView *view = gHost.backend->view(*next);
|
|
273
|
-
if (view != nil && [window makeFirstResponder:view.keyboardResponder]) {
|
|
274
|
-
return true;
|
|
275
|
-
}
|
|
276
|
-
from = next;
|
|
277
|
-
}
|
|
278
|
-
return contained;
|
|
222
|
+
return ngn::appkit::moveFocus(event.window, gHost.mounting->tree(), *gHost.backend, backwards, reach);
|
|
279
223
|
}
|
|
280
224
|
|
|
281
225
|
// Arrow keys, Home and End inside a composite widget (a tablist, radiogroup, menu, menubar, listbox
|
|
@@ -291,7 +235,7 @@ bool moveInComposite(NSEvent *event) {
|
|
|
291
235
|
return false;
|
|
292
236
|
}
|
|
293
237
|
NSWindow *window = event.window;
|
|
294
|
-
auto [container, focused] = focusContext(window);
|
|
238
|
+
auto [container, focused] = ngn::appkit::focusContext(window);
|
|
295
239
|
if (container == nil || focused == nil || window.firstResponder != focused) {
|
|
296
240
|
return false;
|
|
297
241
|
}
|
|
@@ -394,6 +338,8 @@ struct Swipe {
|
|
|
394
338
|
NGNView *below;
|
|
395
339
|
NSWindow *window;
|
|
396
340
|
SurfaceId surface = 0;
|
|
341
|
+
// The direction the swipe began in, which its later moves keep though a reload changes the app's.
|
|
342
|
+
bool rightToLeft = false;
|
|
397
343
|
// The momentum scrolls after a swipe's fingers lift are the swipe's, not the content's.
|
|
398
344
|
bool swallowMomentum = false;
|
|
399
345
|
// Bumped as a swipe starts or ends, so a late animation step or timeout of an old one stops.
|
|
@@ -457,6 +403,11 @@ double fingersMovedRight(NSEvent *event) {
|
|
|
457
403
|
return event.isDirectionInvertedFromDevice ? event.scrollingDeltaX : -event.scrollingDeltaX;
|
|
458
404
|
}
|
|
459
405
|
|
|
406
|
+
// Whether the app lays out right to left, which turns the swipes round: left goes back.
|
|
407
|
+
bool swipesRightToLeft() {
|
|
408
|
+
return gHost.runtime && gHost.runtime->laysOutRightToLeft();
|
|
409
|
+
}
|
|
410
|
+
|
|
460
411
|
// The fingers lifted from a tracking swipe: it goes back, or slides home.
|
|
461
412
|
void liftSwipe(NSEvent *event) {
|
|
462
413
|
bool back = gSwipe.swipe.lifted(event.phase == NSEventPhaseCancelled);
|
|
@@ -506,7 +457,7 @@ NSEvent *swipeScroll(NSEvent *event, NSWindow *window) {
|
|
|
506
457
|
if (window != gSwipe.window) {
|
|
507
458
|
return event;
|
|
508
459
|
}
|
|
509
|
-
double dx = fingersMovedRight(event);
|
|
460
|
+
double dx = ngn::towardsBack(fingersMovedRight(event), gSwipe.rightToLeft);
|
|
510
461
|
if (dx != 0) {
|
|
511
462
|
drawSwipe(gSwipe.swipe.moved(dx));
|
|
512
463
|
}
|
|
@@ -530,23 +481,25 @@ NSEvent *swipeScroll(NSEvent *event, NSWindow *window) {
|
|
|
530
481
|
auto history = gHost.menus->history(*surface);
|
|
531
482
|
bool canGoBack = !history || !history->back.empty();
|
|
532
483
|
bool canGoForward = !history || !history->forward.empty();
|
|
533
|
-
|
|
484
|
+
bool rightToLeft = swipesRightToLeft();
|
|
485
|
+
double dx = ngn::towardsBack(fingersMovedRight(event), rightToLeft);
|
|
534
486
|
if (dx > 0 && canGoBack && gSwipe.swipe.phase() == ngn::BackSwipe::Phase::Idle) {
|
|
535
487
|
auto target = gHost.mounting->backSwipeTarget(*surface);
|
|
536
488
|
NGNView *top = target ? gHost.backend->view(target->top) : nil;
|
|
537
489
|
NGNView *below = target ? gHost.backend->view(target->below) : nil;
|
|
538
|
-
if (top != nil && below != nil && gSwipe.swipe.begin(target, NSWidth(top.bounds))) {
|
|
490
|
+
if (top != nil && below != nil && gSwipe.swipe.begin(target, NSWidth(top.bounds), rightToLeft)) {
|
|
539
491
|
endSwipe();
|
|
540
492
|
gSwipe.top = top;
|
|
541
493
|
gSwipe.below = below;
|
|
542
494
|
gSwipe.window = window;
|
|
543
495
|
gSwipe.surface = *surface;
|
|
496
|
+
gSwipe.rightToLeft = rightToLeft;
|
|
544
497
|
gSwipe.swallowMomentum = true;
|
|
545
498
|
drawSwipe(gSwipe.swipe.moved(dx));
|
|
546
499
|
return nil;
|
|
547
500
|
}
|
|
548
501
|
}
|
|
549
|
-
auto bounds = ngn::swipeBounds(canGoBack, canGoForward);
|
|
502
|
+
auto bounds = ngn::swipeBounds(canGoBack, canGoForward, rightToLeft);
|
|
550
503
|
if (bounds == ngn::SwipeBounds{}) {
|
|
551
504
|
return event;
|
|
552
505
|
}
|
|
@@ -556,7 +509,8 @@ NSEvent *swipeScroll(NSEvent *event, NSWindow *window) {
|
|
|
556
509
|
usingHandler:^(CGFloat amount, NSEventPhase phase, BOOL complete, BOOL *stop) {
|
|
557
510
|
if (phase == NSEventPhaseEnded && amount != 0) {
|
|
558
511
|
navigate(*ngn::navigationFor(
|
|
559
|
-
amount > 0 ? ngn::NavigationInput::SwipeRight : ngn::NavigationInput::SwipeLeft
|
|
512
|
+
amount > 0 ? ngn::NavigationInput::SwipeRight : ngn::NavigationInput::SwipeLeft,
|
|
513
|
+
rightToLeft),
|
|
560
514
|
window);
|
|
561
515
|
}
|
|
562
516
|
}];
|
|
@@ -1258,7 +1212,11 @@ int main(int argc, const char *argv[]) {
|
|
|
1258
1212
|
ngn::addModule(*modules, "NgNativeSplashScreen", [] { return ngn::makeSplashScreenModule(gSplash); });
|
|
1259
1213
|
static auto photos = ngn::appkit::makePhotoLibrary(caches);
|
|
1260
1214
|
ngn::addModule(*modules, "NgNativeMediaLibrary", [] { return ngn::makeMediaLibraryModule(photos, noPrompts, fileAccess); });
|
|
1261
|
-
|
|
1215
|
+
static auto cameraHardware = ngn::appkit::makeCameraHardware();
|
|
1216
|
+
static auto cameraSheet = ngn::appkit::makeCameraSheet();
|
|
1217
|
+
ngn::addModule(*modules, "NgNativeImagePicker", [] {
|
|
1218
|
+
return ngn::makeImagePickerModule(photos, noPrompts, ngn::PickerCamera{.hardware = cameraHardware, .microphone = audioInput, .sheet = cameraSheet, .folder = caches + "/ImagePicker"});
|
|
1219
|
+
});
|
|
1262
1220
|
static auto tracking = ngn::appkit::makeTrackingAuthority();
|
|
1263
1221
|
ngn::addModule(*modules, "NgNativeTrackingTransparency", [] { return ngn::makeTrackingModule(tracking, noPrompts); });
|
|
1264
1222
|
static auto imageHttp = network.http;
|
|
@@ -1275,7 +1233,6 @@ int main(int argc, const char *argv[]) {
|
|
|
1275
1233
|
});
|
|
1276
1234
|
// <expo-image>'s bytes: 64 MB of them in memory, the rest on disk in the caches.
|
|
1277
1235
|
[NGNExpoImageView useHttp:imageHttp cache:std::make_shared<ngn::ImageCache>(caches + "/ExpoImage", 64 << 20)];
|
|
1278
|
-
static auto cameraHardware = ngn::appkit::makeCameraHardware();
|
|
1279
1236
|
static auto cameraViews = std::make_shared<ngn::CameraViews>();
|
|
1280
1237
|
[NGNCameraView useHardware:cameraHardware views:cameraViews noPrompts:noPrompts];
|
|
1281
1238
|
ngn::addModule(*modules, "NgNativeCamera", [] { return ngn::makeCameraModule(cameraHardware, cameraViews, caches + "/Camera", noPrompts); });
|
|
@@ -1349,6 +1306,9 @@ int main(int argc, const char *argv[]) {
|
|
|
1349
1306
|
ngn::DebuggerIdentity{
|
|
1350
1307
|
.appId = appId,
|
|
1351
1308
|
.deviceName = NSHost.currentHost.localizedName ? NSHost.currentHost.localizedName.UTF8String : "Mac"});
|
|
1309
|
+
// Each surface lays out the way I18nManager.isRTL says for the instance running, read again
|
|
1310
|
+
// as a reload starts the next.
|
|
1311
|
+
gHost.runtime->rightToLeft = [system] { return ngn::appRightToLeft(*system); };
|
|
1352
1312
|
// The first launch owes its first frame from the instance the runtime just began.
|
|
1353
1313
|
gHost.launchFrame.loaded(gHost.updates->launchGeneration(), gHost.mounting->instance());
|
|
1354
1314
|
|
|
@@ -1497,7 +1457,7 @@ int main(int argc, const char *argv[]) {
|
|
|
1497
1457
|
}
|
|
1498
1458
|
auto input = event.deltaX > 0 ? ngn::NavigationInput::SwipeRight
|
|
1499
1459
|
: ngn::NavigationInput::SwipeLeft;
|
|
1500
|
-
navigate(*ngn::navigationFor(input), event.window);
|
|
1460
|
+
navigate(*ngn::navigationFor(input, swipesRightToLeft()), event.window);
|
|
1501
1461
|
return nil;
|
|
1502
1462
|
}];
|
|
1503
1463
|
// "Swipe between pages" with two fingers (swipeScroll), for real scrolls and replayed ones.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#include "photo-library.h"
|
|
2
2
|
|
|
3
|
+
#import "camera.h"
|
|
4
|
+
|
|
3
5
|
#include <algorithm>
|
|
4
6
|
|
|
5
7
|
#import <AVFoundation/AVFoundation.h>
|
|
@@ -501,12 +503,10 @@ class PhotoKitLibrary final : public ngn::PhotoLibrary {
|
|
|
501
503
|
item[@"assetId"] = result.assetIdentifier;
|
|
502
504
|
}
|
|
503
505
|
if (video) {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
item[@"
|
|
508
|
-
item[@"height"] = @(fabs(size.height));
|
|
509
|
-
item[@"duration"] = @(CMTimeGetSeconds(asset.duration) * 1000);
|
|
506
|
+
auto clip = ngn::appkit::movieClip(copy.path.UTF8String).value_or(ngn::CameraClip{});
|
|
507
|
+
item[@"width"] = @(clip.width);
|
|
508
|
+
item[@"height"] = @(clip.height);
|
|
509
|
+
item[@"duration"] = @(clip.duration);
|
|
510
510
|
} else if (CGImageSourceRef source = CGImageSourceCreateWithURL((__bridge CFURLRef)copy, nil)) {
|
|
511
511
|
NSDictionary *properties = CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(source, 0, nil));
|
|
512
512
|
CFRelease(source);
|
|
@@ -232,7 +232,11 @@ static std::optional<ngn::GesturePhase> phaseOf(NSEventPhase phase) {
|
|
|
232
232
|
double leading = 0;
|
|
233
233
|
if (NSButton *zoom = [self.window standardWindowButton:NSWindowZoomButton]; zoom != nil && safe.top > 0) {
|
|
234
234
|
NSRect controls = [self convertRect:zoom.bounds fromView:zoom];
|
|
235
|
-
leading =
|
|
235
|
+
leading = ngn::titlebarLeading(
|
|
236
|
+
NSMinX(controls),
|
|
237
|
+
NSMaxX(controls),
|
|
238
|
+
NSWidth(self.bounds),
|
|
239
|
+
self.userInterfaceLayoutDirection == NSUserInterfaceLayoutDirectionRightToLeft);
|
|
236
240
|
}
|
|
237
241
|
ngn::ContainerInsets insets{
|
|
238
242
|
.size = {static_cast<facebook::react::Float>(self.bounds.size.width),
|
package/native/appkit/svg-view.h
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// react-native-svg's views on macOS. The RNSVGSvgView draws its document (ngn/svg.h), which the
|
|
2
2
|
// core builds from the elements under it, with Core Graphics; the elements' own views are
|
|
3
|
-
// hidden, as they draw nothing of their own.
|
|
3
|
+
// hidden, as they draw nothing of their own. The views in a foreignObject stay hidden too: the svg
|
|
4
|
+
// draws them from their layers, so they take no clicks.
|
|
4
5
|
#pragma once
|
|
5
6
|
|
|
6
7
|
#import "host-view.h"
|
|
@@ -6,10 +6,16 @@
|
|
|
6
6
|
|
|
7
7
|
@implementation NGNSvgView {
|
|
8
8
|
std::shared_ptr<const ngn::SvgDocument> _document;
|
|
9
|
+
// The documents set so far, and whether the next draw is the one after a draw of a
|
|
10
|
+
// foreignObject's views with no document set since: see drawRect.
|
|
11
|
+
uint64_t _documents;
|
|
12
|
+
BOOL _followUp;
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
- (void)setDocument:(std::shared_ptr<const ngn::SvgDocument>)document {
|
|
12
16
|
_document = std::move(document);
|
|
17
|
+
_documents++;
|
|
18
|
+
_followUp = NO;
|
|
13
19
|
[self setNeedsDisplay:YES];
|
|
14
20
|
}
|
|
15
21
|
|
|
@@ -23,6 +29,23 @@
|
|
|
23
29
|
[self setNeedsDisplay:YES];
|
|
24
30
|
}
|
|
25
31
|
|
|
32
|
+
// A foreignObject's view: an element's, under the svg's own and its groups'.
|
|
33
|
+
- (NSView *)descendantTagged:(ngn::Tag)tag {
|
|
34
|
+
NSMutableArray<NSView *> *pending = [self.subviews mutableCopy];
|
|
35
|
+
while (pending.count > 0) {
|
|
36
|
+
NSView *view = pending.lastObject;
|
|
37
|
+
[pending removeLastObject];
|
|
38
|
+
if (![view isKindOfClass:NGNSvgElementView.class]) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (((NGNView *)view).reactTag == tag) {
|
|
42
|
+
return view;
|
|
43
|
+
}
|
|
44
|
+
[pending addObjectsFromArray:view.subviews];
|
|
45
|
+
}
|
|
46
|
+
return nil;
|
|
47
|
+
}
|
|
48
|
+
|
|
26
49
|
- (void)drawRect:(NSRect)dirtyRect {
|
|
27
50
|
if (!_document) {
|
|
28
51
|
return;
|
|
@@ -31,12 +54,35 @@
|
|
|
31
54
|
NSSize size = self.bounds.size;
|
|
32
55
|
CGFloat scale = self.window ? self.window.backingScaleFactor : NSScreen.mainScreen.backingScaleFactor;
|
|
33
56
|
__weak NGNSvgView *weakSelf = self;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
57
|
+
__block BOOL drewViews = NO;
|
|
58
|
+
auto canvas = NGNMakeCGCanvas(
|
|
59
|
+
context,
|
|
60
|
+
size,
|
|
61
|
+
scale,
|
|
62
|
+
^{
|
|
63
|
+
[weakSelf setNeedsDisplay:YES];
|
|
64
|
+
},
|
|
65
|
+
^NSView *(ngn::Tag tag) {
|
|
66
|
+
drewViews = YES;
|
|
67
|
+
return [weakSelf descendantTagged:tag];
|
|
68
|
+
});
|
|
37
69
|
CGContextSaveGState(context);
|
|
38
70
|
ngn::drawSvg(*_document, size.width, size.height, *canvas);
|
|
39
71
|
CGContextRestoreGState(context);
|
|
72
|
+
// The views in a foreignObject draw after the svg in the same pass, so a change to one shows in
|
|
73
|
+
// the svg's next draw: that comes on the next turn of the run loop, as react-native-svg's
|
|
74
|
+
// ForeignObject asks for one on iOS, and asks for no other unless something changed first.
|
|
75
|
+
if (drewViews && !_followUp) {
|
|
76
|
+
uint64_t documents = _documents;
|
|
77
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
78
|
+
[weakSelf drawFollowUpOf:documents];
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
- (void)drawFollowUpOf:(uint64_t)documents {
|
|
84
|
+
_followUp = documents == _documents;
|
|
85
|
+
[self setNeedsDisplay:YES];
|
|
40
86
|
}
|
|
41
87
|
|
|
42
88
|
@end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Tab and Shift-Tab in a window: the order is the core's (focus-order.h), walked over the
|
|
2
|
+
// container the focus is in, in place of AppKit's key-view loop.
|
|
3
|
+
#pragma once
|
|
4
|
+
|
|
5
|
+
#import <AppKit/AppKit.h>
|
|
6
|
+
|
|
7
|
+
#include "ngn/focus-order.h"
|
|
8
|
+
|
|
9
|
+
@class NGNSurfaceView;
|
|
10
|
+
@class NGNView;
|
|
11
|
+
|
|
12
|
+
namespace ngn::appkit {
|
|
13
|
+
|
|
14
|
+
class AppKitBackend;
|
|
15
|
+
|
|
16
|
+
// The container the focus is in, and the view holding it, in `window`. An in-window cover (a modal)
|
|
17
|
+
// is the container while it is up, wherever the first responder is: Tab stays inside it.
|
|
18
|
+
struct FocusContext {
|
|
19
|
+
NGNSurfaceView *container = nil;
|
|
20
|
+
NGNView *focused = nil;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
FocusContext focusContext(NSWindow *window);
|
|
24
|
+
|
|
25
|
+
// Moves the focus in `window` to the next view in Tab order (the previous with `backwards`), over
|
|
26
|
+
// the views `backend` mounted for `tree`. A view that will not take the focus (a disabled control,
|
|
27
|
+
// or a field AppKit refuses it to) is passed over. True when the key is used: the focus moved,
|
|
28
|
+
// or it is inside a sheet, cover or popover, which Tab never leaves.
|
|
29
|
+
bool moveFocus(NSWindow *window, const ViewTree &tree, const AppKitBackend &backend, bool backwards, TabReach reach);
|
|
30
|
+
|
|
31
|
+
} // namespace ngn::appkit
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#import "tab-walk.h"
|
|
2
|
+
|
|
3
|
+
#import "appkit-backend.h"
|
|
4
|
+
#import "host-view.h"
|
|
5
|
+
#import "modal-host-view.h"
|
|
6
|
+
#import "surface-view.h"
|
|
7
|
+
|
|
8
|
+
namespace ngn::appkit {
|
|
9
|
+
|
|
10
|
+
FocusContext focusContext(NSWindow *window) {
|
|
11
|
+
FocusContext context;
|
|
12
|
+
NSResponder *first = window.firstResponder;
|
|
13
|
+
// A field editor stands in for its text field, inside the field's view.
|
|
14
|
+
for (NSView *v = [first isKindOfClass:NSView.class] ? (NSView *)first : nil; v != nil; v = v.superview) {
|
|
15
|
+
if (context.focused == nil && [v isKindOfClass:NGNView.class]) {
|
|
16
|
+
context.focused = (NGNView *)v;
|
|
17
|
+
}
|
|
18
|
+
if ([v isKindOfClass:NGNSurfaceView.class]) {
|
|
19
|
+
context.container = (NGNSurfaceView *)v;
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (context.container == nil) {
|
|
24
|
+
context.container =
|
|
25
|
+
[window.contentView isKindOfClass:NGNSurfaceView.class] ? (NGNSurfaceView *)window.contentView : nil;
|
|
26
|
+
}
|
|
27
|
+
NSView *cover = [NGNModalHostView frontCoverIn:window];
|
|
28
|
+
if (cover != nil && ![context.container isDescendantOf:cover]) {
|
|
29
|
+
context.container = (NGNSurfaceView *)cover;
|
|
30
|
+
context.focused = nil;
|
|
31
|
+
}
|
|
32
|
+
return context;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
bool moveFocus(NSWindow *window, const ViewTree &tree, const AppKitBackend &backend, bool backwards, TabReach reach) {
|
|
36
|
+
auto [container, focused] = focusContext(window);
|
|
37
|
+
if (container == nil) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
bool contained = [NGNModalHostView isPresentationContainer:container];
|
|
41
|
+
std::optional<Tag> from;
|
|
42
|
+
if (focused != nil) {
|
|
43
|
+
from = static_cast<Tag>(focused.reactTag);
|
|
44
|
+
}
|
|
45
|
+
auto count = tabOrder(tree, container.rootTag, reach, from).size();
|
|
46
|
+
// A view that will not take the focus passes Tab on: a disabled control, which
|
|
47
|
+
// makeFirstResponder: would focus all the same, or a field or button AppKit refuses.
|
|
48
|
+
for (size_t tries = 0; tries < count; tries++) {
|
|
49
|
+
auto next = nextInTabOrder(tree, container.rootTag, from, backwards, reach);
|
|
50
|
+
if (!next) {
|
|
51
|
+
return contained;
|
|
52
|
+
}
|
|
53
|
+
NGNView *view = backend.view(*next);
|
|
54
|
+
NSResponder *responder = view.keyboardResponder;
|
|
55
|
+
bool disabled = [responder isKindOfClass:NSControl.class] && !((NSControl *)responder).enabled;
|
|
56
|
+
if (view != nil && !disabled && [window makeFirstResponder:responder]) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
from = next;
|
|
60
|
+
}
|
|
61
|
+
return contained;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
} // namespace ngn::appkit
|
|
@@ -62,6 +62,8 @@ BOOL NGNControlShouldChangeText(
|
|
|
62
62
|
- (const ngn::TextInputOptions &)options;
|
|
63
63
|
// Drawn in the field's font; nil colour is the system's placeholder colour.
|
|
64
64
|
- (void)setPlaceholder:(NSString *)placeholder color:(NSColor *)color;
|
|
65
|
+
// The alignment and base writing direction of the text, while editing too, and of the placeholder.
|
|
66
|
+
- (void)setTextAlignment:(NSTextAlignment)alignment writingDirection:(NSWritingDirection)direction;
|
|
65
67
|
// Selects now while editing, or as editing starts.
|
|
66
68
|
- (void)selectRange:(NSRange)range;
|
|
67
69
|
@end
|
|
@@ -72,5 +74,8 @@ BOOL NGNControlShouldChangeText(
|
|
|
72
74
|
@property (nonatomic, copy, readonly) NSAttributedString *placeholder;
|
|
73
75
|
- (void)applyOptions:(const ngn::TextInputOptions &)options;
|
|
74
76
|
- (void)setPlaceholder:(NSString *)placeholder color:(NSColor *)color;
|
|
77
|
+
// The alignment and base writing direction of the text, typed or set later too, and of the
|
|
78
|
+
// placeholder.
|
|
79
|
+
- (void)setTextAlignment:(NSTextAlignment)alignment writingDirection:(NSWritingDirection)direction;
|
|
75
80
|
- (void)selectRange:(NSRange)range;
|
|
76
81
|
@end
|