react-native-smooth-clip-view 0.4.6 → 0.5.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.
Files changed (64) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +47 -0
  3. package/android/src/main/cpp/SmoothClipAndroid.h +22 -0
  4. package/android/src/main/cpp/SmoothClipBindings.cpp +37 -3
  5. package/android/src/main/cpp/SmoothClipRegistry.cpp +85 -2
  6. package/android/src/main/java/com/smoothclipview/ClipGeometryNormalizer.kt +18 -0
  7. package/android/src/main/java/com/smoothclipview/SmoothClipBackdropView.kt +59 -0
  8. package/android/src/main/java/com/smoothclipview/SmoothClipBackdropViewManager.kt +63 -0
  9. package/android/src/main/java/com/smoothclipview/SmoothClipBindings.kt +15 -0
  10. package/android/src/main/java/com/smoothclipview/SmoothClipView.kt +316 -34
  11. package/android/src/main/java/com/smoothclipview/SmoothClipViewManager.kt +19 -0
  12. package/android/src/main/java/com/smoothclipview/SmoothClipViewPackage.kt +1 -1
  13. package/cpp/SmoothClipAnimationCurve.h +36 -11
  14. package/cpp/SmoothClipRegistry.h +11 -4
  15. package/ios/SmoothClipBackdropView.h +17 -0
  16. package/ios/SmoothClipBackdropView.mm +267 -0
  17. package/ios/SmoothClipRegistry.mm +192 -9
  18. package/ios/SmoothClipTurboModule.cpp +33 -11
  19. package/ios/SmoothClipView.mm +713 -22
  20. package/ios/SmoothClipViewRegistry.h +14 -0
  21. package/lib/module/SmoothClipBackdropView.js +40 -0
  22. package/lib/module/SmoothClipBackdropView.js.map +1 -0
  23. package/lib/module/SmoothClipBackdropViewNativeComponent.ts +15 -0
  24. package/lib/module/SmoothClipView.ios.js +17 -1
  25. package/lib/module/SmoothClipView.ios.js.map +1 -1
  26. package/lib/module/SmoothClipViewNativeComponent.ts +4 -0
  27. package/lib/module/geometry.js +44 -6
  28. package/lib/module/geometry.js.map +1 -1
  29. package/lib/module/groups.native.js +10 -3
  30. package/lib/module/groups.native.js.map +1 -1
  31. package/lib/module/index.js +1 -0
  32. package/lib/module/index.js.map +1 -1
  33. package/lib/module/presentationCodec.js +6 -2
  34. package/lib/module/presentationCodec.js.map +1 -1
  35. package/lib/typescript/src/SmoothClipBackdropView.d.ts +155 -0
  36. package/lib/typescript/src/SmoothClipBackdropView.d.ts.map +1 -0
  37. package/lib/typescript/src/SmoothClipBackdropViewNativeComponent.d.ts +8 -0
  38. package/lib/typescript/src/SmoothClipBackdropViewNativeComponent.d.ts.map +1 -0
  39. package/lib/typescript/src/SmoothClipView.android.d.ts +1 -1
  40. package/lib/typescript/src/SmoothClipView.android.d.ts.map +1 -1
  41. package/lib/typescript/src/SmoothClipView.d.ts +1 -1
  42. package/lib/typescript/src/SmoothClipView.d.ts.map +1 -1
  43. package/lib/typescript/src/SmoothClipView.ios.d.ts +15 -1
  44. package/lib/typescript/src/SmoothClipView.ios.d.ts.map +1 -1
  45. package/lib/typescript/src/SmoothClipViewNativeComponent.d.ts +4 -0
  46. package/lib/typescript/src/SmoothClipViewNativeComponent.d.ts.map +1 -1
  47. package/lib/typescript/src/geometry.d.ts +19 -0
  48. package/lib/typescript/src/geometry.d.ts.map +1 -1
  49. package/lib/typescript/src/groups.native.d.ts.map +1 -1
  50. package/lib/typescript/src/index.d.ts +4 -2
  51. package/lib/typescript/src/index.d.ts.map +1 -1
  52. package/lib/typescript/src/presentationCodec.d.ts +1 -1
  53. package/lib/typescript/src/presentationCodec.d.ts.map +1 -1
  54. package/package.json +4 -1
  55. package/src/SmoothClipBackdropView.tsx +53 -0
  56. package/src/SmoothClipBackdropViewNativeComponent.ts +15 -0
  57. package/src/SmoothClipView.android.tsx +4 -1
  58. package/src/SmoothClipView.ios.tsx +24 -1
  59. package/src/SmoothClipView.tsx +4 -1
  60. package/src/SmoothClipViewNativeComponent.ts +4 -0
  61. package/src/geometry.ts +59 -4
  62. package/src/groups.native.ts +9 -3
  63. package/src/index.ts +7 -1
  64. package/src/presentationCodec.ts +8 -2
