@shopify/react-native-skia 0.1.124 → 0.1.127
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/android/CMakeLists.txt +3 -0
- package/android/build.gradle +1 -1
- package/cpp/api/JsiSkApi.h +3 -1
- package/cpp/api/JsiSkCanvas.h +1 -1
- package/cpp/api/JsiSkColor.h +41 -7
- package/cpp/api/JsiSkColorFilterFactory.h +2 -1
- package/cpp/api/JsiSkImageFilter.h +0 -2
- package/cpp/api/JsiSkImageFilterFactory.h +37 -17
- package/cpp/api/JsiSkMatrix.h +44 -2
- package/cpp/api/JsiSkPaint.h +4 -7
- package/cpp/api/JsiSkRuntimeEffect.h +7 -0
- package/cpp/api/JsiSkRuntimeEffectFactory.h +3 -2
- package/cpp/api/JsiSkRuntimeShaderBuilder.h +70 -0
- package/cpp/api/JsiSkShaderFactory.h +2 -2
- package/cpp/api/JsiSkVertices.h +1 -1
- package/cpp/api/third_party/CSSColorParser.cpp +194 -0
- package/cpp/api/third_party/CSSColorParser.h +1 -191
- package/cpp/jsi/JsiSimpleValueWrapper.h +108 -0
- package/cpp/rnskia/values/RNSkReadonlyValue.h +13 -12
- package/ios/RNSkia-iOS/PlatformContext.h +30 -4
- package/ios/RNSkia-iOS/SkiaDrawView.mm +9 -12
- package/lib/commonjs/{values/animation → animation}/decay/decay.js +0 -0
- package/lib/commonjs/{values/animation → animation}/decay/decay.js.map +0 -0
- package/lib/commonjs/{values/animation → animation}/decay/index.js +0 -0
- package/lib/commonjs/{values/animation → animation}/decay/index.js.map +0 -0
- package/lib/commonjs/{values/animation → animation}/decay/runDecay.js +1 -1
- package/lib/commonjs/animation/decay/runDecay.js.map +1 -0
- package/lib/commonjs/{values/animation → animation}/decay/types.js +0 -0
- package/lib/commonjs/{values/animation → animation}/decay/types.js.map +0 -0
- package/lib/commonjs/{values/animation → animation}/functions/index.js +0 -0
- package/lib/commonjs/{values/animation → animation}/functions/index.js.map +0 -0
- package/lib/commonjs/animation/functions/interpolate.js +141 -0
- package/lib/commonjs/animation/functions/interpolate.js.map +1 -0
- package/lib/commonjs/animation/functions/interpolateColors.js +39 -0
- package/lib/commonjs/animation/functions/interpolateColors.js.map +1 -0
- package/lib/commonjs/{values/animation → animation}/index.js +0 -0
- package/lib/commonjs/{values/animation → animation}/index.js.map +0 -0
- package/lib/commonjs/{values/animation → animation}/spring/Spring.js +0 -0
- package/lib/commonjs/{values/animation → animation}/spring/Spring.js.map +0 -0
- package/lib/commonjs/{values/animation → animation}/spring/functions/index.js +0 -0
- package/lib/commonjs/{values/animation → animation}/spring/functions/index.js.map +0 -0
- package/lib/commonjs/{values/animation → animation}/spring/functions/spring.js +0 -0
- package/lib/commonjs/{values/animation → animation}/spring/functions/spring.js.map +0 -0
- package/lib/commonjs/{values/animation → animation}/spring/index.js +0 -0
- package/lib/commonjs/{values/animation → animation}/spring/index.js.map +0 -0
- package/lib/commonjs/{values/animation → animation}/spring/runSpring.js +0 -0
- package/lib/commonjs/animation/spring/runSpring.js.map +1 -0
- package/lib/commonjs/{values/animation → animation}/spring/types.js +0 -0
- package/lib/commonjs/{values/animation → animation}/spring/types.js.map +0 -0
- package/lib/commonjs/{values/animation → animation}/spring/useSpring.js +0 -0
- package/lib/commonjs/animation/spring/useSpring.js.map +1 -0
- package/lib/commonjs/{values/animation → animation}/timing/Easing.js +0 -0
- package/lib/commonjs/{values/animation → animation}/timing/Easing.js.map +0 -0
- package/lib/commonjs/{values/animation → animation}/timing/createTiming.js +1 -1
- package/lib/commonjs/animation/timing/createTiming.js.map +1 -0
- package/lib/commonjs/{values/animation → animation}/timing/functions/bezier.js +0 -0
- package/lib/commonjs/{values/animation → animation}/timing/functions/bezier.js.map +0 -0
- package/lib/commonjs/{values/animation → animation}/timing/functions/getResolvedParams.js +0 -0
- package/lib/commonjs/{values/animation → animation}/timing/functions/getResolvedParams.js.map +0 -0
- package/lib/commonjs/{values/animation → animation}/timing/functions/index.js +0 -0
- package/lib/commonjs/{values/animation → animation}/timing/functions/index.js.map +0 -0
- package/lib/commonjs/{values/animation → animation}/timing/functions/timing.js +0 -0
- package/lib/commonjs/{values/animation → animation}/timing/functions/timing.js.map +1 -1
- package/lib/commonjs/{values/animation → animation}/timing/functions/types.js +0 -0
- package/lib/commonjs/{values/animation → animation}/timing/functions/types.js.map +0 -0
- package/lib/commonjs/{values/animation → animation}/timing/index.js +0 -0
- package/lib/commonjs/{values/animation → animation}/timing/index.js.map +0 -0
- package/lib/commonjs/{values/animation → animation}/timing/runTiming.js +0 -0
- package/lib/commonjs/animation/timing/runTiming.js.map +1 -0
- package/lib/commonjs/{values/animation → animation}/timing/useLoop.js +0 -0
- package/lib/commonjs/{values/animation → animation}/timing/useLoop.js.map +0 -0
- package/lib/commonjs/{values/animation → animation}/timing/useTiming.js +1 -1
- package/lib/commonjs/animation/timing/useTiming.js.map +1 -0
- package/lib/commonjs/{values/animation → animation}/types.js +0 -0
- package/lib/commonjs/{values/animation → animation}/types.js.map +0 -0
- package/lib/commonjs/index.js +13 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/renderer/components/colorFilters/BlendColor.js.map +1 -1
- package/lib/commonjs/renderer/components/imageFilters/InnerShadow.js +4 -2
- package/lib/commonjs/renderer/components/imageFilters/InnerShadow.js.map +1 -1
- package/lib/commonjs/renderer/components/imageFilters/RuntimeShader.js +37 -0
- package/lib/commonjs/renderer/components/imageFilters/RuntimeShader.js.map +1 -0
- package/lib/commonjs/renderer/components/imageFilters/index.js +13 -0
- package/lib/commonjs/renderer/components/imageFilters/index.js.map +1 -1
- package/lib/commonjs/renderer/components/shaders/Gradient.js +1 -1
- package/lib/commonjs/renderer/components/shaders/Gradient.js.map +1 -1
- package/lib/commonjs/renderer/components/shaders/Shader.js.map +1 -1
- package/lib/commonjs/renderer/processors/Rects.js +5 -15
- package/lib/commonjs/renderer/processors/Rects.js.map +1 -1
- package/lib/commonjs/renderer/processors/math/Matrix3.js +42 -63
- package/lib/commonjs/renderer/processors/math/Matrix3.js.map +1 -1
- package/lib/commonjs/renderer/processors/math/Vector.js +4 -5
- package/lib/commonjs/renderer/processors/math/Vector.js.map +1 -1
- package/lib/commonjs/skia/Color.js +14 -38
- package/lib/commonjs/skia/Color.js.map +1 -1
- package/lib/commonjs/skia/ImageFilter/ImageFilterFactory.js.map +1 -1
- package/lib/commonjs/skia/Matrix.js.map +1 -1
- package/lib/commonjs/skia/Shader/useShader.js +4 -1
- package/lib/commonjs/skia/Shader/useShader.js.map +1 -1
- package/lib/commonjs/skia/Skia.js +3 -45
- package/lib/commonjs/skia/Skia.js.map +1 -1
- package/lib/commonjs/skia/SkiaApi.js +4 -0
- package/lib/commonjs/skia/SkiaApi.js.map +1 -0
- package/lib/commonjs/values/api.js +4 -6
- package/lib/commonjs/values/api.js.map +1 -1
- package/lib/commonjs/values/api.web.js +18 -0
- package/lib/commonjs/values/api.web.js.map +1 -0
- package/lib/commonjs/values/index.js +0 -13
- package/lib/commonjs/values/index.js.map +1 -1
- package/lib/commonjs/values/web/RNSkAnimation.js +46 -0
- package/lib/commonjs/values/web/RNSkAnimation.js.map +1 -0
- package/lib/commonjs/values/web/RNSkClockValue.js +75 -0
- package/lib/commonjs/values/web/RNSkClockValue.js.map +1 -0
- package/lib/commonjs/values/web/RNSkDerivedValue.js +51 -0
- package/lib/commonjs/values/web/RNSkDerivedValue.js.map +1 -0
- package/lib/commonjs/values/web/RNSkReadonlyValue.js +45 -0
- package/lib/commonjs/values/web/RNSkReadonlyValue.js.map +1 -0
- package/lib/commonjs/values/web/RNSkValue.js +73 -0
- package/lib/commonjs/values/web/RNSkValue.js.map +1 -0
- package/lib/commonjs/values/web/api.js +31 -0
- package/lib/commonjs/values/web/api.js.map +1 -0
- package/lib/commonjs/values/web/index.js +19 -0
- package/lib/commonjs/values/web/index.js.map +1 -0
- package/lib/commonjs/views/SkiaView.js +13 -10
- package/lib/commonjs/views/SkiaView.js.map +1 -1
- package/lib/commonjs/views/api.js +11 -0
- package/lib/commonjs/views/api.js.map +1 -0
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/{values/animation → animation}/decay/decay.js +0 -0
- package/lib/module/{values/animation → animation}/decay/decay.js.map +0 -0
- package/lib/module/{values/animation → animation}/decay/index.js +0 -0
- package/lib/module/{values/animation → animation}/decay/index.js.map +0 -0
- package/lib/module/{values/animation → animation}/decay/runDecay.js +1 -1
- package/lib/module/animation/decay/runDecay.js.map +1 -0
- package/lib/module/{values/animation → animation}/decay/types.js +0 -0
- package/lib/module/{values/animation → animation}/decay/types.js.map +0 -0
- package/lib/module/{values/animation → animation}/functions/index.js +0 -0
- package/lib/module/{values/animation → animation}/functions/index.js.map +0 -0
- package/lib/module/animation/functions/interpolate.js +132 -0
- package/lib/module/animation/functions/interpolate.js.map +1 -0
- package/lib/module/animation/functions/interpolateColors.js +23 -0
- package/lib/module/animation/functions/interpolateColors.js.map +1 -0
- package/lib/module/{values/animation → animation}/index.js +0 -0
- package/lib/module/{values/animation → animation}/index.js.map +0 -0
- package/lib/module/{values/animation → animation}/spring/Spring.js +0 -0
- package/lib/module/{values/animation → animation}/spring/Spring.js.map +0 -0
- package/lib/module/{values/animation → animation}/spring/functions/index.js +0 -0
- package/lib/module/{values/animation → animation}/spring/functions/index.js.map +0 -0
- package/lib/module/{values/animation → animation}/spring/functions/spring.js +0 -0
- package/lib/module/{values/animation → animation}/spring/functions/spring.js.map +0 -0
- package/lib/module/{values/animation → animation}/spring/index.js +0 -0
- package/lib/module/{values/animation → animation}/spring/index.js.map +0 -0
- package/lib/module/{values/animation → animation}/spring/runSpring.js +0 -0
- package/lib/module/animation/spring/runSpring.js.map +1 -0
- package/lib/module/{values/animation → animation}/spring/types.js +0 -0
- package/lib/module/{values/animation → animation}/spring/types.js.map +0 -0
- package/lib/module/{values/animation → animation}/spring/useSpring.js +0 -0
- package/lib/module/animation/spring/useSpring.js.map +1 -0
- package/lib/module/{values/animation → animation}/timing/Easing.js +0 -0
- package/lib/module/{values/animation → animation}/timing/Easing.js.map +0 -0
- package/lib/module/{values/animation → animation}/timing/createTiming.js +1 -1
- package/lib/module/animation/timing/createTiming.js.map +1 -0
- package/lib/module/{values/animation → animation}/timing/functions/bezier.js +0 -0
- package/lib/module/{values/animation → animation}/timing/functions/bezier.js.map +0 -0
- package/lib/module/{values/animation → animation}/timing/functions/getResolvedParams.js +0 -0
- package/lib/module/{values/animation → animation}/timing/functions/getResolvedParams.js.map +0 -0
- package/lib/module/{values/animation → animation}/timing/functions/index.js +0 -0
- package/lib/module/{values/animation → animation}/timing/functions/index.js.map +0 -0
- package/lib/module/{values/animation → animation}/timing/functions/timing.js +0 -0
- package/lib/module/{values/animation → animation}/timing/functions/timing.js.map +1 -1
- package/lib/module/{values/animation → animation}/timing/functions/types.js +0 -0
- package/lib/module/{values/animation → animation}/timing/functions/types.js.map +0 -0
- package/lib/module/{values/animation → animation}/timing/index.js +0 -0
- package/lib/module/{values/animation → animation}/timing/index.js.map +0 -0
- package/lib/module/{values/animation → animation}/timing/runTiming.js +0 -0
- package/lib/module/animation/timing/runTiming.js.map +1 -0
- package/lib/module/{values/animation → animation}/timing/useLoop.js +0 -0
- package/lib/module/{values/animation → animation}/timing/useLoop.js.map +0 -0
- package/lib/module/{values/animation → animation}/timing/useTiming.js +1 -1
- package/lib/module/animation/timing/useTiming.js.map +1 -0
- package/lib/module/{values/animation → animation}/types.js +0 -0
- package/lib/module/{values/animation → animation}/types.js.map +0 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/renderer/components/colorFilters/BlendColor.js.map +1 -1
- package/lib/module/renderer/components/imageFilters/InnerShadow.js +3 -2
- package/lib/module/renderer/components/imageFilters/InnerShadow.js.map +1 -1
- package/lib/module/renderer/components/imageFilters/RuntimeShader.js +19 -0
- package/lib/module/renderer/components/imageFilters/RuntimeShader.js.map +1 -0
- package/lib/module/renderer/components/imageFilters/index.js +1 -0
- package/lib/module/renderer/components/imageFilters/index.js.map +1 -1
- package/lib/module/renderer/components/shaders/Gradient.js +2 -2
- package/lib/module/renderer/components/shaders/Gradient.js.map +1 -1
- package/lib/module/renderer/components/shaders/Shader.js.map +1 -1
- package/lib/module/renderer/processors/Rects.js +4 -15
- package/lib/module/renderer/processors/Rects.js.map +1 -1
- package/lib/module/renderer/processors/math/Matrix3.js +52 -72
- package/lib/module/renderer/processors/math/Matrix3.js.map +1 -1
- package/lib/module/renderer/processors/math/Vector.js +3 -5
- package/lib/module/renderer/processors/math/Vector.js.map +1 -1
- package/lib/module/skia/Color.js +9 -25
- package/lib/module/skia/Color.js.map +1 -1
- package/lib/module/skia/ImageFilter/ImageFilterFactory.js.map +1 -1
- package/lib/module/skia/Matrix.js.map +1 -1
- package/lib/module/skia/Shader/useShader.js +4 -1
- package/lib/module/skia/Shader/useShader.js.map +1 -1
- package/lib/module/skia/Skia.js +2 -46
- package/lib/module/skia/Skia.js.map +1 -1
- package/lib/module/skia/SkiaApi.js +2 -0
- package/lib/module/skia/SkiaApi.js.map +1 -0
- package/lib/module/values/api.js +4 -6
- package/lib/module/values/api.js.map +1 -1
- package/lib/module/values/api.web.js +7 -0
- package/lib/module/values/api.web.js.map +1 -0
- package/lib/module/values/index.js +0 -1
- package/lib/module/values/index.js.map +1 -1
- package/lib/module/values/web/RNSkAnimation.js +36 -0
- package/lib/module/values/web/RNSkAnimation.js.map +1 -0
- package/lib/module/values/web/RNSkClockValue.js +65 -0
- package/lib/module/values/web/RNSkClockValue.js.map +1 -0
- package/lib/module/values/web/RNSkDerivedValue.js +41 -0
- package/lib/module/values/web/RNSkDerivedValue.js.map +1 -0
- package/lib/module/values/web/RNSkReadonlyValue.js +36 -0
- package/lib/module/values/web/RNSkReadonlyValue.js.map +1 -0
- package/lib/module/values/web/RNSkValue.js +63 -0
- package/lib/module/values/web/RNSkValue.js.map +1 -0
- package/lib/module/values/web/api.js +19 -0
- package/lib/module/values/web/api.js.map +1 -0
- package/lib/module/values/web/index.js +2 -0
- package/lib/module/values/web/index.js.map +1 -0
- package/lib/module/views/SkiaView.js +1 -3
- package/lib/module/views/SkiaView.js.map +1 -1
- package/lib/module/views/api.js +4 -0
- package/lib/module/views/api.js.map +1 -0
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/src/{values/animation → animation}/decay/decay.d.ts +0 -0
- package/lib/typescript/src/{values/animation → animation}/decay/index.d.ts +0 -0
- package/lib/typescript/src/{values/animation → animation}/decay/runDecay.d.ts +2 -2
- package/lib/typescript/src/{values/animation → animation}/decay/types.d.ts +1 -1
- package/lib/typescript/src/{values/animation → animation}/functions/index.d.ts +0 -0
- package/lib/typescript/src/animation/functions/interpolate.d.ts +11 -0
- package/lib/typescript/src/animation/functions/interpolateColors.d.ts +3 -0
- package/lib/typescript/src/{values/animation → animation}/index.d.ts +0 -0
- package/lib/typescript/src/{values/animation → animation}/spring/Spring.d.ts +0 -0
- package/lib/typescript/src/{values/animation → animation}/spring/functions/index.d.ts +0 -0
- package/lib/typescript/src/{values/animation → animation}/spring/functions/spring.d.ts +0 -0
- package/lib/typescript/src/{values/animation → animation}/spring/index.d.ts +0 -0
- package/lib/typescript/src/{values/animation → animation}/spring/runSpring.d.ts +1 -1
- package/lib/typescript/src/{values/animation → animation}/spring/types.d.ts +0 -0
- package/lib/typescript/src/{values/animation → animation}/spring/useSpring.d.ts +1 -1
- package/lib/typescript/src/{values/animation → animation}/timing/Easing.d.ts +0 -0
- package/lib/typescript/src/{values/animation → animation}/timing/createTiming.d.ts +2 -2
- package/lib/typescript/src/{values/animation → animation}/timing/functions/bezier.d.ts +0 -0
- package/lib/typescript/src/{values/animation → animation}/timing/functions/getResolvedParams.d.ts +0 -0
- package/lib/typescript/src/{values/animation → animation}/timing/functions/index.d.ts +0 -0
- package/lib/typescript/src/{values/animation → animation}/timing/functions/timing.d.ts +1 -1
- package/lib/typescript/src/{values/animation → animation}/timing/functions/types.d.ts +0 -0
- package/lib/typescript/src/{values/animation → animation}/timing/index.d.ts +0 -0
- package/lib/typescript/src/{values/animation → animation}/timing/runTiming.d.ts +1 -1
- package/lib/typescript/src/{values/animation → animation}/timing/useLoop.d.ts +0 -0
- package/lib/typescript/src/{values/animation → animation}/timing/useTiming.d.ts +1 -1
- package/lib/typescript/src/{values/animation → animation}/types.d.ts +0 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/renderer/components/colorFilters/BlendColor.d.ts +1 -1
- package/lib/typescript/src/renderer/components/imageFilters/RuntimeShader.d.ts +7 -0
- package/lib/typescript/src/renderer/components/imageFilters/index.d.ts +1 -0
- package/lib/typescript/src/renderer/components/shaders/Gradient.d.ts +1 -1
- package/lib/typescript/src/renderer/components/shaders/Shader.d.ts +2 -2
- package/lib/typescript/src/renderer/components/shapes/Circle.d.ts +1 -4
- package/lib/typescript/src/renderer/processors/Rects.d.ts +9 -41
- package/lib/typescript/src/renderer/processors/math/Matrix3.d.ts +1 -5
- package/lib/typescript/src/renderer/processors/math/Vector.d.ts +5 -17
- package/lib/typescript/src/skia/Color.d.ts +8 -9
- package/lib/typescript/src/skia/ImageFilter/ImageFilterFactory.d.ts +16 -0
- package/lib/typescript/src/skia/Matrix.d.ts +7 -1
- package/lib/typescript/src/skia/RuntimeEffect/RuntimeEffect.d.ts +2 -1
- package/lib/typescript/src/skia/RuntimeEffect/RuntimeEffectFactory.d.ts +2 -2
- package/lib/typescript/src/skia/Shader/useShader.d.ts +1 -1
- package/lib/typescript/src/skia/Skia.d.ts +28 -95
- package/lib/typescript/src/skia/SkiaApi.d.ts +71 -0
- package/lib/typescript/src/skia/Surface/Surface.d.ts +1 -1
- package/lib/typescript/src/skia/Surface/SurfaceFactory.d.ts +2 -2
- package/lib/typescript/src/values/api.d.ts +2 -25
- package/lib/typescript/src/values/api.web.d.ts +2 -0
- package/lib/typescript/src/values/index.d.ts +0 -1
- package/lib/typescript/src/values/types.d.ts +24 -1
- package/lib/typescript/src/values/web/RNSkAnimation.d.ts +9 -0
- package/lib/typescript/src/values/web/RNSkClockValue.d.ts +13 -0
- package/lib/typescript/src/values/web/RNSkDerivedValue.d.ts +9 -0
- package/lib/typescript/src/values/web/RNSkReadonlyValue.d.ts +11 -0
- package/lib/typescript/src/values/web/RNSkValue.d.ts +14 -0
- package/lib/typescript/src/values/web/api.d.ts +2 -0
- package/lib/typescript/src/values/web/index.d.ts +1 -0
- package/lib/typescript/src/views/SkiaView.d.ts +3 -36
- package/lib/typescript/src/views/api.d.ts +5 -0
- package/lib/typescript/src/views/types.d.ts +32 -0
- package/package.json +2 -2
- package/src/{values/animation → animation}/decay/decay.ts +0 -0
- package/src/{values/animation → animation}/decay/index.ts +0 -0
- package/src/{values/animation → animation}/decay/runDecay.ts +2 -2
- package/src/{values/animation → animation}/decay/types.ts +1 -1
- package/src/{values/animation → animation}/functions/index.ts +0 -0
- package/src/animation/functions/interpolate.ts +182 -0
- package/src/animation/functions/interpolateColors.ts +58 -0
- package/src/{values/animation → animation}/index.ts +0 -0
- package/src/{values/animation → animation}/spring/Spring.ts +0 -0
- package/src/{values/animation → animation}/spring/functions/index.ts +0 -0
- package/src/{values/animation → animation}/spring/functions/spring.ts +0 -0
- package/src/{values/animation → animation}/spring/index.ts +0 -0
- package/src/{values/animation → animation}/spring/runSpring.ts +1 -1
- package/src/{values/animation → animation}/spring/types.ts +0 -0
- package/src/{values/animation → animation}/spring/useSpring.ts +1 -1
- package/src/{values/animation → animation}/timing/Easing.ts +0 -0
- package/src/{values/animation → animation}/timing/createTiming.ts +2 -2
- package/src/{values/animation → animation}/timing/functions/__tests__/timing.spec.ts +0 -0
- package/src/{values/animation → animation}/timing/functions/bezier.ts +0 -0
- package/src/{values/animation → animation}/timing/functions/getResolvedParams.ts +0 -0
- package/src/{values/animation → animation}/timing/functions/index.ts +0 -0
- package/src/{values/animation → animation}/timing/functions/timing.ts +1 -1
- package/src/{values/animation → animation}/timing/functions/types.ts +0 -0
- package/src/{values/animation → animation}/timing/index.ts +0 -0
- package/src/{values/animation → animation}/timing/runTiming.ts +1 -1
- package/src/{values/animation → animation}/timing/useLoop.ts +0 -0
- package/src/{values/animation → animation}/timing/useTiming.ts +2 -2
- package/src/{values/animation → animation}/types.ts +0 -0
- package/src/index.ts +1 -0
- package/src/renderer/components/colorFilters/BlendColor.tsx +1 -1
- package/src/renderer/components/imageFilters/InnerShadow.tsx +4 -2
- package/src/renderer/components/imageFilters/RuntimeShader.tsx +23 -0
- package/src/renderer/components/imageFilters/index.ts +1 -0
- package/src/renderer/components/shaders/Gradient.ts +2 -4
- package/src/renderer/components/shaders/Shader.tsx +2 -2
- package/src/renderer/processors/Rects.ts +6 -12
- package/src/renderer/processors/math/Matrix3.ts +24 -105
- package/src/renderer/processors/math/Vector.ts +3 -2
- package/src/skia/Color.ts +13 -27
- package/src/skia/ImageFilter/ImageFilterFactory.ts +20 -0
- package/src/skia/Matrix.ts +8 -1
- package/src/skia/RuntimeEffect/RuntimeEffect.ts +3 -1
- package/src/skia/RuntimeEffect/RuntimeEffectFactory.ts +2 -2
- package/src/skia/Shader/useShader.ts +4 -1
- package/src/skia/Skia.ts +4 -126
- package/src/skia/SkiaApi.ts +86 -0
- package/src/skia/Surface/Surface.ts +1 -1
- package/src/skia/Surface/SurfaceFactory.ts +2 -2
- package/src/values/api.ts +3 -42
- package/src/values/api.web.ts +5 -0
- package/src/values/index.ts +0 -1
- package/src/values/types.ts +30 -1
- package/src/values/web/RNSkAnimation.ts +33 -0
- package/src/values/web/RNSkClockValue.ts +58 -0
- package/src/values/web/RNSkDerivedValue.ts +38 -0
- package/src/values/web/RNSkReadonlyValue.ts +32 -0
- package/src/values/web/RNSkValue.ts +57 -0
- package/src/values/web/__tests__/RNSkAnimation.spec.ts +21 -0
- package/src/values/web/__tests__/RNSkDerivedValue.spec.ts +15 -0
- package/src/values/web/__tests__/RNSkReadonlyValue.spec.ts +8 -0
- package/src/values/web/__tests__/RNSkValue.spec.ts +11 -0
- package/src/values/web/api.ts +33 -0
- package/src/values/web/index.ts +1 -0
- package/src/views/SkiaView.tsx +3 -49
- package/src/views/api.ts +7 -0
- package/src/views/types.ts +40 -0
- package/lib/commonjs/values/animation/decay/runDecay.js.map +0 -1
- package/lib/commonjs/values/animation/functions/interpolate.js +0 -139
- package/lib/commonjs/values/animation/functions/interpolate.js.map +0 -1
- package/lib/commonjs/values/animation/functions/interpolateColors.js +0 -47
- package/lib/commonjs/values/animation/functions/interpolateColors.js.map +0 -1
- package/lib/commonjs/values/animation/spring/runSpring.js.map +0 -1
- package/lib/commonjs/values/animation/spring/useSpring.js.map +0 -1
- package/lib/commonjs/values/animation/timing/createTiming.js.map +0 -1
- package/lib/commonjs/values/animation/timing/runTiming.js.map +0 -1
- package/lib/commonjs/values/animation/timing/useTiming.js.map +0 -1
- package/lib/module/values/animation/decay/runDecay.js.map +0 -1
- package/lib/module/values/animation/functions/interpolate.js +0 -132
- package/lib/module/values/animation/functions/interpolate.js.map +0 -1
- package/lib/module/values/animation/functions/interpolateColors.js +0 -32
- package/lib/module/values/animation/functions/interpolateColors.js.map +0 -1
- package/lib/module/values/animation/spring/runSpring.js.map +0 -1
- package/lib/module/values/animation/spring/useSpring.js.map +0 -1
- package/lib/module/values/animation/timing/createTiming.js.map +0 -1
- package/lib/module/values/animation/timing/runTiming.js.map +0 -1
- package/lib/module/values/animation/timing/useTiming.js.map +0 -1
- package/lib/typescript/scripts/install-npm.d.ts +0 -1
- package/lib/typescript/src/values/animation/functions/interpolate.d.ts +0 -7
- package/lib/typescript/src/values/animation/functions/interpolateColors.d.ts +0 -3
- package/src/values/animation/functions/interpolate.ts +0 -169
- package/src/values/animation/functions/interpolateColors.ts +0 -62
@@ -122,71 +122,6 @@ namespace CSSColorParser {
|
|
122
122
|
{ "yellow", { 255, 255, 0, 1 } }, { "yellowgreen", { 154, 205, 50, 1 } }
|
123
123
|
};
|
124
124
|
|
125
|
-
template <typename T>
|
126
|
-
uint8_t clamp_css_byte(T i) { // Clamp to integer 0 .. 255.
|
127
|
-
i = ::round(i); // Seems to be what Chrome does (vs truncation).
|
128
|
-
return i < 0 ? 0 : i > 255 ? 255 : uint8_t(i);
|
129
|
-
}
|
130
|
-
|
131
|
-
template <typename T>
|
132
|
-
float clamp_css_float(T f) { // Clamp to float 0.0 .. 1.0.
|
133
|
-
return f < 0 ? 0 : f > 1 ? 1 : float(f);
|
134
|
-
}
|
135
|
-
|
136
|
-
float parseFloat(const std::string& str) {
|
137
|
-
return strtof(str.c_str(), nullptr);
|
138
|
-
}
|
139
|
-
|
140
|
-
int64_t parseInt(const std::string& str, uint8_t base = 10) {
|
141
|
-
return strtoll(str.c_str(), nullptr, base);
|
142
|
-
}
|
143
|
-
|
144
|
-
uint8_t parse_css_int(const std::string& str) { // int or percentage.
|
145
|
-
if (str.length() && str.back() == '%') {
|
146
|
-
return clamp_css_byte(parseFloat(str) / 100.0f * 255.0f);
|
147
|
-
} else {
|
148
|
-
return clamp_css_byte(parseInt(str));
|
149
|
-
}
|
150
|
-
}
|
151
|
-
|
152
|
-
float parse_css_float(const std::string& str) { // float or percentage.
|
153
|
-
if (str.length() && str.back() == '%') {
|
154
|
-
return clamp_css_float(parseFloat(str) / 100.0f);
|
155
|
-
} else {
|
156
|
-
return clamp_css_float(parseFloat(str));
|
157
|
-
}
|
158
|
-
}
|
159
|
-
|
160
|
-
float css_hue_to_rgb(float m1, float m2, float h) {
|
161
|
-
if (h < 0.0f) {
|
162
|
-
h += 1.0f;
|
163
|
-
} else if (h > 1.0f) {
|
164
|
-
h -= 1.0f;
|
165
|
-
}
|
166
|
-
|
167
|
-
if (h * 6.0f < 1.0f) {
|
168
|
-
return m1 + (m2 - m1) * h * 6.0f;
|
169
|
-
}
|
170
|
-
if (h * 2.0f < 1.0f) {
|
171
|
-
return m2;
|
172
|
-
}
|
173
|
-
if (h * 3.0f < 2.0f) {
|
174
|
-
return m1 + (m2 - m1) * (2.0f / 3.0f - h) * 6.0f;
|
175
|
-
}
|
176
|
-
return m1;
|
177
|
-
}
|
178
|
-
|
179
|
-
std::vector<std::string> split(const std::string& s, char delim) {
|
180
|
-
std::vector<std::string> elems;
|
181
|
-
std::stringstream ss(s);
|
182
|
-
std::string item;
|
183
|
-
while (std::getline(ss, item, delim)) {
|
184
|
-
elems.push_back(item);
|
185
|
-
}
|
186
|
-
return elems;
|
187
|
-
}
|
188
|
-
|
189
|
-
|
190
125
|
inline bool operator==(const Color& lhs, const Color& rhs) {
|
191
126
|
return lhs.r == rhs.r && lhs.g == rhs.g && lhs.b == rhs.b && ::fabs(lhs.a - rhs.a) < 0.0001f;
|
192
127
|
}
|
@@ -195,130 +130,5 @@ namespace CSSColorParser {
|
|
195
130
|
return !(lhs == rhs);
|
196
131
|
}
|
197
132
|
|
198
|
-
Color parse(const std::string& css_str)
|
199
|
-
std::string str = css_str;
|
200
|
-
|
201
|
-
// Remove all whitespace, not compliant, but should just be more accepting.
|
202
|
-
str.erase(std::remove(str.begin(), str.end(), ' '), str.end());
|
203
|
-
|
204
|
-
// Convert to lowercase.
|
205
|
-
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
|
206
|
-
|
207
|
-
for (const auto& namedColor : namedColors) {
|
208
|
-
if (str == namedColor.name) {
|
209
|
-
return { namedColor.color };
|
210
|
-
}
|
211
|
-
}
|
212
|
-
|
213
|
-
// #abc and #abc123 syntax.
|
214
|
-
if (str.length() && str.front() == '#') {
|
215
|
-
auto iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
|
216
|
-
if (str.length() == 4) {
|
217
|
-
if (!(iv >= 0 && iv <= 0xfff)) {
|
218
|
-
return {};
|
219
|
-
} else {
|
220
|
-
return {
|
221
|
-
static_cast<uint8_t>(((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8)),
|
222
|
-
static_cast<uint8_t>((iv & 0xf0) | ((iv & 0xf0) >> 4)),
|
223
|
-
static_cast<uint8_t>((iv & 0xf) | ((iv & 0xf) << 4)),
|
224
|
-
1
|
225
|
-
};
|
226
|
-
}
|
227
|
-
} else if (str.length() == 7) {
|
228
|
-
if (!(iv >= 0 && iv <= 0xffffff)) {
|
229
|
-
return {}; // Covers NaN.
|
230
|
-
} else {
|
231
|
-
return {
|
232
|
-
static_cast<uint8_t>((iv & 0xff0000) >> 16),
|
233
|
-
static_cast<uint8_t>((iv & 0xff00) >> 8),
|
234
|
-
static_cast<uint8_t>(iv & 0xff),
|
235
|
-
1
|
236
|
-
};
|
237
|
-
}
|
238
|
-
}else if (str.length() == 5) {
|
239
|
-
// #rgba
|
240
|
-
if (!(iv >= 0 && iv <= 0xffff)) return {}; // Covers NaN.
|
241
|
-
return {
|
242
|
-
static_cast<uint8_t>(((iv & 0xf000) >> 8) | ((iv & 0xf000) >> 12)),
|
243
|
-
static_cast<uint8_t>(((iv & 0x0f00) >> 4) | ((iv & 0x0f00) >> 8)),
|
244
|
-
static_cast<uint8_t>((iv & 0x00f0) | ((iv & 0x00f0) >> 4)),
|
245
|
-
static_cast<uint8_t>(((iv & 0x000f) << 4 | (iv & 0x000f))) / 255.0f
|
246
|
-
};
|
247
|
-
} else if (str.length() == 9) {
|
248
|
-
// #rrggbbaa
|
249
|
-
if (!(iv >= 0 && iv <= 0xffffffff)) return {}; // Covers NaN.
|
250
|
-
return {
|
251
|
-
static_cast<uint8_t>(((iv & 0xff000000) >> 24) & 0xff),
|
252
|
-
static_cast<uint8_t>((iv & 0x00ff0000) >> 16),
|
253
|
-
static_cast<uint8_t>((iv & 0x0000ff00) >> 8),
|
254
|
-
static_cast<uint8_t>((iv & 0x000000ff)) / 255.0f
|
255
|
-
};
|
256
|
-
}
|
257
|
-
|
258
|
-
return {};
|
259
|
-
}
|
260
|
-
|
261
|
-
size_t op = str.find_first_of('('), ep = str.find_first_of(')');
|
262
|
-
if (op != std::string::npos && ep + 1 == str.length()) {
|
263
|
-
const std::string fname = str.substr(0, op);
|
264
|
-
const std::vector<std::string> params = split(str.substr(op + 1, ep - (op + 1)), ',');
|
265
|
-
|
266
|
-
float alpha = 1.0f;
|
267
|
-
|
268
|
-
if (fname == "rgba" || fname == "rgb") {
|
269
|
-
if (fname == "rgba") {
|
270
|
-
if (params.size() != 4) {
|
271
|
-
return { };
|
272
|
-
}
|
273
|
-
alpha = parse_css_float(params.back());
|
274
|
-
} else {
|
275
|
-
if (params.size() != 3) {
|
276
|
-
return { };
|
277
|
-
}
|
278
|
-
}
|
279
|
-
|
280
|
-
return {
|
281
|
-
parse_css_int(params[0]),
|
282
|
-
parse_css_int(params[1]),
|
283
|
-
parse_css_int(params[2]),
|
284
|
-
alpha
|
285
|
-
};
|
286
|
-
|
287
|
-
} else if (fname == "hsla" || fname == "hsl") {
|
288
|
-
if (fname == "hsla") {
|
289
|
-
if (params.size() != 4) {
|
290
|
-
return { };
|
291
|
-
}
|
292
|
-
alpha = parse_css_float(params.back());
|
293
|
-
} else {
|
294
|
-
if (params.size() != 3) {
|
295
|
-
return { };
|
296
|
-
}
|
297
|
-
}
|
298
|
-
|
299
|
-
float h = parseFloat(params[0]) / 360.0f;
|
300
|
-
float i;
|
301
|
-
// Normalize the hue to [0..1[
|
302
|
-
h = std::modf(h, &i);
|
303
|
-
|
304
|
-
// NOTE(deanm): According to the CSS spec s/l should only be
|
305
|
-
// percentages, but we don't bother and let float or percentage.
|
306
|
-
float s = parse_css_float(params[1]);
|
307
|
-
float l = parse_css_float(params[2]);
|
308
|
-
|
309
|
-
float m2 = l <= 0.5f ? l * (s + 1.0f) : l + s - l * s;
|
310
|
-
float m1 = l * 2.0f - m2;
|
311
|
-
|
312
|
-
return {
|
313
|
-
clamp_css_byte(css_hue_to_rgb(m1, m2, h + 1.0f / 3.0f) * 255.0f),
|
314
|
-
clamp_css_byte(css_hue_to_rgb(m1, m2, h) * 255.0f),
|
315
|
-
clamp_css_byte(css_hue_to_rgb(m1, m2, h - 1.0f / 3.0f) * 255.0f),
|
316
|
-
alpha
|
317
|
-
};
|
318
|
-
}
|
319
|
-
}
|
320
|
-
|
321
|
-
return { };
|
322
|
-
}
|
323
|
-
|
133
|
+
Color parse(const std::string& css_str);
|
324
134
|
} // namespace CSSColorParser
|
@@ -0,0 +1,108 @@
|
|
1
|
+
|
2
|
+
#pragma once
|
3
|
+
|
4
|
+
#include <jsi/jsi.h>
|
5
|
+
|
6
|
+
namespace RNJsi
|
7
|
+
{
|
8
|
+
using namespace facebook;
|
9
|
+
|
10
|
+
enum JsiWrapperValueType
|
11
|
+
{
|
12
|
+
NonInitialized,
|
13
|
+
Undefined,
|
14
|
+
Null,
|
15
|
+
Bool,
|
16
|
+
Number,
|
17
|
+
JsiValue
|
18
|
+
};
|
19
|
+
|
20
|
+
/**
|
21
|
+
Implements a simple wrapper class for JSI primitives like numbers and boolean values. Objects,
|
22
|
+
strings and arrays are stored as values inside a property holder. The class also provides a method
|
23
|
+
for comparing values that will compare numbers, booleans and strings.
|
24
|
+
*/
|
25
|
+
class JsiSimpleValueWrapper
|
26
|
+
{
|
27
|
+
public:
|
28
|
+
JsiSimpleValueWrapper(jsi::Runtime& runtime) :
|
29
|
+
_type(JsiWrapperValueType::NonInitialized),
|
30
|
+
_propNameId(jsi::PropNameID::forUtf8(runtime, "value"))
|
31
|
+
{}
|
32
|
+
|
33
|
+
jsi::Value getCurrent(jsi::Runtime &runtime)
|
34
|
+
{
|
35
|
+
switch (_type)
|
36
|
+
{
|
37
|
+
case JsiWrapperValueType::NonInitialized:
|
38
|
+
return nullptr;
|
39
|
+
case JsiWrapperValueType::Undefined:
|
40
|
+
return jsi::Value::undefined();
|
41
|
+
case JsiWrapperValueType::Null:
|
42
|
+
return jsi::Value::null();
|
43
|
+
case JsiWrapperValueType::Bool:
|
44
|
+
return _boolValue;
|
45
|
+
case JsiWrapperValueType::Number:
|
46
|
+
return _numberValue;
|
47
|
+
case JsiWrapperValueType::JsiValue:
|
48
|
+
if (_valueHolder == nullptr) {
|
49
|
+
return jsi::Value::undefined();
|
50
|
+
}
|
51
|
+
return _valueHolder->getProperty(runtime, _propNameId);
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
void setCurrent(jsi::Runtime &runtime, const jsi::Value &value)
|
56
|
+
{
|
57
|
+
if(value.isNumber()) {
|
58
|
+
_type = JsiWrapperValueType::Number;
|
59
|
+
_numberValue = value.asNumber();
|
60
|
+
} else if(value.isBool()) {
|
61
|
+
_type = JsiWrapperValueType::Bool;
|
62
|
+
_boolValue = value.getBool();
|
63
|
+
} else if(value.isUndefined()) {
|
64
|
+
_type = JsiWrapperValueType::Undefined;
|
65
|
+
} else if(value.isNull()) {
|
66
|
+
_type = JsiWrapperValueType::Null;
|
67
|
+
} else {
|
68
|
+
_type = JsiWrapperValueType::JsiValue;
|
69
|
+
// Save as javascript object - we don't want to have to copy strings, objects and values
|
70
|
+
if(_valueHolder == nullptr) {
|
71
|
+
_valueHolder = std::make_shared<jsi::Object>(runtime);
|
72
|
+
}
|
73
|
+
_valueHolder->setProperty(runtime, _propNameId, value);
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
bool equals(jsi::Runtime& runtime, const jsi::Value &value) {
|
78
|
+
if (_type == JsiWrapperValueType::NonInitialized) {
|
79
|
+
return false;
|
80
|
+
}
|
81
|
+
if(value.isNumber() && _type == JsiWrapperValueType::Number) {
|
82
|
+
return _numberValue == value.asNumber();
|
83
|
+
} else if(value.isBool() && _type == JsiWrapperValueType::Bool) {
|
84
|
+
return _boolValue == value.getBool();
|
85
|
+
} else if(value.isUndefined()) {
|
86
|
+
return _type == JsiWrapperValueType::Undefined;
|
87
|
+
} else if(value.isNull()) {
|
88
|
+
return _type == JsiWrapperValueType::Null;
|
89
|
+
} else if(value.isString()) {
|
90
|
+
auto current = getCurrent(runtime);
|
91
|
+
if (current.isString()) {
|
92
|
+
return jsi::String::strictEquals(runtime, value.asString(runtime), current.asString(runtime));
|
93
|
+
}
|
94
|
+
return false;
|
95
|
+
}
|
96
|
+
return false;
|
97
|
+
}
|
98
|
+
|
99
|
+
private:
|
100
|
+
jsi::PropNameID _propNameId;
|
101
|
+
std::shared_ptr<jsi::Object> _valueHolder;
|
102
|
+
|
103
|
+
bool _boolValue;
|
104
|
+
double _numberValue;
|
105
|
+
|
106
|
+
JsiWrapperValueType _type;
|
107
|
+
};
|
108
|
+
}
|
@@ -11,6 +11,7 @@
|
|
11
11
|
|
12
12
|
#include <JsiSkHostObjects.h>
|
13
13
|
#include <RNSkPlatformContext.h>
|
14
|
+
#include <JsiSimpleValueWrapper.h>
|
14
15
|
|
15
16
|
namespace RNSkia
|
16
17
|
{
|
@@ -26,7 +27,8 @@ class RNSkReadonlyValue : public JsiSkHostObject,
|
|
26
27
|
public:
|
27
28
|
RNSkReadonlyValue(std::shared_ptr<RNSkPlatformContext> platformContext)
|
28
29
|
: JsiSkHostObject(platformContext),
|
29
|
-
|
30
|
+
_valueHolder(std::make_unique<JsiSimpleValueWrapper>(*platformContext->getJsRuntime()))
|
31
|
+
{ }
|
30
32
|
|
31
33
|
virtual ~RNSkReadonlyValue() { }
|
32
34
|
|
@@ -86,23 +88,22 @@ public:
|
|
86
88
|
}
|
87
89
|
|
88
90
|
/**
|
89
|
-
Updates the underlying value and notifies all listeners about the change
|
91
|
+
Updates the underlying value and notifies all listeners about the change.
|
92
|
+
Listeners are only notified if the value was actually changed for numeric, boolean and string
|
93
|
+
values. For all other values listeners are notified without comparison.
|
90
94
|
@param runtime Current JS Runtime
|
91
95
|
@param value Next value
|
92
96
|
*/
|
93
97
|
virtual void update(jsi::Runtime &runtime, const jsi::Value &value) {
|
94
|
-
|
95
|
-
|
98
|
+
auto equal = _valueHolder->equals(runtime, value);
|
99
|
+
_valueHolder->setCurrent(runtime, value);
|
100
|
+
if(!equal) {
|
101
|
+
notifyListeners(runtime);
|
96
102
|
}
|
97
|
-
_valueHolder->setProperty(runtime, _propNameId, value);
|
98
|
-
notifyListeners(runtime);
|
99
103
|
}
|
100
104
|
|
101
105
|
jsi::Value getCurrent(jsi::Runtime &runtime) {
|
102
|
-
|
103
|
-
return jsi::Value::undefined();
|
104
|
-
}
|
105
|
-
return _valueHolder->getProperty(runtime, _propNameId);
|
106
|
+
return _valueHolder->getCurrent(runtime);
|
106
107
|
}
|
107
108
|
|
108
109
|
protected:
|
@@ -132,8 +133,8 @@ protected:
|
|
132
133
|
}
|
133
134
|
|
134
135
|
private:
|
135
|
-
|
136
|
-
|
136
|
+
std::unique_ptr<JsiSimpleValueWrapper> _valueHolder;
|
137
|
+
|
137
138
|
long _listenerId = 0;
|
138
139
|
std::unordered_map<long, std::function<void(jsi::Runtime&)>> _listeners;
|
139
140
|
std::mutex _mutex;
|
@@ -1,5 +1,7 @@
|
|
1
1
|
#pragma once
|
2
2
|
|
3
|
+
#import "RCTBridge.h"
|
4
|
+
|
3
5
|
#include <functional>
|
4
6
|
#include <memory>
|
5
7
|
#include <string>
|
@@ -26,13 +28,27 @@ namespace RNSkia {
|
|
26
28
|
|
27
29
|
using namespace facebook;
|
28
30
|
|
31
|
+
static void handleNotification(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo);
|
32
|
+
|
29
33
|
class PlatformContext : public RNSkPlatformContext {
|
30
34
|
public:
|
31
35
|
PlatformContext(jsi::Runtime *runtime,
|
32
36
|
std::shared_ptr<react::CallInvoker> callInvoker)
|
33
|
-
: RNSkPlatformContext(runtime, callInvoker, [[UIScreen mainScreen] scale]) {
|
34
|
-
|
35
|
-
|
37
|
+
: RNSkPlatformContext(runtime, callInvoker, [[UIScreen mainScreen] scale]) {
|
38
|
+
// We need to make sure we invalidate when modules are freed
|
39
|
+
CFNotificationCenterAddObserver(
|
40
|
+
CFNotificationCenterGetLocalCenter(),
|
41
|
+
this,
|
42
|
+
&handleNotification,
|
43
|
+
(__bridge CFStringRef)RCTBridgeWillInvalidateModulesNotification,
|
44
|
+
NULL,
|
45
|
+
CFNotificationSuspensionBehaviorDeliverImmediately
|
46
|
+
);
|
47
|
+
}
|
48
|
+
|
49
|
+
~PlatformContext() {
|
50
|
+
CFNotificationCenterRemoveEveryObserver(CFNotificationCenterGetLocalCenter(), this);
|
51
|
+
}
|
36
52
|
|
37
53
|
void startDrawLoop() override;
|
38
54
|
void stopDrawLoop() override;
|
@@ -42,9 +58,19 @@ public:
|
|
42
58
|
const std::function<void(std::unique_ptr<SkStreamAsset>)> &op) override;
|
43
59
|
|
44
60
|
void raiseError(const std::exception &err) override;
|
45
|
-
|
61
|
+
|
62
|
+
void willInvalidateModules() {
|
63
|
+
// We need to do some house-cleaning here!
|
64
|
+
invalidate();
|
65
|
+
}
|
66
|
+
|
46
67
|
private:
|
47
68
|
DisplayLink *_displayLink;
|
48
69
|
};
|
49
70
|
|
71
|
+
static void handleNotification(CFNotificationCenterRef center, void *observer, CFStringRef name,
|
72
|
+
const void *object, CFDictionaryRef userInfo) {
|
73
|
+
(static_cast<PlatformContext*>(observer))->willInvalidateModules();
|
74
|
+
}
|
75
|
+
|
50
76
|
} // namespace RNSkia
|
@@ -28,20 +28,19 @@
|
|
28
28
|
_drawingMode = RNSkia::RNSkDrawingMode::Default;
|
29
29
|
|
30
30
|
// Listen to notifications about module invalidation
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
queue:nil
|
36
|
-
usingBlock:^(NSNotification *notification){
|
37
|
-
// Remove local variables when the bridge is teared down.
|
38
|
-
weakSelf->_impl = nullptr;
|
39
|
-
weakSelf->_manager = nullptr;
|
40
|
-
}];
|
31
|
+
[[NSNotificationCenter defaultCenter] addObserver:self
|
32
|
+
selector:@selector(willInvalidateModules)
|
33
|
+
name:RCTBridgeWillInvalidateModulesNotification
|
34
|
+
object:nil];
|
41
35
|
}
|
42
36
|
return self;
|
43
37
|
}
|
44
38
|
|
39
|
+
- (void) willInvalidateModules {
|
40
|
+
_impl = nullptr;
|
41
|
+
_manager = nullptr;
|
42
|
+
}
|
43
|
+
|
45
44
|
#pragma mark Lifecycle
|
46
45
|
|
47
46
|
- (void) willMoveToSuperview:(UIView *)newWindow {
|
@@ -71,8 +70,6 @@
|
|
71
70
|
}
|
72
71
|
|
73
72
|
- (void) dealloc {
|
74
|
-
auto nc = [NSNotificationCenter defaultCenter];
|
75
|
-
[nc removeObserver:self name:RCTBridgeWillInvalidateModulesNotification object:nil];
|
76
73
|
if(_manager != nullptr && _nativeId != 0) {
|
77
74
|
_manager->unregisterSkiaDrawView(_nativeId);
|
78
75
|
}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["runDecay.ts"],"names":["runDecay","value","config","resolvedConfig","deceleration","velocityFactor","velocity","from","current","updateFunction","t","state","finished","lastTimestamp","startTimestamp","initialVelocity","animation","ValueApi","createAnimation"],"mappings":";;;;;;;AAAA;;AAGA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,QAAQ,GAAG,CAACC,KAAD,EAA2BC,MAA3B,KAAoD;AAC1E,QAAMC,cAAkC,GAAG;AACzCC,IAAAA,YAAY,EAAE,KAD2B;AAEzCC,IAAAA,cAAc,EAAE,CAFyB;AAGzCC,IAAAA,QAAQ,EAAE,CAH+B;AAIzCC,IAAAA,IAAI,EAAEN,KAAK,CAACO,OAJ6B;AAKzC,OAAGN;AALsC,GAA3C;;AAOA,QAAMO,cAAc,GAAG,CAACC,CAAD,EAAYC,KAAZ,KAA8C;AACnE,QAAI,CAACA,KAAL,EAAY;AACV,aAAO;AACLH,QAAAA,OAAO,EAAEL,cAAc,CAACI,IADnB;AAELK,QAAAA,QAAQ,EAAE,KAFL;AAGLC,QAAAA,aAAa,EAAEH,CAHV;AAILI,QAAAA,cAAc,EAAEJ,CAJX;AAKLK,QAAAA,eAAe,EAAEZ,cAAc,CAACG,QAL3B;AAMLA,QAAAA,QAAQ,EAAEH,cAAc,CAACG;AANpB,OAAP;AAQD;;AACD,WAAO,kBAAMI,CAAN,EAASC,KAAT,EAAgBR,cAAhB,CAAP;AACD,GAZD;;AAaAF,EAAAA,KAAK,CAACe,SAAN,GAAkBC,cAASC,eAAT,CAAyBT,cAAzB,CAAlB;AACA,SAAOR,KAAK,CAACe,SAAb;AACD,CAvBM","sourcesContent":["import { ValueApi } from \"../../values/api\";\nimport type { SkiaValue } from \"../../values/types\";\n\nimport { decay } from \"./decay\";\nimport type { DecayConfig, DefaultDecayConfig, DecayState } from \"./types\";\n\n/**\n * Runs a decay animation from the current value to zero with the given decay\n * configuration.\n * @param value value to animate\n * @param config Configuration or default configuration\n * @returns Animation\n */\nexport const runDecay = (value: SkiaValue<number>, config?: DecayConfig) => {\n const resolvedConfig: DefaultDecayConfig = {\n deceleration: 0.998,\n velocityFactor: 1,\n velocity: 0,\n from: value.current,\n ...config,\n };\n const updateFunction = (t: number, state: DecayState | undefined) => {\n if (!state) {\n return {\n current: resolvedConfig.from,\n finished: false,\n lastTimestamp: t,\n startTimestamp: t,\n initialVelocity: resolvedConfig.velocity,\n velocity: resolvedConfig.velocity,\n };\n }\n return decay(t, state, resolvedConfig);\n };\n value.animation = ValueApi.createAnimation(updateFunction);\n return value.animation;\n};\n"]}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,141 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.Extrapolate = void 0;
|
7
|
+
exports.interpolate = interpolate;
|
8
|
+
|
9
|
+
/* eslint-disable max-len */
|
10
|
+
let Extrapolate;
|
11
|
+
exports.Extrapolate = Extrapolate;
|
12
|
+
|
13
|
+
(function (Extrapolate) {
|
14
|
+
Extrapolate["IDENTITY"] = "identity";
|
15
|
+
Extrapolate["CLAMP"] = "clamp";
|
16
|
+
Extrapolate["EXTEND"] = "extend";
|
17
|
+
})(Extrapolate || (exports.Extrapolate = Extrapolate = {}));
|
18
|
+
|
19
|
+
function getVal(type, coef, val, leftEdgeOutput, rightEdgeOutput, x) {
|
20
|
+
switch (type) {
|
21
|
+
case Extrapolate.IDENTITY:
|
22
|
+
return x;
|
23
|
+
|
24
|
+
case Extrapolate.CLAMP:
|
25
|
+
if (coef * val < coef * leftEdgeOutput) {
|
26
|
+
return leftEdgeOutput;
|
27
|
+
}
|
28
|
+
|
29
|
+
return rightEdgeOutput;
|
30
|
+
|
31
|
+
case Extrapolate.EXTEND:
|
32
|
+
default:
|
33
|
+
return val;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
function isExtrapolate(value) {
|
38
|
+
return value === Extrapolate.EXTEND || value === Extrapolate.CLAMP || value === Extrapolate.IDENTITY;
|
39
|
+
} // validates extrapolations type
|
40
|
+
// if type is correct, converts it to ExtrapolationConfig
|
41
|
+
|
42
|
+
|
43
|
+
function validateType(type) {
|
44
|
+
// initialize extrapolationConfig with default extrapolation
|
45
|
+
const extrapolationConfig = {
|
46
|
+
extrapolateLeft: Extrapolate.EXTEND,
|
47
|
+
extrapolateRight: Extrapolate.EXTEND
|
48
|
+
};
|
49
|
+
|
50
|
+
if (!type) {
|
51
|
+
return extrapolationConfig;
|
52
|
+
}
|
53
|
+
|
54
|
+
if (typeof type === "string") {
|
55
|
+
if (!isExtrapolate(type)) {
|
56
|
+
throw new Error(`No supported value for "interpolate" \nSupported values: ["extend", "clamp", "identity", Extrapolatation.CLAMP, Extrapolatation.EXTEND, Extrapolatation.IDENTITY]\n Valid example:
|
57
|
+
interpolate(value, [inputRange], [outputRange], "clamp")`);
|
58
|
+
}
|
59
|
+
|
60
|
+
extrapolationConfig.extrapolateLeft = type;
|
61
|
+
extrapolationConfig.extrapolateRight = type;
|
62
|
+
return extrapolationConfig;
|
63
|
+
} // otherwise type is extrapolation config object
|
64
|
+
|
65
|
+
|
66
|
+
if (type.extrapolateLeft && !isExtrapolate(type.extrapolateLeft) || type.extrapolateRight && !isExtrapolate(type.extrapolateRight)) {
|
67
|
+
throw new Error(`No supported value for "interpolate" \nSupported values: ["extend", "clamp", "identity", Extrapolatation.CLAMP, Extrapolatation.EXTEND, Extrapolatation.IDENTITY]\n Valid example:
|
68
|
+
interpolate(value, [inputRange], [outputRange], {
|
69
|
+
extrapolateLeft: Extrapolation.CLAMP,
|
70
|
+
extrapolateRight: Extrapolation.IDENTITY
|
71
|
+
}})`);
|
72
|
+
}
|
73
|
+
|
74
|
+
Object.assign(extrapolationConfig, type);
|
75
|
+
return extrapolationConfig;
|
76
|
+
}
|
77
|
+
|
78
|
+
function internalInterpolate(x, narrowedInput, extrapolationConfig) {
|
79
|
+
const {
|
80
|
+
leftEdgeInput,
|
81
|
+
rightEdgeInput,
|
82
|
+
leftEdgeOutput,
|
83
|
+
rightEdgeOutput
|
84
|
+
} = narrowedInput;
|
85
|
+
|
86
|
+
if (rightEdgeInput - leftEdgeInput === 0) {
|
87
|
+
return leftEdgeOutput;
|
88
|
+
}
|
89
|
+
|
90
|
+
const progress = (x - leftEdgeInput) / (rightEdgeInput - leftEdgeInput);
|
91
|
+
const val = leftEdgeOutput + progress * (rightEdgeOutput - leftEdgeOutput);
|
92
|
+
const coef = rightEdgeOutput >= leftEdgeOutput ? 1 : -1;
|
93
|
+
|
94
|
+
if (coef * val < coef * leftEdgeOutput) {
|
95
|
+
return getVal(extrapolationConfig.extrapolateLeft, coef, val, leftEdgeOutput, rightEdgeOutput, x);
|
96
|
+
} else if (coef * val > coef * rightEdgeOutput) {
|
97
|
+
return getVal(extrapolationConfig.extrapolateRight, coef, val, leftEdgeOutput, rightEdgeOutput, x);
|
98
|
+
}
|
99
|
+
|
100
|
+
return val;
|
101
|
+
} // e.g. function interpolate(x, input, output, type = Extrapolatation.CLAMP)
|
102
|
+
|
103
|
+
|
104
|
+
function interpolate(x, input, output, type) {
|
105
|
+
if (input.length < 2 || output.length < 2) {
|
106
|
+
throw Error("Interpolation input and output should contain at least two values.");
|
107
|
+
}
|
108
|
+
|
109
|
+
const extrapolationConfig = validateType(type);
|
110
|
+
const {
|
111
|
+
length
|
112
|
+
} = input;
|
113
|
+
const narrowedInput = {
|
114
|
+
leftEdgeInput: input[0],
|
115
|
+
rightEdgeInput: input[1],
|
116
|
+
leftEdgeOutput: output[0],
|
117
|
+
rightEdgeOutput: output[1]
|
118
|
+
};
|
119
|
+
|
120
|
+
if (length > 2) {
|
121
|
+
if (x > input[length - 1]) {
|
122
|
+
narrowedInput.leftEdgeInput = input[length - 2];
|
123
|
+
narrowedInput.rightEdgeInput = input[length - 1];
|
124
|
+
narrowedInput.leftEdgeOutput = output[length - 2];
|
125
|
+
narrowedInput.rightEdgeOutput = output[length - 1];
|
126
|
+
} else {
|
127
|
+
for (let i = 1; i < length; ++i) {
|
128
|
+
if (x <= input[i]) {
|
129
|
+
narrowedInput.leftEdgeInput = input[i - 1];
|
130
|
+
narrowedInput.rightEdgeInput = input[i];
|
131
|
+
narrowedInput.leftEdgeOutput = output[i - 1];
|
132
|
+
narrowedInput.rightEdgeOutput = output[i];
|
133
|
+
break;
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
139
|
+
return internalInterpolate(x, narrowedInput, extrapolationConfig);
|
140
|
+
}
|
141
|
+
//# sourceMappingURL=interpolate.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["interpolate.ts"],"names":["Extrapolate","getVal","type","coef","val","leftEdgeOutput","rightEdgeOutput","x","IDENTITY","CLAMP","EXTEND","isExtrapolate","value","validateType","extrapolationConfig","extrapolateLeft","extrapolateRight","Error","Object","assign","internalInterpolate","narrowedInput","leftEdgeInput","rightEdgeInput","progress","interpolate","input","output","length","i"],"mappings":"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","sourcesContent":["/* eslint-disable max-len */\nexport enum Extrapolate {\n IDENTITY = \"identity\",\n CLAMP = \"clamp\",\n EXTEND = \"extend\",\n}\n\ninterface InterpolationNarrowedInput {\n leftEdgeInput: number;\n rightEdgeInput: number;\n leftEdgeOutput: number;\n rightEdgeOutput: number;\n}\n\nexport interface ExtrapolationConfig {\n extrapolateLeft?: Extrapolate | string;\n extrapolateRight?: Extrapolate | string;\n}\n\ninterface RequiredExtrapolationConfig {\n extrapolateLeft: Extrapolate;\n extrapolateRight: Extrapolate;\n}\n\nexport type ExtrapolationType =\n | ExtrapolationConfig\n | Extrapolate\n | string\n | undefined;\n\nfunction getVal(\n type: Extrapolate,\n coef: number,\n val: number,\n leftEdgeOutput: number,\n rightEdgeOutput: number,\n x: number\n): number {\n switch (type) {\n case Extrapolate.IDENTITY:\n return x;\n case Extrapolate.CLAMP:\n if (coef * val < coef * leftEdgeOutput) {\n return leftEdgeOutput;\n }\n return rightEdgeOutput;\n case Extrapolate.EXTEND:\n default:\n return val;\n }\n}\n\nfunction isExtrapolate(value: string): value is Extrapolate {\n return (\n value === Extrapolate.EXTEND ||\n value === Extrapolate.CLAMP ||\n value === Extrapolate.IDENTITY\n );\n}\n\n// validates extrapolations type\n// if type is correct, converts it to ExtrapolationConfig\nfunction validateType(type: ExtrapolationType): RequiredExtrapolationConfig {\n // initialize extrapolationConfig with default extrapolation\n const extrapolationConfig: RequiredExtrapolationConfig = {\n extrapolateLeft: Extrapolate.EXTEND,\n extrapolateRight: Extrapolate.EXTEND,\n };\n\n if (!type) {\n return extrapolationConfig;\n }\n\n if (typeof type === \"string\") {\n if (!isExtrapolate(type)) {\n throw new Error(\n `No supported value for \"interpolate\" \\nSupported values: [\"extend\", \"clamp\", \"identity\", Extrapolatation.CLAMP, Extrapolatation.EXTEND, Extrapolatation.IDENTITY]\\n Valid example:\n interpolate(value, [inputRange], [outputRange], \"clamp\")`\n );\n }\n extrapolationConfig.extrapolateLeft = type;\n extrapolationConfig.extrapolateRight = type;\n return extrapolationConfig;\n }\n\n // otherwise type is extrapolation config object\n if (\n (type.extrapolateLeft && !isExtrapolate(type.extrapolateLeft)) ||\n (type.extrapolateRight && !isExtrapolate(type.extrapolateRight))\n ) {\n throw new Error(\n `No supported value for \"interpolate\" \\nSupported values: [\"extend\", \"clamp\", \"identity\", Extrapolatation.CLAMP, Extrapolatation.EXTEND, Extrapolatation.IDENTITY]\\n Valid example:\n interpolate(value, [inputRange], [outputRange], {\n extrapolateLeft: Extrapolation.CLAMP,\n extrapolateRight: Extrapolation.IDENTITY\n }})`\n );\n }\n\n Object.assign(extrapolationConfig, type);\n return extrapolationConfig;\n}\n\nfunction internalInterpolate(\n x: number,\n narrowedInput: InterpolationNarrowedInput,\n extrapolationConfig: RequiredExtrapolationConfig\n) {\n const { leftEdgeInput, rightEdgeInput, leftEdgeOutput, rightEdgeOutput } =\n narrowedInput;\n if (rightEdgeInput - leftEdgeInput === 0) {\n return leftEdgeOutput;\n }\n const progress = (x - leftEdgeInput) / (rightEdgeInput - leftEdgeInput);\n const val = leftEdgeOutput + progress * (rightEdgeOutput - leftEdgeOutput);\n const coef = rightEdgeOutput >= leftEdgeOutput ? 1 : -1;\n\n if (coef * val < coef * leftEdgeOutput) {\n return getVal(\n extrapolationConfig.extrapolateLeft,\n coef,\n val,\n leftEdgeOutput,\n rightEdgeOutput,\n x\n );\n } else if (coef * val > coef * rightEdgeOutput) {\n return getVal(\n extrapolationConfig.extrapolateRight,\n coef,\n val,\n leftEdgeOutput,\n rightEdgeOutput,\n x\n );\n }\n\n return val;\n}\n\n// e.g. function interpolate(x, input, output, type = Extrapolatation.CLAMP)\nexport function interpolate(\n x: number,\n input: readonly number[],\n output: readonly number[],\n type?: ExtrapolationType\n): number {\n if (input.length < 2 || output.length < 2) {\n throw Error(\n \"Interpolation input and output should contain at least two values.\"\n );\n }\n\n const extrapolationConfig = validateType(type);\n const { length } = input;\n const narrowedInput: InterpolationNarrowedInput = {\n leftEdgeInput: input[0],\n rightEdgeInput: input[1],\n leftEdgeOutput: output[0],\n rightEdgeOutput: output[1],\n };\n if (length > 2) {\n if (x > input[length - 1]) {\n narrowedInput.leftEdgeInput = input[length - 2];\n narrowedInput.rightEdgeInput = input[length - 1];\n narrowedInput.leftEdgeOutput = output[length - 2];\n narrowedInput.rightEdgeOutput = output[length - 1];\n } else {\n for (let i = 1; i < length; ++i) {\n if (x <= input[i]) {\n narrowedInput.leftEdgeInput = input[i - 1];\n narrowedInput.rightEdgeInput = input[i];\n narrowedInput.leftEdgeOutput = output[i - 1];\n narrowedInput.rightEdgeOutput = output[i];\n break;\n }\n }\n }\n }\n\n return internalInterpolate(x, narrowedInput, extrapolationConfig);\n}\n"]}
|