Skip to content

Commit 8e38749

Browse files
authored
Merge pull request #2062 from Shopify/remove-skia-values
Deprecate Skia Value API
2 parents 540047e + 91b514d commit 8e38749

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+20
-3542
lines changed

docs/docs/animations/reanimated2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ In the example below, the animation runs on the JS thread due to the use of Rean
2121

2222
```tsx twoslash
2323
import {useEffect} from "react";
24-
import {Canvas, Rect, mix, useValue} from "@shopify/react-native-skia";
24+
import {Canvas, Rect, mix} from "@shopify/react-native-skia";
2525
import {useSharedValue, withRepeat, withTiming, useDerivedValue} from "react-native-reanimated";
2626

2727
const MyComponent = () => {

package/cpp/rnskia/RNSkAnimation.h

Lines changed: 0 additions & 65 deletions
This file was deleted.

package/cpp/rnskia/RNSkJsiViewApi.h

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "JsiHostObject.h"
1111
#include "JsiValueWrapper.h"
1212
#include "RNSkPlatformContext.h"
13-
#include "RNSkValue.h"
1413
#include "RNSkView.h"
1514
#include <jsi/jsi.h>
1615

@@ -178,59 +177,8 @@ class RNSkJsiViewApi : public RNJsi::JsiHostObject,
178177
return jsi::Value::undefined();
179178
}
180179

181-
JSI_HOST_FUNCTION(registerValuesInView) {
182-
// Check params
183-
if (!arguments[1].isObject() ||
184-
!arguments[1].asObject(runtime).isArray(runtime)) {
185-
throw jsi::JSError(runtime,
186-
"Expected array of Values as second parameter");
187-
return jsi::Value::undefined();
188-
}
189-
190-
// Get identifier of native SkiaView
191-
int nativeId = arguments[0].asNumber();
192-
193-
// Get values that should be added as dependencies
194-
auto values = arguments[1].asObject(runtime).asArray(runtime);
195-
std::vector<std::function<void()>> unsubscribers;
196-
const std::size_t size = values.size(runtime);
197-
unsubscribers.reserve(size);
198-
for (size_t i = 0; i < size; ++i) {
199-
auto value = values.getValueAtIndex(runtime, i)
200-
.asObject(runtime)
201-
.asHostObject<RNSkReadonlyValue>(runtime);
202-
203-
if (value != nullptr) {
204-
// Add change listener
205-
unsubscribers.push_back(value->addListener(
206-
[weakSelf = weak_from_this(), nativeId](jsi::Runtime &) {
207-
auto self = weakSelf.lock();
208-
if (self) {
209-
auto info = self->getEnsuredViewInfo(nativeId);
210-
if (info->view != nullptr) {
211-
info->view->requestRedraw();
212-
}
213-
}
214-
}));
215-
}
216-
}
217-
218-
// Return unsubscribe method that unsubscribes to all values
219-
// that we subscribed to.
220-
return jsi::Function::createFromHostFunction(
221-
runtime, jsi::PropNameID::forUtf8(runtime, "unsubscribe"), 0,
222-
JSI_HOST_FUNCTION_LAMBDA {
223-
// decrease dependency count on the Skia View
224-
for (auto &unsub : unsubscribers) {
225-
unsub();
226-
}
227-
return jsi::Value::undefined();
228-
});
229-
}
230-
231180
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(RNSkJsiViewApi, setJsiProperty),
232181
JSI_EXPORT_FUNC(RNSkJsiViewApi, callJsiMethod),
233-
JSI_EXPORT_FUNC(RNSkJsiViewApi, registerValuesInView),
234182
JSI_EXPORT_FUNC(RNSkJsiViewApi, requestRedraw),
235183
JSI_EXPORT_FUNC(RNSkJsiViewApi, makeImageSnapshot))
236184

package/cpp/rnskia/RNSkManager.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include <JsiSkApi.h>
99
#include <RNSkJsiViewApi.h>
10-
#include <RNSkValueApi.h>
1110
#include <RNSkView.h>
1211

1312
#include <JsiDomApi.h>
@@ -80,11 +79,6 @@ void RNSkManager::installBindings() {
8079
*_jsRuntime, "SkiaViewApi",
8180
jsi::Object::createFromHostObject(*_jsRuntime, _viewApi));
8281

83-
auto skiaValueApi = std::make_shared<RNSkValueApi>(_platformContext);
84-
_jsRuntime->global().setProperty(
85-
*_jsRuntime, "SkiaValueApi",
86-
jsi::Object::createFromHostObject(*_jsRuntime, std::move(skiaValueApi)));
87-
8882
auto skiaDomApi = std::make_shared<JsiDomApi>(_platformContext);
8983
_jsRuntime->global().setProperty(
9084
*_jsRuntime, "SkiaDomApi",

package/cpp/rnskia/RNSkValueApi.h

Lines changed: 0 additions & 72 deletions
This file was deleted.

package/cpp/rnskia/RNSkView.h

Lines changed: 2 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "JsiValueWrapper.h"
1010
#include "RNSkPlatformContext.h"
11-
#include "RNSkValue.h"
1211

1312
#include "JsiSkImage.h"
1413
#include "JsiSkPoint.h"
@@ -163,51 +162,15 @@ class RNSkView : public std::enable_shared_from_this<RNSkView> {
163162
/**
164163
Destructor
165164
*/
166-
virtual ~RNSkView() {
167-
endDrawingLoop();
168-
if (_onSizeUnsubscribe != nullptr) {
169-
_onSizeUnsubscribe();
170-
_onSizeUnsubscribe = nullptr;
171-
}
172-
}
165+
virtual ~RNSkView() { endDrawingLoop(); }
173166

174167
/**
175168
Sets custom properties. Custom properties are properties that are set
176169
directly from Javascript without having to go through the async bridge.
177170
*/
178171
virtual void setJsiProperties(
179172
std::unordered_map<std::string, RNJsi::JsiValueWrapper> &props) {
180-
181-
for (auto &prop : props) {
182-
if (prop.first == "onSize") {
183-
// Start by removing any subscribers to the current onSize
184-
if (_onSizeUnsubscribe != nullptr) {
185-
_onSizeUnsubscribe();
186-
_onSizeUnsubscribe = nullptr;
187-
}
188-
if (prop.second.isUndefinedOrNull()) {
189-
// Clear touchCallback
190-
_onSize = nullptr;
191-
} else if (prop.second.getType() !=
192-
RNJsi::JsiWrapperValueType::HostObject) {
193-
// We expect a function for the draw callback custom property
194-
throw std::runtime_error(
195-
"Expected a Skia mutable value for the onSize property.");
196-
}
197-
// Save onSize
198-
_onSize =
199-
std::dynamic_pointer_cast<RNSkValue>(prop.second.getAsHostObject());
200-
201-
// Add listener
202-
_onSizeUnsubscribe =
203-
_onSize->addListener([weakSelf = weak_from_this()](jsi::Runtime &) {
204-
auto self = weakSelf.lock();
205-
if (self) {
206-
self->requestRedraw();
207-
}
208-
});
209-
}
210-
}
173+
// Nothing here...
211174
}
212175

213176
/**
@@ -326,53 +289,6 @@ class RNSkView : public std::enable_shared_from_this<RNSkView> {
326289
});
327290
}
328291

329-
void updateOnSize() {
330-
if (_onSize != nullptr) {
331-
auto width = _canvasProvider->getScaledWidth() /
332-
_platformContext->getPixelDensity();
333-
auto height = _canvasProvider->getScaledHeight() /
334-
_platformContext->getPixelDensity();
335-
336-
_platformContext->runOnJavascriptThread(
337-
[width, height, weakSelf = weak_from_this()]() {
338-
auto self = weakSelf.lock();
339-
if (self) {
340-
auto runtime = self->_platformContext->getJsRuntime();
341-
auto onSize = self->_onSize->getCurrent(*runtime);
342-
if (!onSize.isObject()) {
343-
throw jsi::JSError(
344-
*runtime,
345-
"Expected onSize property to be a mutable Skia value.");
346-
return;
347-
}
348-
auto onSizeObj = onSize.asObject(*runtime);
349-
350-
auto wVal = onSizeObj.getProperty(*runtime, "width");
351-
auto hVal = onSizeObj.getProperty(*runtime, "height");
352-
353-
if (!wVal.isNumber() || !hVal.isNumber()) {
354-
throw jsi::JSError(*runtime,
355-
"Expected onSize property to be a mutable "
356-
"Skia value of type SkSize.");
357-
return;
358-
}
359-
360-
auto w = wVal.asNumber();
361-
auto h = hVal.asNumber();
362-
363-
if (w != width || h != height) {
364-
// Update
365-
auto newValue = jsi::Object(*runtime);
366-
newValue.setProperty(*runtime, "width", width);
367-
newValue.setProperty(*runtime, "height", height);
368-
self->_onSize->set_current(*runtime,
369-
jsi::Value(*runtime, newValue));
370-
}
371-
}
372-
});
373-
}
374-
}
375-
376292
/**
377293
Draw loop callback
378294
*/
@@ -381,9 +297,6 @@ class RNSkView : public std::enable_shared_from_this<RNSkView> {
381297
_drawingMode == RNSkDrawingMode::Continuous) {
382298
_redrawRequestCounter = 0;
383299

384-
// Update size if needed
385-
updateOnSize();
386-
387300
if (!_renderer->tryRender(_canvasProvider)) {
388301
// The renderer could not render cause it was busy, just schedule
389302
// redrawing on the next frame.
@@ -396,8 +309,6 @@ class RNSkView : public std::enable_shared_from_this<RNSkView> {
396309
std::shared_ptr<RNSkCanvasProvider> _canvasProvider;
397310
std::shared_ptr<RNSkRenderer> _renderer;
398311

399-
std::shared_ptr<RNSkValue> _onSize;
400-
std::function<void()> _onSizeUnsubscribe;
401312
RNSkDrawingMode _drawingMode = RNSkDrawingMode::Default;
402313
size_t _nativeId;
403314

package/cpp/rnskia/dom/JsiDomApi.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
#include "JsiHostObject.h"
1010

11-
#include "base/JsiDependencyManager.h"
12-
1311
#include "nodes/JsiCircleNode.h"
1412
#include "nodes/JsiDiffRectNode.h"
1513
#include "nodes/JsiFillNode.h"
@@ -56,8 +54,6 @@ class JsiDomApi : public JsiHostObject {
5654
public:
5755
explicit JsiDomApi(std::shared_ptr<RNSkPlatformContext> context)
5856
: JsiHostObject() {
59-
installFunction("DependencyManager",
60-
JsiDependencyManager::createCtor(context));
6157

6258
// Shapes
6359
installFunction("RectNode", JsiRectNode::createCtor(context));

0 commit comments

Comments
 (0)