@shopify/react-native-skia 0.1.151 → 0.1.152

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 (89) hide show
  1. package/android/CMakeLists.txt +4 -5
  2. package/android/cpp/jni/JniLoad.cpp +7 -5
  3. package/android/cpp/jni/JniSkiaManager.cpp +2 -15
  4. package/android/cpp/jni/include/JniSkiaBaseView.h +68 -0
  5. package/android/cpp/jni/include/JniSkiaDrawView.h +64 -47
  6. package/android/cpp/jni/include/JniSkiaManager.h +8 -10
  7. package/android/cpp/jni/include/JniSkiaPictureView.h +96 -0
  8. package/android/cpp/rnskia-android/{RNSkPlatformContextImpl.h → RNSkAndroidPlatformContext.h} +4 -4
  9. package/android/cpp/rnskia-android/RNSkAndroidView.h +100 -0
  10. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +91 -0
  11. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +39 -0
  12. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +15 -6
  13. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +5 -4
  14. package/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +5 -11
  15. package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaPackage.java +1 -2
  16. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +143 -0
  17. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDrawView.java +17 -145
  18. package/android/src/main/java/com/shopify/reactnative/skia/{RNSkiaViewManager.java → SkiaDrawViewManager.java} +4 -15
  19. package/android/src/main/java/com/shopify/reactnative/skia/SkiaManager.java +1 -10
  20. package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureView.java +45 -0
  21. package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureViewManager.java +64 -0
  22. package/cpp/jsi/JsiValueWrapper.h +11 -0
  23. package/cpp/rnskia/RNSkInfoParameter.h +4 -14
  24. package/cpp/rnskia/RNSkJsView.cpp +211 -0
  25. package/cpp/rnskia/RNSkJsView.h +115 -0
  26. package/cpp/rnskia/RNSkJsiViewApi.h +6 -6
  27. package/cpp/rnskia/RNSkManager.cpp +7 -7
  28. package/cpp/rnskia/RNSkManager.h +7 -7
  29. package/cpp/rnskia/RNSkPictureView.h +124 -0
  30. package/cpp/rnskia/RNSkView.h +287 -0
  31. package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +38 -0
  32. package/ios/RNSkia-iOS/{RNSkDrawViewImpl.mm → RNSkMetalCanvasProvider.mm} +40 -23
  33. package/ios/RNSkia-iOS/{PlatformContext.h → RNSkiOSPlatformContext.h} +4 -4
  34. package/ios/RNSkia-iOS/{PlatformContext.mm → RNSkiOSPlatformContext.mm} +5 -5
  35. package/ios/RNSkia-iOS/RNSkiOSView.h +34 -0
  36. package/ios/RNSkia-iOS/SkiaDrawViewManager.mm +19 -11
  37. package/ios/RNSkia-iOS/SkiaManager.mm +3 -3
  38. package/ios/RNSkia-iOS/SkiaPictureViewManager.h +8 -0
  39. package/ios/RNSkia-iOS/SkiaPictureViewManager.mm +51 -0
  40. package/ios/RNSkia-iOS/SkiaUIView.h +26 -0
  41. package/ios/RNSkia-iOS/{SkiaDrawView.mm → SkiaUIView.mm} +29 -23
  42. package/lib/commonjs/views/SkiaBaseWebView.js +213 -0
  43. package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -0
  44. package/lib/commonjs/views/SkiaPictureView.js +112 -0
  45. package/lib/commonjs/views/SkiaPictureView.js.map +1 -0
  46. package/lib/commonjs/views/SkiaPictureView.web.js +31 -0
  47. package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -0
  48. package/lib/commonjs/views/SkiaView.js +1 -1
  49. package/lib/commonjs/views/SkiaView.js.map +1 -1
  50. package/lib/commonjs/views/SkiaView.web.js +14 -201
  51. package/lib/commonjs/views/SkiaView.web.js.map +1 -1
  52. package/lib/commonjs/views/index.js +13 -0
  53. package/lib/commonjs/views/index.js.map +1 -1
  54. package/lib/commonjs/views/types.js.map +1 -1
  55. package/lib/module/views/SkiaBaseWebView.js +198 -0
  56. package/lib/module/views/SkiaBaseWebView.js.map +1 -0
  57. package/lib/module/views/SkiaPictureView.js +94 -0
  58. package/lib/module/views/SkiaPictureView.js.map +1 -0
  59. package/lib/module/views/SkiaPictureView.web.js +19 -0
  60. package/lib/module/views/SkiaPictureView.web.js.map +1 -0
  61. package/lib/module/views/SkiaView.js +1 -1
  62. package/lib/module/views/SkiaView.js.map +1 -1
  63. package/lib/module/views/SkiaView.web.js +15 -199
  64. package/lib/module/views/SkiaView.web.js.map +1 -1
  65. package/lib/module/views/index.js +1 -0
  66. package/lib/module/views/index.js.map +1 -1
  67. package/lib/module/views/types.js.map +1 -1
  68. package/lib/typescript/src/views/SkiaBaseWebView.d.ts +58 -0
  69. package/lib/typescript/src/views/SkiaPictureView.d.ts +27 -0
  70. package/lib/typescript/src/views/SkiaPictureView.web.d.ts +7 -0
  71. package/lib/typescript/src/views/SkiaView.d.ts +4 -4
  72. package/lib/typescript/src/views/SkiaView.web.d.ts +6 -53
  73. package/lib/typescript/src/views/index.d.ts +1 -0
  74. package/lib/typescript/src/views/types.d.ts +7 -2
  75. package/package.json +1 -1
  76. package/src/views/SkiaBaseWebView.tsx +177 -0
  77. package/src/views/SkiaPictureView.tsx +93 -0
  78. package/src/views/SkiaPictureView.web.tsx +23 -0
  79. package/src/views/SkiaView.tsx +6 -7
  80. package/src/views/SkiaView.web.tsx +18 -167
  81. package/src/views/index.ts +1 -0
  82. package/src/views/types.ts +9 -2
  83. package/android/cpp/jni/JniSkiaDrawView.cpp +0 -113
  84. package/android/cpp/rnskia-android/RNSkDrawViewImpl.cpp +0 -73
  85. package/android/cpp/rnskia-android/RNSkDrawViewImpl.h +0 -48
  86. package/cpp/rnskia/RNSkDrawView.cpp +0 -315
  87. package/cpp/rnskia/RNSkDrawView.h +0 -226
  88. package/ios/RNSkia-iOS/RNSkDrawViewImpl.h +0 -52
  89. package/ios/RNSkia-iOS/SkiaDrawView.h +0 -23
