@shopify/react-native-skia 2.3.7 → 2.3.8
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/cpp/jsi/ViewProperty.h +34 -1
 - package/package.json +1 -1
 
    
        package/cpp/jsi/ViewProperty.h
    CHANGED
    
    | 
         @@ -1,5 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            #pragma once
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
      
 3 
     | 
    
         
            +
            #include <atomic>
         
     | 
| 
       3 
4 
     | 
    
         
             
            #include <functional>
         
     | 
| 
       4 
5 
     | 
    
         
             
            #include <jsi/jsi.h>
         
     | 
| 
       5 
6 
     | 
    
         
             
            #include <memory>
         
     | 
| 
         @@ -7,10 +8,35 @@ 
     | 
|
| 
       7 
8 
     | 
    
         
             
            #include <variant>
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
10 
     | 
    
         
             
            #include "JsiSkPicture.h"
         
     | 
| 
      
 11 
     | 
    
         
            +
            #include "RuntimeLifecycleMonitor.h"
         
     | 
| 
       10 
12 
     | 
    
         | 
| 
       11 
13 
     | 
    
         
             
            namespace RNJsi {
         
     | 
| 
       12 
14 
     | 
    
         
             
            namespace jsi = facebook::jsi;
         
     | 
| 
       13 
15 
     | 
    
         | 
| 
      
 16 
     | 
    
         
            +
            class RuntimeAwareRuntimeGuard : public RuntimeLifecycleListener {
         
     | 
| 
      
 17 
     | 
    
         
            +
            public:
         
     | 
| 
      
 18 
     | 
    
         
            +
              explicit RuntimeAwareRuntimeGuard(jsi::Runtime &runtime)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  : _runtime(&runtime) {
         
     | 
| 
      
 20 
     | 
    
         
            +
                RuntimeLifecycleMonitor::addListener(runtime, this);
         
     | 
| 
      
 21 
     | 
    
         
            +
              }
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
              ~RuntimeAwareRuntimeGuard() override {
         
     | 
| 
      
 24 
     | 
    
         
            +
                auto runtime = _runtime.load();
         
     | 
| 
      
 25 
     | 
    
         
            +
                if (runtime != nullptr) {
         
     | 
| 
      
 26 
     | 
    
         
            +
                  RuntimeLifecycleMonitor::removeListener(*runtime, this);
         
     | 
| 
      
 27 
     | 
    
         
            +
                }
         
     | 
| 
      
 28 
     | 
    
         
            +
              }
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
              void onRuntimeDestroyed(jsi::Runtime *) override {
         
     | 
| 
      
 31 
     | 
    
         
            +
                _runtime.store(nullptr);
         
     | 
| 
      
 32 
     | 
    
         
            +
              }
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
              jsi::Runtime *getRuntime() const { return _runtime.load(); }
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            private:
         
     | 
| 
      
 37 
     | 
    
         
            +
              std::atomic<jsi::Runtime *> _runtime;
         
     | 
| 
      
 38 
     | 
    
         
            +
            };
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
       14 
40 
     | 
    
         
             
            class ViewProperty {
         
     | 
| 
       15 
41 
     | 
    
         
             
            public:
         
     | 
| 
       16 
42 
     | 
    
         
             
              ViewProperty(jsi::Runtime &runtime, const jsi::Value &value) {
         
     | 
| 
         @@ -31,8 +57,15 @@ public: 
     | 
|
| 
       31 
57 
     | 
    
         
             
              ViewProperty(jsi::Runtime &runtime, const jsi::Value &value,
         
     | 
| 
       32 
58 
     | 
    
         
             
                           PlatformContext platformContext, size_t nativeId) {
         
     | 
| 
       33 
59 
     | 
    
         
             
                // Set the onSize callback with all the necessary context
         
     | 
| 
      
 60 
     | 
    
         
            +
                auto runtimeGuard = std::make_shared<RuntimeAwareRuntimeGuard>(runtime);
         
     | 
| 
       34 
61 
     | 
    
         
             
                _value = std::function<void(int, int)>(
         
     | 
| 
       35 
     | 
    
         
            -
                    [ 
     | 
| 
      
 62 
     | 
    
         
            +
                    [runtimeGuard, platformContext, nativeId](int width, int height) {
         
     | 
| 
      
 63 
     | 
    
         
            +
                      auto runtimePtr = runtimeGuard->getRuntime();
         
     | 
| 
      
 64 
     | 
    
         
            +
                      if (runtimePtr == nullptr) {
         
     | 
| 
      
 65 
     | 
    
         
            +
                        return;
         
     | 
| 
      
 66 
     | 
    
         
            +
                      }
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                      jsi::Runtime &runtime = *runtimePtr;
         
     | 
| 
       36 
69 
     | 
    
         
             
                      jsi::Object size(runtime);
         
     | 
| 
       37 
70 
     | 
    
         
             
                      auto pd = platformContext->getPixelDensity();
         
     | 
| 
       38 
71 
     | 
    
         
             
                      size.setProperty(runtime, "width", jsi::Value(width / pd));
         
     |