@@ -5,12 +5,13 @@
5
5
  #include "SmoothClipRegistrySnapshot.h"
6
6
 
7
7
  #include <cmath>
8
+ #include <limits>
8
9
  #include <utility>
9
10
 
10
11
  namespace facebook::react {
11
12
  namespace {
12
13
 
13
- constexpr size_t kPresentationStride = 23;
14
+ constexpr size_t kPresentationStride = 25;
14
15
  constexpr size_t kSnapshotStride = kPresentationStride + 1;
15
16
  constexpr size_t kMotionEntryStride = kPresentationStride * 2 + 2;
16
17
 
@@ -67,7 +68,9 @@ smoothclip::Presentation makePresentation(
67
68
  double shadowBlurRadius = 0,
68
69
  double shadowSpreadDistance = 0,
69
70
  double rotation = 0,
70
- double opacity = 1) {
71
+ double opacity = 1,
72
+ double backdropTranslateX = 0,
73
+ double backdropTranslateY = 0) {
71
74
  const bool uniform = topLeftRadius == topRightRadius &&
72
75
  topLeftRadius == bottomRightRadius &&
73
76
  topLeftRadius == bottomLeftRadius;
@@ -85,7 +88,7 @@ smoothclip::Presentation makePresentation(
85
88
  contentScale,
86
89
  {shadowEnabled, shadowRed, shadowGreen, shadowBlue, shadowAlpha,
87
90
  shadowOffsetX, shadowOffsetY, shadowBlurRadius, shadowSpreadDistance},
88
- rotation, opacity};
91
+ rotation, opacity, backdropTranslateX, backdropTranslateY};
89
92
  }
90
93
 
91
94
  bool finitePresentation(const smoothclip::Presentation &presentation) {
@@ -101,6 +104,8 @@ bool finitePresentation(const smoothclip::Presentation &presentation) {
101
104
  std::isfinite(presentation.contentScale) &&
102
105
  presentation.contentScale > 0 &&
103
106
  std::isfinite(presentation.rotation) && std::isfinite(presentation.opacity) &&
107
+ std::isfinite(presentation.backdropTranslateX) &&
108
+ std::isfinite(presentation.backdropTranslateY) &&
104
109
  std::isfinite(presentation.shadow.red) &&
105
110
  std::isfinite(presentation.shadow.green) &&
106
111
  std::isfinite(presentation.shadow.blue) &&
@@ -122,10 +127,14 @@ bool presentationAt(
122
127
  size_t offset,
123
128
  smoothclip::Presentation &result) {
124
129
  double values[kPresentationStride];
130
+ // One length read for the whole packet: `size` is a JSI call of its own,
131
+ // and this runs per clip per drag frame.
132
+ if (offset + kPresentationStride > array.size(runtime)) return false;
125
133
  for (size_t index = 0; index < kPresentationStride; index += 1) {
126
- if (!numberAt(runtime, array, offset + index, values[index])) {
127
- return false;
128
- }
134
+ const jsi::Value value = array.getValueAtIndex(runtime, offset + index);
135
+ if (!value.isNumber()) return false;
136
+ values[index] = value.asNumber();
137
+ if (!std::isfinite(values[index])) return false;
129
138
  }
130
139
  const int32_t curveCode = static_cast<int32_t>(values[8]);
131
140
  if (values[8] != curveCode || !validCurveCode(curveCode) ||
@@ -145,7 +154,8 @@ bool presentationAt(
145
154
  values[11],
146
155
  values[12] == 1,
147
156
  values[13], values[14], values[15], values[16],
148
- values[17], values[18], values[19], values[20], values[21], values[22]);
157
+ values[17], values[18], values[19], values[20], values[21], values[22],
158
+ values[23], values[24]);
149
159
  return finitePresentation(result);
150
160
  }
151
161
 
@@ -187,6 +197,8 @@ void writePresentation(
187
197
  result.setValueAtIndex(runtime, offset + 20, presentation.shadow.spreadDistance);
188
198
  result.setValueAtIndex(runtime, offset + 21, presentation.rotation);
189
199
  result.setValueAtIndex(runtime, offset + 22, presentation.opacity);
200
+ result.setValueAtIndex(runtime, offset + 23, presentation.backdropTranslateX);
201
+ result.setValueAtIndex(runtime, offset + 24, presentation.backdropTranslateY);
190
202
  }
191
203
 
192
204
  jsi::Array snapshotArray(
@@ -387,6 +399,16 @@ bool SmoothClipTurboModule::setClipPresentationBatch(
387
399
  return smoothclip::setPresentationBatch(parsed);
388
400
  }
389
401
 
402
+ // JS stamps a run with Reanimated's frame timestamp in milliseconds on the
403
+ // CACurrentMediaTime base; the registry takes seconds. Anything else means
404
+ // "start now".
405
+ static double startedAtHintSeconds(double startTimestampMs) {
406
+ if (!std::isfinite(startTimestampMs) || startTimestampMs <= 0) {
407
+ return std::numeric_limits<double>::quiet_NaN();
408
+ }
409
+ return startTimestampMs / 1000.0;
410
+ }
411
+
390
412
  int32_t SmoothClipTurboModule::animateTimingGroup(
391
413
  jsi::Runtime &runtime,
392
414
  double controllerId,
@@ -399,7 +421,6 @@ int32_t SmoothClipTurboModule::animateTimingGroup(
399
421
  int32_t reduceMotion,
400
422
  int32_t completionTag,
401
423
  double startTimestamp) {
402
- (void)startTimestamp;
403
424
  std::vector<smoothclip::GroupMotionEntry> parsed;
404
425
  if (!validDriverId(controllerId) ||
405
426
  !fixedGroupEntriesAt(runtime, entries, parsed) ||
@@ -417,7 +438,8 @@ int32_t SmoothClipTurboModule::animateTimingGroup(
417
438
  controlPoint2X,
418
439
  controlPoint2Y,
419
440
  reduceMotion},
420
- completionTag);
441
+ completionTag,
442
+ startedAtHintSeconds(startTimestamp));
421
443
  }
422
444
 
423
445
  int32_t SmoothClipTurboModule::animateSpringGroup(
@@ -432,7 +454,6 @@ int32_t SmoothClipTurboModule::animateSpringGroup(
432
454
  int32_t reduceMotion,
433
455
  int32_t completionTag,
434
456
  double startTimestamp) {
435
- (void)startTimestamp;
436
457
  std::vector<smoothclip::GroupMotionEntry> parsed;
437
458
  if (!validDriverId(controllerId) ||
438
459
  !fixedGroupEntriesAt(runtime, entries, parsed) ||
@@ -452,7 +473,8 @@ int32_t SmoothClipTurboModule::animateSpringGroup(
452
473
  false,
453
474
  reduceMotion,
454
475
  energyThreshold},
455
- completionTag);
476
+ completionTag,
477
+ startedAtHintSeconds(startTimestamp));
456
478
  }
457
479
 
458
480
  jsi::Array SmoothClipTurboModule::cancelAnimationGroup(