@@ -1,6 +1,8 @@
1
1
  #include "SkiaOpenGLRenderer.h"
2
2
 
3
3
  #include <RNSkLog.h>
4
+ #include <android/native_window.h>
5
+ #include <android/native_window_jni.h>
4
6
 
5
7
  namespace RNSkia
6
8
  {
@@ -20,9 +22,14 @@ namespace RNSkia
20
22
  return threadContexts.at(threadId);
21
23
  }
22
24
 
23
- SkiaOpenGLRenderer::SkiaOpenGLRenderer(ANativeWindow *surface, size_t renderId) : _surfaceTexture(surface),
24
- _renderId(renderId)
25
- {
25
+ SkiaOpenGLRenderer::SkiaOpenGLRenderer(jobject surface) {
26
+ _nativeWindow = ANativeWindow_fromSurface(facebook::jni::Environment::current(), surface);
27
+ }
28
+
29
+ SkiaOpenGLRenderer::~SkiaOpenGLRenderer() {
30
+ // Release surface
31
+ ANativeWindow_release(_nativeWindow);
32
+ _nativeWindow = nullptr;
26
33
  }
27
34
 
28
35
  void SkiaOpenGLRenderer::run(const std::function<void(SkCanvas *)> &cb, int width, int height)
@@ -79,13 +86,15 @@ namespace RNSkia
79
86
  {
80
87
  _renderState = RenderState::Done;
81
88
 
89
+ // Release GL surface
82
90
  if (_glSurface != EGL_NO_SURFACE && getThreadDrawingContext()->glDisplay != EGL_NO_DISPLAY)
83
91
  {
84
92
  eglDestroySurface(getThreadDrawingContext()->glDisplay, _glSurface);
93
+ _glSurface = EGL_NO_SURFACE;
85
94
  }
86
95
 
96
+ // Release Skia Surface
87
97
  _skSurface = nullptr;
88
- _surfaceTexture = nullptr;
89
98
 
90
99
  break;
91
100
  }
@@ -215,7 +224,7 @@ namespace RNSkia
215
224
 
216
225
  bool SkiaOpenGLRenderer::initGLSurface()
217
226
  {
218
- if (_surfaceTexture == nullptr)
227
+ if (_nativeWindow == nullptr)
219
228
  {
220
229
  return false;
221
230
  }
@@ -240,7 +249,7 @@ namespace RNSkia
240
249
  eglCreateWindowSurface(
241
250
  getThreadDrawingContext()->glDisplay,
242
251
  getThreadDrawingContext()->glConfig,
243
- _surfaceTexture,
252
+ _nativeWindow,
244
253
  nullptr);
245
254
 
246
255
  if (_glSurface == EGL_NO_SURFACE)
@@ -3,6 +3,8 @@
3
3
  #include <RNSkLog.h>
4
4
 
5
5
  #include "android/native_window.h"
6
+ #include <fbjni/fbjni.h>
7
+ #include <jni.h>
6
8
  #include "EGL/egl.h"
7
9
  #include "GLES2/gl2.h"
8
10
 
@@ -45,7 +47,8 @@ namespace RNSkia
45
47
  class SkiaOpenGLRenderer
46
48
  {
47
49
  public:
48
- SkiaOpenGLRenderer(ANativeWindow *surface, size_t renderId);
50
+ SkiaOpenGLRenderer(jobject surface);
51
+ ~SkiaOpenGLRenderer();
49
52
 
50
53
  /**
51
54
  * Initializes, renders and tears down the render pipeline depending on the state of the
@@ -116,15 +119,13 @@ namespace RNSkia
116
119
 
117
120
  EGLSurface _glSurface = EGL_NO_SURFACE;
118
121
 
119
- ANativeWindow *_surfaceTexture = nullptr;
122
+ ANativeWindow *_nativeWindow = nullptr;
120
123
  GrBackendRenderTarget _skRenderTarget;
121
124
  sk_sp<SkSurface> _skSurface;
122
125
 
123
126
  int _prevWidth = 0;
124
127
  int _prevHeight = 0;
125
128
 
126
- size_t _renderId;
127
-
128
129
  std::atomic<RenderState> _renderState = { RenderState::Initializing };
129
130
  };
130
131
 
@@ -26,8 +26,8 @@ import java.util.concurrent.Executors;
26
26
  public class PlatformContext {
27
27
  @DoNotStrip
28
28
  private final HybridData mHybridData;
29
+
29
30
  private final ReactContext mContext;
30
- private ExecutorService mDrawCallbackThread = Executors.newSingleThreadExecutor();
31
31
 
32
32
  private boolean _drawLoopActive = false;
33
33
  private boolean _isPaused = false;
@@ -37,7 +37,6 @@ public class PlatformContext {
37
37
  public PlatformContext(ReactContext reactContext) {
38
38
  mContext = reactContext;
39
39
  mHybridData = initHybrid(reactContext.getResources().getDisplayMetrics().density);
40
-
41
40
  }
42
41
 
43
42
  private byte[] getStreamAsBytes(InputStream is) throws IOException {
@@ -66,6 +65,7 @@ public class PlatformContext {
66
65
  Choreographer.getInstance().postFrameCallback(frameCallback);
67
66
  }
68
67
 
68
+ @DoNotStrip
69
69
  public void raise(final String message) {
70
70
  new Handler(Looper.getMainLooper()).post(new Runnable() {
71
71
  @Override
@@ -75,6 +75,7 @@ public class PlatformContext {
75
75
  });
76
76
  }
77
77
 
78
+ @DoNotStrip
78
79
  public void beginDrawLoop() {
79
80
  if (_drawLoopActive) {
80
81
  return;
@@ -88,21 +89,14 @@ public class PlatformContext {
88
89
  });
89
90
  }
90
91
 
92
+ @DoNotStrip
91
93
  public void endDrawLoop() {
92
94
  if (_drawLoopActive) {
93
95
  _drawLoopActive = false;
94
96
  }
95
97
  }
96
98
 
97
- public void triggerOnRenderThread() {
98
- mDrawCallbackThread.execute(new Runnable() {
99
- @Override
100
- public void run() {
101
- notifyTaskReady();
102
- }
103
- });
104
- }
105
-
99
+ @DoNotStrip
106
100
  public byte[] getJniStreamFromSource(String sourceUri) throws IOException {
107
101
  // First try loading the input as a resource directly
108
102
  int resourceId = mContext.getResources().getIdentifier(sourceUri, "drawable", mContext.getPackageName());
@@ -3,7 +3,6 @@
3
3
  package com.shopify.reactnative.skia;
4
4
 
5
5
  import java.util.Arrays;
6
- import java.util.Collections;
7
6
  import java.util.List;
8
7
 
9
8
  import com.facebook.react.ReactPackage;
@@ -19,6 +18,6 @@ public class RNSkiaPackage implements ReactPackage {
19
18
 
20
19
  @Override
21
20
  public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
22
- return Arrays.<ViewManager>asList(new RNSkiaViewManager());
21
+ return Arrays.<ViewManager>asList(new SkiaDrawViewManager(), new SkiaPictureViewManager());
23
22
  }
24
23
  }
@@ -0,0 +1,143 @@
1
+ package com.shopify.reactnative.skia;
2
+
3
+ import android.content.Context;
4
+ import android.graphics.SurfaceTexture;
5
+ import android.view.MotionEvent;
6
+ import android.view.Surface;
7
+ import android.view.TextureView;
8
+
9
+ import com.facebook.jni.annotations.DoNotStrip;
10
+
11
+ public abstract class SkiaBaseView extends TextureView implements TextureView.SurfaceTextureListener {
12
+
13
+ @DoNotStrip
14
+ private Surface mSurface;
15
+
16
+ public SkiaBaseView(Context context) {
17
+ super(context);
18
+ setSurfaceTextureListener(this);
19
+ setOpaque(false);
20
+ }
21
+
22
+ @Override
23
+ public void setBackgroundColor(int color) {
24
+ // Texture view does not support setting the background color.
25
+ }
26
+
27
+ @Override
28
+ public boolean onTouchEvent(MotionEvent ev) {
29
+ // https://developer.android.com/training/gestures/multi
30
+ int action = ev.getActionMasked();
31
+
32
+ MotionEvent.PointerCoords r = new MotionEvent.PointerCoords();
33
+
34
+ double[] points;
35
+
36
+ // If this is a pointer_up/down event we need to handle it a bit specialized
37
+ switch (action) {
38
+ case MotionEvent.ACTION_POINTER_DOWN:
39
+ case MotionEvent.ACTION_POINTER_UP: {
40
+ points = new double[5];
41
+ int pointerIndex = ev.getActionIndex();
42
+ ev.getPointerCoords(pointerIndex, r);
43
+ points[0] = r.x;
44
+ points[1] = r.y;
45
+ points[2] = ev.getPressure(pointerIndex);
46
+ points[3] = motionActionToType(action);
47
+ points[4] = ev.getPointerId(pointerIndex);
48
+
49
+ updateTouchPoints(points);
50
+
51
+ break;
52
+ }
53
+ default: {
54
+ // For the rest we can just handle it like expected
55
+ int count = ev.getPointerCount();
56
+ int pointerIndex = 0;
57
+ points = new double[5 * count];
58
+ for (int i = 0; i < count; i++) {
59
+ ev.getPointerCoords(i, r);
60
+ points[pointerIndex++] = r.x;
61
+ points[pointerIndex++] = r.y;
62
+ points[pointerIndex++] = ev.getPressure(i);
63
+ points[pointerIndex++] = motionActionToType(action);
64
+ points[pointerIndex++] = ev.getPointerId(i);
65
+ }
66
+
67
+ updateTouchPoints(points);
68
+
69
+ break;
70
+ }
71
+ }
72
+
73
+ return true;
74
+ }
75
+
76
+ private static int motionActionToType(int action) {
77
+ int actionType = 3;
78
+ switch (action) {
79
+ case MotionEvent.ACTION_DOWN:
80
+ case MotionEvent.ACTION_POINTER_DOWN:
81
+ actionType = 0;
82
+ break;
83
+ case MotionEvent.ACTION_MOVE:
84
+ actionType = 1;
85
+ break;
86
+ case MotionEvent.ACTION_UP:
87
+ case MotionEvent.ACTION_POINTER_UP:
88
+ actionType = 2;
89
+ break;
90
+ case MotionEvent.ACTION_CANCEL:
91
+ actionType = 3;
92
+ break;
93
+ }
94
+ return actionType;
95
+ }
96
+
97
+ @Override
98
+ public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
99
+ mSurface = new Surface(surface);
100
+ surfaceAvailable(mSurface, width, height);
101
+ }
102
+
103
+ @Override
104
+ public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
105
+ surfaceSizeChanged(width, height);
106
+ }
107
+
108
+ @Override
109
+ public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
110
+ // Notify the native side
111
+ surfaceDestroyed();
112
+ // https://developer.android.com/reference/android/view/TextureView.SurfaceTextureListener#onSurfaceTextureDestroyed(android.graphics.SurfaceTexture)
113
+ // Invoked when the specified SurfaceTexture is about to be destroyed. If returns true,
114
+ // no rendering should happen inside the surface texture after this method is invoked.
115
+ // We've measured this and it seems like we need to call release and return true - and
116
+ // then handle the issue with this being ripped out underneath the native layer in the C++
117
+ // code.
118
+ mSurface.release();
119
+ // Return true - we promise that no more rendering will be done now.
120
+ return true;
121
+ }
122
+
123
+ @Override
124
+ public void onSurfaceTextureUpdated(SurfaceTexture surface) {
125
+ // Nothing special to do here
126
+ }
127
+
128
+ protected abstract void surfaceAvailable(Object surface, int width, int height);
129
+
130
+ protected abstract void surfaceSizeChanged(int width, int height);
131
+
132
+ protected abstract void surfaceDestroyed();
133
+
134
+ protected abstract void setMode(String mode);
135
+
136
+ protected abstract void setDebugMode(boolean show);
137
+
138
+ protected abstract void updateTouchPoints(double[] points);
139
+
140
+ protected abstract void registerView(int nativeId);
141
+
142
+ protected abstract void unregisterView();
143
+ }
@@ -1,173 +1,45 @@
1
1
  package com.shopify.reactnative.skia;
2
2
 
3
3
  import android.content.Context;
4
- import android.graphics.SurfaceTexture;
5
- import android.view.Surface;
6
- import android.view.TextureView;
7
- import android.view.MotionEvent;
8
4
 
9
5
  import com.facebook.jni.HybridData;
10
6
  import com.facebook.jni.annotations.DoNotStrip;
11
7
  import com.facebook.react.bridge.ReactContext;
12
8
 
13
- public class SkiaDrawView extends TextureView implements TextureView.SurfaceTextureListener {
14
-
15
- private static final String TAG = "Java::JniSkiaDrawView";
16
-
9
+ public class SkiaDrawView extends SkiaBaseView {
17
10
  @DoNotStrip
18
11
  private HybridData mHybridData;
19
12
 
20
- @DoNotStrip
21
- private boolean mViewRemoved;
22
-
23
- @DoNotStrip
24
- private Surface mSurface;
25
-
26
- public SkiaDrawView(Context ctx) {
27
- super(ctx);
28
- RNSkiaModule skiaModule = ((ReactContext)ctx).getNativeModule(RNSkiaModule.class);
13
+ public SkiaDrawView(Context context) {
14
+ super(context);
15
+ RNSkiaModule skiaModule = ((ReactContext) context).getNativeModule(RNSkiaModule.class);
29
16
  mHybridData = initHybrid(skiaModule.getSkiaManager());
30
- setSurfaceTextureListener(this);
31
- setOpaque(false);
32
- }
33
-
34
- @Override
35
- public void setBackgroundColor(int color) {
36
- // Texture view does not support setting the background color.
37
- }
38
-
39
- public void releaseSurface() {
40
- if(mSurface != null) {
41
- mSurface.release();
42
- mSurface = null;
43
- }
44
- // We can only reset the native side when the view was removed from screen.
45
- // releasing the surface can also be done when the view is hidden and then
46
- // we should only release the surface - and keep the native part around.
47
- if(mViewRemoved) {
48
- mHybridData.resetNative();
49
- }
50
- }
51
-
52
- void onViewRemoved() {
53
- mViewRemoved = true;
54
- // We can only reset the native side when the view was removed from screen.
55
- // releasing the surface can also be done when the view is hidden and then
56
- // we should only release the surface - and keep the native part around.
57
- if(mSurface == null) {
58
- mHybridData.resetNative();
59
- }
60
17
  }
61
18
 
62
19
  @Override
63
- public boolean onTouchEvent(MotionEvent ev) {
64
- // https://developer.android.com/training/gestures/multi
65
- int action = ev.getActionMasked();
66
-
67
- MotionEvent.PointerCoords r = new MotionEvent.PointerCoords();
68
-
69
- double[] points;
70
-
71
- // If this is a pointer_up/down event we need to handle it a bit specialized
72
- switch (action) {
73
- case MotionEvent.ACTION_POINTER_DOWN:
74
- case MotionEvent.ACTION_POINTER_UP: {
75
- points = new double[5];
76
- int pointerIndex = ev.getActionIndex();
77
- ev.getPointerCoords(pointerIndex, r);
78
- points[0] = r.x;
79
- points[1] = r.y;
80
- points[2] = ev.getPressure(pointerIndex);
81
- points[3] = motionActionToType(action);
82
- points[4] = ev.getPointerId(pointerIndex);
83
-
84
- updateTouchPoints(points);
85
-
86
- break;
87
- }
88
- default: {
89
- // For the rest we can just handle it like expected
90
- int count = ev.getPointerCount();
91
- int pointerIndex = 0;
92
- points = new double[5 * count];
93
- for (int i = 0; i < count; i++) {
94
- ev.getPointerCoords(i, r);
95
- points[pointerIndex++] = r.x;
96
- points[pointerIndex++] = r.y;
97
- points[pointerIndex++] = ev.getPressure(i);
98
- points[pointerIndex++] = motionActionToType(action);
99
- points[pointerIndex++] = ev.getPointerId(i);
100
- }
101
-
102
- updateTouchPoints(points);
103
-
104
- break;
105
- }
106
- }
107
-
108
- return true;
20
+ protected void finalize() throws Throwable {
21
+ super.finalize();
22
+ mHybridData.resetNative();
109
23
  }
110
24
 
111
- private static int motionActionToType(int action) {
112
- int actionType = 3;
113
- switch (action) {
114
- case MotionEvent.ACTION_DOWN:
115
- case MotionEvent.ACTION_POINTER_DOWN:
116
- actionType = 0;
117
- break;
118
- case MotionEvent.ACTION_MOVE:
119
- actionType = 1;
120
- break;
121
- case MotionEvent.ACTION_UP:
122
- case MotionEvent.ACTION_POINTER_UP:
123
- actionType = 2;
124
- break;
125
- case MotionEvent.ACTION_CANCEL:
126
- actionType = 3;
127
- break;
128
- }
129
- return actionType;
130
- }
131
-
132
- @Override
133
- public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
134
- mSurface = new Surface(surface);
135
- surfaceAvailable(mSurface, width, height);
136
- }
137
-
138
- @Override
139
- public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
140
- surfaceSizeChanged(width, height);
141
- }
25
+ private native HybridData initHybrid(SkiaManager skiaManager);
142
26
 
143
- @Override
144
- public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
145
- surfaceDestroyed();
146
- // https://developer.android.com/reference/android/view/TextureView.SurfaceTextureListener#onSurfaceTextureDestroyed(android.graphics.SurfaceTexture)
147
- // Invoked when the specified SurfaceTexture is about to be destroyed. If returns true,
148
- // no rendering should happen inside the surface texture after this method is invoked.
149
- // When returning false, the client needs to call SurfaceTexture#release().
150
- return false;
151
- }
27
+ protected native void surfaceAvailable(Object surface, int width, int height);
152
28
 
153
- @Override
154
- public void onSurfaceTextureUpdated(SurfaceTexture surface) {
155
- // Nothing special to do here
156
- }
29
+ protected native void surfaceSizeChanged(int width, int height);
157
30
 
158
- private native HybridData initHybrid(SkiaManager skiaManager);
31
+ protected native void surfaceDestroyed();
159
32
 
160
- private native void surfaceAvailable(Object surface, int width, int height);
33
+ protected native void setBgColor(int color);
161
34
 
162
- private native void surfaceSizeChanged(int width, int height);
35
+ protected native void setMode(String mode);
163
36
 
164
- private native void surfaceDestroyed();
37
+ protected native void setDebugMode(boolean show);
165
38
 
166
- private native void setBgColor(int color);
39
+ protected native void updateTouchPoints(double[] points);
167
40
 
168
- public native void setMode(String mode);
41
+ protected native void registerView(int nativeId);
169
42
 
170
- public native void setDebugMode(boolean show);
43
+ protected native void unregisterView();
171
44
 
172
- public native void updateTouchPoints(double[] points);
173
45
  }
@@ -1,6 +1,5 @@
1
1
  package com.shopify.reactnative.skia;
2
2
 
3
- import com.facebook.react.bridge.ReactContext;
4
3
  import com.facebook.react.uimanager.BaseViewManager;
5
4
  import com.facebook.react.uimanager.LayoutShadowNode;
6
5
  import com.facebook.react.uimanager.ThemedReactContext;
@@ -9,16 +8,12 @@ import com.facebook.react.uimanager.annotations.ReactProp;
9
8
  import androidx.annotation.NonNull;
10
9
  import androidx.annotation.Nullable;
11
10
 
12
- import java.util.HashMap;
13
-
14
- public class RNSkiaViewManager extends BaseViewManager<SkiaDrawView, LayoutShadowNode> {
15
-
16
- final private HashMap<SkiaDrawView, Integer> mViewMapping = new HashMap();
11
+ public class SkiaDrawViewManager extends BaseViewManager<SkiaDrawView, LayoutShadowNode> {
17
12
 
18
13
  @NonNull
19
14
  @Override
20
15
  public String getName() {
21
- return "ReactNativeSkiaView";
16
+ return "SkiaDrawView";
22
17
  }
23
18
 
24
19
  @Override
@@ -39,9 +34,7 @@ public class RNSkiaViewManager extends BaseViewManager<SkiaDrawView, LayoutShado
39
34
  public void setNativeId(@NonNull SkiaDrawView view, @Nullable String nativeId) {
40
35
  super.setNativeId(view, nativeId);
41
36
  int nativeIdResolved = Integer.parseInt(nativeId);
42
- RNSkiaModule skiaModule = ((ReactContext)view.getContext()).getNativeModule(RNSkiaModule.class);
43
- skiaModule.getSkiaManager().register(nativeIdResolved, view);
44
- mViewMapping.put(view, nativeIdResolved);
37
+ view.registerView(nativeIdResolved);
45
38
  }
46
39
 
47
40
  @ReactProp(name = "mode")
@@ -57,11 +50,7 @@ public class RNSkiaViewManager extends BaseViewManager<SkiaDrawView, LayoutShado
57
50
  @Override
58
51
  public void onDropViewInstance(@NonNull SkiaDrawView view) {
59
52
  super.onDropViewInstance(view);
60
- RNSkiaModule skiaModule = ((ReactContext)view.getContext()).getNativeModule(RNSkiaModule.class);
61
- Integer nativeId = mViewMapping.get(view);
62
- skiaModule.getSkiaManager().unregister(nativeId);
63
- mViewMapping.remove(view);
64
- view.onViewRemoved();
53
+ view.unregisterView();
65
54
  }
66
55
 
67
56
  @NonNull
@@ -43,14 +43,6 @@ public class SkiaManager {
43
43
  return mPlatformContext;
44
44
  }
45
45
 
46
- public void register(int nativeId, SkiaDrawView view) {
47
- registerSkiaView(nativeId, view);
48
- }
49
-
50
- public void unregister(int nativeId) {
51
- unregisterSkiaView(nativeId);
52
- }
53
-
54
46
  public void onHostResume() { mPlatformContext.onResume(); }
55
47
 
56
48
  public void onHostPause() { mPlatformContext.onPause(); }
@@ -58,9 +50,8 @@ public class SkiaManager {
58
50
  // private C++ functions
59
51
  private native HybridData initHybrid(long jsContext, CallInvokerHolderImpl jsCallInvokerHolder,
60
52
  PlatformContext platformContext);
53
+
61
54
  private native void initializeRuntime();
62
- private native void registerSkiaView(int nativeId, SkiaDrawView view);
63
- private native void unregisterSkiaView(int nativeId);
64
55
  public native void invalidate();
65
56
 
66
57
  }
@@ -0,0 +1,45 @@
1
+ package com.shopify.reactnative.skia;
2
+
3
+ import android.content.Context;
4
+
5
+ import com.facebook.jni.HybridData;
6
+ import com.facebook.jni.annotations.DoNotStrip;
7
+ import com.facebook.react.bridge.ReactContext;
8
+
9
+ public class SkiaPictureView extends SkiaBaseView {
10
+ @DoNotStrip
11
+ private HybridData mHybridData;
12
+
13
+ public SkiaPictureView(Context context) {
14
+ super(context);
15
+ RNSkiaModule skiaModule = ((ReactContext) context).getNativeModule(RNSkiaModule.class);
16
+ mHybridData = initHybrid(skiaModule.getSkiaManager());
17
+ }
18
+
19
+ @Override
20
+ protected void finalize() throws Throwable {
21
+ super.finalize();
22
+ mHybridData.resetNative();
23
+ }
24
+
25
+ private native HybridData initHybrid(SkiaManager skiaManager);
26
+
27
+ protected native void surfaceAvailable(Object surface, int width, int height);
28
+
29
+ protected native void surfaceSizeChanged(int width, int height);
30
+
31
+ protected native void surfaceDestroyed();
32
+
33
+ protected native void setBgColor(int color);
34
+
35
+ protected native void setMode(String mode);
36
+
37
+ protected native void setDebugMode(boolean show);
38
+
39
+ protected native void updateTouchPoints(double[] points);
40
+
41
+ protected native void registerView(int nativeId);
42
+
43
+ protected native void unregisterView();
44
+
45
+ }
@@ -0,0 +1,64 @@
1
+ package com.shopify.reactnative.skia;
2
+
3
+ import com.facebook.react.bridge.ReactContext;
4
+ import com.facebook.react.uimanager.BaseViewManager;
5
+ import com.facebook.react.uimanager.LayoutShadowNode;
6
+ import com.facebook.react.uimanager.ThemedReactContext;
7
+ import com.facebook.react.uimanager.annotations.ReactProp;
8
+
9
+ import androidx.annotation.NonNull;
10
+ import androidx.annotation.Nullable;
11
+
12
+ import java.util.HashMap;
13
+
14
+ public class SkiaPictureViewManager extends BaseViewManager<SkiaPictureView, LayoutShadowNode> {
15
+
16
+ @NonNull
17
+ @Override
18
+ public String getName() {
19
+ return "SkiaPictureView";
20
+ }
21
+
22
+ @Override
23
+ public LayoutShadowNode createShadowNodeInstance() {
24
+ return new LayoutShadowNode();
25
+ }
26
+
27
+ @Override
28
+ public Class<? extends LayoutShadowNode> getShadowNodeClass() {
29
+ return LayoutShadowNode.class;
30
+ }
31
+
32
+ @Override
33
+ public void updateExtraData(SkiaPictureView root, Object extraData) {
34
+ }
35
+
36
+ @Override
37
+ public void setNativeId(@NonNull SkiaPictureView view, @Nullable String nativeId) {
38
+ super.setNativeId(view, nativeId);
39
+ int nativeIdResolved = Integer.parseInt(nativeId);
40
+ view.registerView(nativeIdResolved);
41
+ }
42
+
43
+ @ReactProp(name = "mode")
44
+ public void setMode(SkiaPictureView view, String mode) {
45
+ view.setMode(mode);
46
+ }
47
+
48
+ @ReactProp(name = "debug")
49
+ public void setDebug(SkiaPictureView view, boolean show) {
50
+ view.setDebugMode(show);
51
+ }
52
+
53
+ @Override
54
+ public void onDropViewInstance(@NonNull SkiaPictureView view) {
55
+ super.onDropViewInstance(view);
56
+ view.unregisterView();
57
+ }
58
+
59
+ @NonNull
60
+ @Override
61
+ protected SkiaPictureView createViewInstance(@NonNull ThemedReactContext reactContext) {
62
+ return new SkiaPictureView(reactContext);
63
+ }
64
+ }