@@ -31,18 +31,19 @@ using namespace facebook;
31
31
32
32
33
33
class JsiSkPath : public JsiSkWrappingSharedPtrHostObject <SkPath> {
34
+
34
35
public:
35
- // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter?
36
- JSI_PROPERTY_GET (__typename__) {
37
- return jsi::String::createFromUtf8 (runtime, " Path" );
38
- }
36
+ // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter?
37
+ JSI_PROPERTY_GET (__typename__) {
38
+ return jsi::String::createFromUtf8 (runtime, " Path" );
39
+ }
39
40
40
- JSI_HOST_FUNCTION (addArc) {
41
+ JSI_HOST_FUNCTION (addArc) {
41
42
auto rect = JsiSkRect::fromValue (runtime, arguments[0 ]).get ();
42
43
auto start = arguments[1 ].asNumber ();
43
44
auto sweep = arguments[2 ].asNumber ();
44
45
getObject ()->addArc (*rect, start, sweep);
45
- return jsi::Value::undefined ( );
46
+ return thisValue. getObject (runtime );
46
47
}
47
48
48
49
JSI_HOST_FUNCTION (addOval) {
@@ -52,8 +53,8 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject<SkPath> {
52
53
direction = SkPathDirection::kCCW ;
53
54
}
54
55
unsigned startIndex = count < 3 ? 0 : arguments[2 ].asNumber ();
55
- getObject ()->addOval (*rect, direction, startIndex);
56
- return jsi::Value::undefined ( );
56
+ auto result = getObject ()->addOval (*rect, direction, startIndex);
57
+ return thisValue. getObject (runtime );
57
58
}
58
59
59
60
JSI_HOST_FUNCTION (addPoly) {
@@ -68,7 +69,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject<SkPath> {
68
69
points.push_back (*point.get ());
69
70
}
70
71
getObject ()->addPoly (points.data (), (int )points.size (), close);
71
- return jsi::Value::undefined ( );
72
+ return thisValue. getObject (runtime );
72
73
}
73
74
74
75
JSI_HOST_FUNCTION (addRect) {
@@ -88,7 +89,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject<SkPath> {
88
89
direction = SkPathDirection::kCCW ;
89
90
}
90
91
getObject ()->addRRect (*rrect, direction);
91
- return jsi::Value::undefined ( );
92
+ return thisValue. getObject (runtime );
92
93
}
93
94
94
95
JSI_HOST_FUNCTION (arcToOval) {
@@ -97,7 +98,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject<SkPath> {
97
98
auto sweep = arguments[2 ].asNumber ();
98
99
auto forceMoveTo = arguments[3 ].getBool ();
99
100
getObject ()->arcTo (*rect, start, sweep, forceMoveTo);
100
- return jsi::Value::undefined ( );
101
+ return thisValue. getObject (runtime );
101
102
}
102
103
103
104
JSI_HOST_FUNCTION (arcToRotated) {
@@ -112,7 +113,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject<SkPath> {
112
113
auto x = arguments[5 ].asNumber ();
113
114
auto y = arguments[6 ].asNumber ();
114
115
getObject ()->arcTo (rx, ry, xAxisRotate, arcSize, sweep, x, y);
115
- return jsi::Value::undefined ( );
116
+ return thisValue. getObject (runtime );
116
117
}
117
118
118
119
JSI_HOST_FUNCTION (rArcTo) {
@@ -127,7 +128,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject<SkPath> {
127
128
auto x = arguments[5 ].asNumber ();
128
129
auto y = arguments[6 ].asNumber ();
129
130
getObject ()->rArcTo (rx, ry, xAxisRotate, arcSize, sweep, x, y);
130
- return jsi::Value::undefined ( );
131
+ return thisValue. getObject (runtime );
131
132
}
132
133
133
134
JSI_HOST_FUNCTION (arcToTangent) {
@@ -137,7 +138,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject<SkPath> {
137
138
auto y2 = arguments[3 ].asNumber ();
138
139
auto r = arguments[4 ].asNumber ();
139
140
getObject ()->arcTo (x1, y1, x2, y2, r);
140
- return jsi::Value::undefined ( );
141
+ return thisValue. getObject (runtime );
141
142
}
142
143
143
144
JSI_HOST_FUNCTION (computeTightBounds) {
@@ -160,7 +161,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject<SkPath> {
160
161
auto y2 = arguments[3 ].asNumber ();
161
162
auto w = arguments[4 ].asNumber ();
162
163
getObject ()->conicTo (x1, y1, x2, y2, w);
163
- return jsi::Value::undefined ( );
164
+ return thisValue. getObject (runtime );
164
165
}
165
166
166
167
JSI_HOST_FUNCTION (rConicTo) {
@@ -170,7 +171,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject<SkPath> {
170
171
auto y2 = arguments[3 ].asNumber ();
171
172
auto w = arguments[4 ].asNumber ();
172
173
getObject ()->rConicTo (x1, y1, x2, y2, w);
173
- return jsi::Value::undefined ( );
174
+ return thisValue. getObject (runtime );
174
175
}
175
176
176
177
JSI_HOST_FUNCTION (contains) {
@@ -270,7 +271,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject<SkPath> {
270
271
auto precision = jsiPrecision.isUndefined () ? 1 : jsiPrecision.asNumber ();
271
272
auto result = p.getFillPath (path, &path, nullptr , precision);
272
273
getObject ()->swap (path);
273
- return jsi::Value (result );
274
+ return result ? thisValue. getObject (runtime) : jsi::Value::null ( );
274
275
}
275
276
276
277
JSI_HOST_FUNCTION (trim) {
@@ -284,15 +285,15 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject<SkPath> {
284
285
if (!pe) {
285
286
// SkDebugf("Invalid args to trim(): startT and stopT must be in
286
287
// [0,1]\n");
287
- return jsi::Value ( false );
288
+ return jsi::Value::null ( );
288
289
}
289
290
SkStrokeRec rec (SkStrokeRec::InitStyle::kHairline_InitStyle );
290
291
if (pe->filterPath (&path, path, &rec, nullptr )) {
291
292
getObject ()->swap (path);
292
- return jsi::Value ( true );
293
+ return thisValue. getObject (runtime );
293
294
}
294
295
SkDebugf (" Could not trim path\n " );
295
- return jsi::Value ( false );
296
+ return jsi::Value::null ( );
296
297
}
297
298
298
299
JSI_HOST_FUNCTION (getPoint) {
@@ -312,8 +313,8 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject<SkPath> {
312
313
JSI_HOST_FUNCTION (makeAsWinding) {
313
314
SkPath out;
314
315
if (AsWinding (*getObject (), &out)) {
315
- return jsi::Object::createFromHostObject (
316
- runtime, std::make_shared<JsiSkPath>( getContext (), std::move (out)) );
316
+ getObject ()-> swap (out);
317
+ return thisValue. getObject (runtime );
317
318
}
318
319
return jsi::Value::null ();
319
320
}
@@ -324,34 +325,34 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject<SkPath> {
324
325
SkScalar dx = arguments[0 ].asNumber ();
325
326
SkScalar dy = arguments[1 ].asNumber ();
326
327
getObject ()->offset (dx, dy);
327
- return jsi::Value::undefined ( );
328
+ return thisValue. getObject (runtime );
328
329
}
329
330
330
331
JSI_HOST_FUNCTION (moveTo) {
331
332
SkScalar x = arguments[0 ].asNumber ();
332
333
SkScalar y = arguments[1 ].asNumber ();
333
334
getObject ()->moveTo (x, y);
334
- return jsi::Value::undefined ( );
335
+ return thisValue. getObject (runtime );
335
336
}
336
337
337
338
JSI_HOST_FUNCTION (rMoveTo) {
338
339
SkScalar x = arguments[0 ].asNumber ();
339
340
SkScalar y = arguments[1 ].asNumber ();
340
341
getObject ()->rMoveTo (x, y);
341
- return jsi::Value::undefined ( );
342
+ return thisValue. getObject (runtime );
342
343
}
343
344
JSI_HOST_FUNCTION (lineTo) {
344
345
SkScalar x = arguments[0 ].asNumber ();
345
346
SkScalar y = arguments[1 ].asNumber ();
346
347
getObject ()->lineTo (x, y);
347
- return jsi::Value::undefined ( );
348
+ return thisValue. getObject (runtime );
348
349
}
349
350
350
351
JSI_HOST_FUNCTION (rlineTo) {
351
352
SkScalar x = arguments[0 ].asNumber ();
352
353
SkScalar y = arguments[1 ].asNumber ();
353
354
getObject ()->rLineTo (x, y);
354
- return jsi::Value::undefined ( );
355
+ return thisValue. getObject (runtime );
355
356
}
356
357
357
358
JSI_HOST_FUNCTION (cubicTo) {
@@ -362,7 +363,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject<SkPath> {
362
363
auto x3 = arguments[4 ].asNumber ();
363
364
auto y3 = arguments[5 ].asNumber ();
364
365
getObject ()->cubicTo (x1, y1, x2, y2, x3, y3);
365
- return jsi::Value::undefined ( );
366
+ return thisValue. getObject (runtime );
366
367
}
367
368
368
369
JSI_HOST_FUNCTION (rCubicTo) {
@@ -373,7 +374,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject<SkPath> {
373
374
auto x3 = arguments[4 ].asNumber ();
374
375
auto y3 = arguments[5 ].asNumber ();
375
376
getObject ()->rCubicTo (x1, y1, x2, y2, x3, y3);
376
- return jsi::Value::undefined ( );
377
+ return thisValue. getObject (runtime );
377
378
}
378
379
379
380
JSI_HOST_FUNCTION (reset) {
@@ -401,7 +402,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject<SkPath> {
401
402
auto x2 = arguments[2 ].asNumber ();
402
403
auto y2 = arguments[3 ].asNumber ();
403
404
getObject ()->rQuadTo (x1, y1, x2, y2);
404
- return jsi::Value::undefined ( );
405
+ return thisValue. getObject (runtime );
405
406
}
406
407
407
408
JSI_HOST_FUNCTION (addCircle) {
@@ -514,45 +515,61 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject<SkPath> {
514
515
JSI_EXPORT_PROPERTY_GETTERS (JSI_EXPORT_PROP_GET(JsiSkPath, __typename__))
515
516
516
517
JSI_EXPORT_FUNCTIONS (
517
- JSI_EXPORT_FUNC (JsiSkPath, addArc), JSI_EXPORT_FUNC(JsiSkPath, addOval),
518
- JSI_EXPORT_FUNC(JsiSkPath, addPoly), JSI_EXPORT_FUNC(JsiSkPath, addRect),
518
+ JSI_EXPORT_FUNC (JsiSkPath, addArc),
519
+ JSI_EXPORT_FUNC(JsiSkPath, addOval),
520
+ JSI_EXPORT_FUNC(JsiSkPath, addPoly),
521
+ JSI_EXPORT_FUNC(JsiSkPath, addRect),
519
522
JSI_EXPORT_FUNC(JsiSkPath, addRRect),
520
523
JSI_EXPORT_FUNC(JsiSkPath, arcToOval),
521
524
JSI_EXPORT_FUNC(JsiSkPath, arcToRotated),
522
525
JSI_EXPORT_FUNC(JsiSkPath, rArcTo),
523
526
JSI_EXPORT_FUNC(JsiSkPath, arcToTangent),
524
527
JSI_EXPORT_FUNC(JsiSkPath, computeTightBounds),
525
528
JSI_EXPORT_FUNC(JsiSkPath, getBounds),
526
- JSI_EXPORT_FUNC(JsiSkPath, conicTo), JSI_EXPORT_FUNC(JsiSkPath, rConicTo),
527
- JSI_EXPORT_FUNC(JsiSkPath, contains), JSI_EXPORT_FUNC(JsiSkPath, dash),
529
+ JSI_EXPORT_FUNC(JsiSkPath, conicTo),
530
+ JSI_EXPORT_FUNC(JsiSkPath, rConicTo),
531
+ JSI_EXPORT_FUNC(JsiSkPath, contains),
532
+ JSI_EXPORT_FUNC(JsiSkPath, dash),
528
533
JSI_EXPORT_FUNC(JsiSkPath, equals),
529
534
JSI_EXPORT_FUNC(JsiSkPath, getFillType),
530
535
JSI_EXPORT_FUNC(JsiSkPath, setFillType),
531
536
JSI_EXPORT_FUNC(JsiSkPath, setIsVolatile),
532
537
JSI_EXPORT_FUNC(JsiSkPath, isVolatile),
533
- JSI_EXPORT_FUNC(JsiSkPath, transform), JSI_EXPORT_FUNC(JsiSkPath, stroke),
534
- JSI_EXPORT_FUNC(JsiSkPath, trim), JSI_EXPORT_FUNC(JsiSkPath, getPoint),
538
+ JSI_EXPORT_FUNC(JsiSkPath, transform),
539
+ JSI_EXPORT_FUNC(JsiSkPath, stroke),
540
+ JSI_EXPORT_FUNC(JsiSkPath, trim),
541
+ JSI_EXPORT_FUNC(JsiSkPath, getPoint),
535
542
JSI_EXPORT_FUNC(JsiSkPath, toSVGString),
536
543
JSI_EXPORT_FUNC(JsiSkPath, makeAsWinding),
537
- JSI_EXPORT_FUNC(JsiSkPath, isEmpty), JSI_EXPORT_FUNC(JsiSkPath, offset),
538
- JSI_EXPORT_FUNC(JsiSkPath, moveTo), JSI_EXPORT_FUNC(JsiSkPath, rMoveTo),
539
- JSI_EXPORT_FUNC(JsiSkPath, lineTo), JSI_EXPORT_FUNC(JsiSkPath, rlineTo),
540
- JSI_EXPORT_FUNC(JsiSkPath, cubicTo), JSI_EXPORT_FUNC(JsiSkPath, rCubicTo),
541
- JSI_EXPORT_FUNC(JsiSkPath, reset), JSI_EXPORT_FUNC(JsiSkPath, rewind),
542
- JSI_EXPORT_FUNC(JsiSkPath, quadTo), JSI_EXPORT_FUNC(JsiSkPath, rQuadTo),
544
+ JSI_EXPORT_FUNC(JsiSkPath, isEmpty),
545
+ JSI_EXPORT_FUNC(JsiSkPath, offset),
546
+ JSI_EXPORT_FUNC(JsiSkPath, moveTo),
547
+ JSI_EXPORT_FUNC(JsiSkPath, rMoveTo),
548
+ JSI_EXPORT_FUNC(JsiSkPath, lineTo),
549
+ JSI_EXPORT_FUNC(JsiSkPath, rlineTo),
550
+ JSI_EXPORT_FUNC(JsiSkPath, cubicTo),
551
+ JSI_EXPORT_FUNC(JsiSkPath, rCubicTo),
552
+ JSI_EXPORT_FUNC(JsiSkPath, reset),
553
+ JSI_EXPORT_FUNC(JsiSkPath, rewind),
554
+ JSI_EXPORT_FUNC(JsiSkPath, quadTo),
555
+ JSI_EXPORT_FUNC(JsiSkPath, rQuadTo),
543
556
JSI_EXPORT_FUNC(JsiSkPath, addCircle),
544
- JSI_EXPORT_FUNC(JsiSkPath, getLastPt), JSI_EXPORT_FUNC(JsiSkPath, close),
557
+ JSI_EXPORT_FUNC(JsiSkPath, getLastPt),
558
+ JSI_EXPORT_FUNC(JsiSkPath, close),
545
559
JSI_EXPORT_FUNC(JsiSkPath, simplify),
546
- JSI_EXPORT_FUNC(JsiSkPath, countPoints), JSI_EXPORT_FUNC(JsiSkPath, copy),
547
- JSI_EXPORT_FUNC(JsiSkPath, fromText), JSI_EXPORT_FUNC(JsiSkPath, op),
560
+ JSI_EXPORT_FUNC(JsiSkPath, countPoints),
561
+ JSI_EXPORT_FUNC(JsiSkPath, copy),
562
+ JSI_EXPORT_FUNC(JsiSkPath, fromText),
563
+ JSI_EXPORT_FUNC(JsiSkPath, op),
548
564
JSI_EXPORT_FUNC(JsiSkPath, isInterpolatable),
549
565
JSI_EXPORT_FUNC(JsiSkPath, interpolate),
550
566
JSI_EXPORT_FUNC(JsiSkPath, toCmds),
551
567
)
552
568
553
569
JsiSkPath(std::shared_ptr<RNSkPlatformContext> context, SkPath path)
554
570
: JsiSkWrappingSharedPtrHostObject<SkPath>(
555
- std::move (context), std::make_shared<SkPath>(std::move(path))){}
571
+ std::move (context), std::make_shared<SkPath>(std::move(path))) {
572
+ }
556
573
557
574
/* *
558
575
Returns the underlying object from a host object of this type
0 commit comments