@shopify/react-native-skia 0.1.122 → 0.1.125
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +6 -1
- package/android/build.gradle +1 -1
- package/android/cpp/jni/JniSkiaDrawView.cpp +14 -71
- package/android/cpp/jni/JniSkiaManager.cpp +1 -1
- package/android/cpp/jni/include/JniSkiaDrawView.h +18 -22
- package/android/cpp/jni/include/JniSkiaManager.h +4 -4
- package/android/cpp/rnskia-android/RNSkDrawViewImpl.cpp +68 -0
- package/android/cpp/rnskia-android/RNSkDrawViewImpl.h +48 -0
- package/android/cpp/{jni/include/JniPlatformContextWrapper.h → rnskia-android/RNSkPlatformContextImpl.h} +4 -4
- package/android/cpp/{jni → rnskia-android}/SkiaOpenGLRenderer.cpp +39 -54
- package/android/cpp/{jni/include → rnskia-android}/SkiaOpenGLRenderer.h +2 -31
- package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaViewManager.java +1 -1
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaDrawView.java +21 -28
- 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 +98 -0
- package/cpp/rnskia/RNSkAnimation.h +0 -2
- package/cpp/rnskia/RNSkDrawView.cpp +84 -126
- package/cpp/rnskia/RNSkDrawView.h +7 -37
- package/cpp/rnskia/RNSkJsiViewApi.h +8 -5
- package/cpp/rnskia/RNSkManager.cpp +2 -2
- package/cpp/rnskia/RNSkManager.h +2 -2
- package/cpp/rnskia/RNSkPlatformContext.h +1 -1
- package/cpp/rnskia/RNSkValueApi.h +6 -2
- package/cpp/rnskia/values/RNSkClockValue.h +18 -10
- package/cpp/rnskia/values/RNSkDerivedValue.h +12 -5
- package/cpp/rnskia/values/RNSkReadonlyValue.h +25 -17
- package/cpp/rnskia/values/RNSkValue.h +8 -3
- package/cpp/utils/RNSkTimingInfo.h +13 -1
- package/ios/RNSkia-iOS/PlatformContext.h +30 -4
- package/ios/RNSkia-iOS/RNSkDrawViewImpl.h +8 -10
- package/ios/RNSkia-iOS/RNSkDrawViewImpl.mm +25 -10
- package/ios/RNSkia-iOS/SkiaDrawView.mm +22 -20
- 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 +3 -3
- package/lib/commonjs/animation/timing/functions/getResolvedParams.js.map +1 -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/Canvas.js +17 -8
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/components/Paint.js +1 -1
- package/lib/commonjs/renderer/components/Paint.js.map +1 -1
- package/lib/commonjs/renderer/components/colorFilters/BlendColor.js.map +1 -1
- package/lib/commonjs/renderer/components/colorFilters/Lerp.js +1 -1
- package/lib/commonjs/renderer/components/colorFilters/Lerp.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 +2 -2
- package/lib/commonjs/renderer/components/shaders/Shader.js.map +1 -1
- package/lib/commonjs/renderer/components/shapes/Path.js +9 -1
- package/lib/commonjs/renderer/components/shapes/Path.js.map +1 -1
- package/lib/commonjs/renderer/processors/Circles.js +3 -2
- package/lib/commonjs/renderer/processors/Circles.js.map +1 -1
- package/lib/commonjs/renderer/processors/Font.js +1 -1
- package/lib/commonjs/renderer/processors/Font.js.map +1 -1
- package/lib/commonjs/renderer/processors/Paint.js +6 -1
- package/lib/commonjs/renderer/processors/Paint.js.map +1 -1
- package/lib/commonjs/renderer/processors/Rects.js +11 -21
- 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/Paint/Paint.js +13 -1
- package/lib/commonjs/skia/Paint/Paint.js.map +1 -1
- package/lib/commonjs/skia/Paint/usePaint.js +2 -4
- package/lib/commonjs/skia/Paint/usePaint.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 -43
- 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 +3 -3
- package/lib/module/animation/timing/functions/getResolvedParams.js.map +1 -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/Canvas.js +12 -6
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/components/Paint.js +2 -2
- package/lib/module/renderer/components/Paint.js.map +1 -1
- package/lib/module/renderer/components/colorFilters/BlendColor.js.map +1 -1
- package/lib/module/renderer/components/colorFilters/Lerp.js +1 -1
- package/lib/module/renderer/components/colorFilters/Lerp.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 +3 -2
- package/lib/module/renderer/components/shaders/Shader.js.map +1 -1
- package/lib/module/renderer/components/shapes/Path.js +9 -2
- package/lib/module/renderer/components/shapes/Path.js.map +1 -1
- package/lib/module/renderer/processors/Circles.js +3 -2
- package/lib/module/renderer/processors/Circles.js.map +1 -1
- package/lib/module/renderer/processors/Font.js +1 -1
- package/lib/module/renderer/processors/Font.js.map +1 -1
- package/lib/module/renderer/processors/Paint.js +6 -1
- package/lib/module/renderer/processors/Paint.js.map +1 -1
- package/lib/module/renderer/processors/Rects.js +9 -21
- 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/Paint/Paint.js +6 -0
- package/lib/module/skia/Paint/Paint.js.map +1 -1
- package/lib/module/skia/Paint/usePaint.js +2 -3
- package/lib/module/skia/Paint/usePaint.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 -44
- 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 +5 -5
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/renderer/Canvas.d.ts +6 -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/components/shapes/Path.d.ts +3 -1
- package/lib/typescript/src/renderer/processors/Paint.d.ts +2 -1
- 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/Paint/Paint.d.ts +1 -0
- 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 +2 -2
- 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 +5 -5
- package/src/index.ts +1 -0
- package/src/renderer/Canvas.tsx +13 -6
- package/src/renderer/components/Paint.tsx +2 -2
- package/src/renderer/components/colorFilters/BlendColor.tsx +1 -1
- package/src/renderer/components/colorFilters/Lerp.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 +3 -3
- package/src/renderer/components/shapes/Path.tsx +11 -3
- package/src/renderer/processors/Circles.ts +2 -1
- package/src/renderer/processors/Font.ts +1 -1
- package/src/renderer/processors/Paint.ts +5 -0
- package/src/renderer/processors/Rects.ts +9 -14
- 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/Paint/Paint.ts +7 -0
- package/src/skia/Paint/usePaint.ts +2 -4
- 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 -123
- 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/functions/getResolvedParams.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/functions/getResolvedParams.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
package/src/skia/Skia.ts
CHANGED
@@ -1,130 +1,12 @@
|
|
1
|
-
import { Platform, processColor } from "react-native";
|
2
|
-
|
3
1
|
/*global SkiaApi*/
|
4
|
-
import type { ImageFilterFactory } from "./ImageFilter";
|
5
|
-
import type { PathFactory } from "./Path";
|
6
|
-
import type { ColorFilterFactory } from "./ColorFilter";
|
7
|
-
import type { SkFont } from "./Font";
|
8
|
-
import type { SkTypeface, TypefaceFactory } from "./Typeface";
|
9
|
-
import type { ImageFactory } from "./Image";
|
10
|
-
import type { MaskFilterFactory } from "./MaskFilter";
|
11
|
-
import type { SkPaint } from "./Paint";
|
12
|
-
import type { SkRect } from "./Rect";
|
13
|
-
import type { SkRRect } from "./RRect";
|
14
|
-
import type { RuntimeEffectFactory } from "./RuntimeEffect";
|
15
|
-
import type { ShaderFactory } from "./Shader";
|
16
|
-
import type { SkMatrix } from "./Matrix";
|
17
|
-
import type { PathEffectFactory } from "./PathEffect";
|
18
|
-
import type { SkPoint } from "./Point";
|
19
|
-
import type { SkVertices, VertexMode } from "./Vertices/Vertices";
|
20
|
-
import type { DataFactory } from "./Data";
|
21
|
-
import type { SVGFactory } from "./SVG";
|
22
|
-
import type { TextBlobFactory } from "./TextBlob";
|
23
|
-
import type { FontMgrFactory } from "./FontMgr/FontMgrFactory";
|
24
|
-
import type { SurfaceFactory } from "./Surface";
|
25
2
|
import "./NativeSetup";
|
26
|
-
import type {
|
27
|
-
import type { SkPath } from "./Path/Path";
|
28
|
-
import type { SkContourMeasureIter } from "./ContourMeasure";
|
29
|
-
import type { PictureFactory, SkPictureRecorder } from "./Picture";
|
30
|
-
import type { Color, SkColor } from "./Color";
|
31
|
-
|
32
|
-
/*
|
33
|
-
* Parse CSS colors
|
34
|
-
*/
|
35
|
-
const SkiaColor = (cl: Color) => {
|
36
|
-
if (typeof cl === "number") {
|
37
|
-
return cl;
|
38
|
-
}
|
39
|
-
const color = Skia.parseColorString(cl);
|
40
|
-
if (color !== undefined) {
|
41
|
-
return color;
|
42
|
-
} else {
|
43
|
-
// If the color is not recognized, we fallback to React Native
|
44
|
-
let rnColor = processColor(cl);
|
45
|
-
// 1. Neither Skia or RN could parse the color
|
46
|
-
if (typeof rnColor !== "number") {
|
47
|
-
throw new Error("Skia couldn't parse the following color " + cl);
|
48
|
-
// 2. The color is recognized by RN but not by Skia
|
49
|
-
} else {
|
50
|
-
console.warn(
|
51
|
-
"Skia couldn't parse the following color " +
|
52
|
-
cl +
|
53
|
-
". The color parsing was delegated to React Native. Please file on issue with that color."
|
54
|
-
);
|
55
|
-
// On android we need to move the alpha byte to the start of the structure
|
56
|
-
if (Platform.OS === "android") {
|
57
|
-
rnColor = rnColor >>> 0;
|
58
|
-
const a = (rnColor >> 24) & 0xff;
|
59
|
-
const r = (rnColor >> 16) & 0xff;
|
60
|
-
const g = (rnColor >> 8) & 0xff;
|
61
|
-
const b = rnColor & 0xff;
|
62
|
-
rnColor = ((a << 24) | (r << 16) | (g << 8) | b) >>> 0;
|
63
|
-
}
|
64
|
-
return rnColor;
|
65
|
-
}
|
66
|
-
}
|
67
|
-
};
|
68
|
-
|
69
|
-
/**
|
70
|
-
* Declares the interface for the native Skia API
|
71
|
-
*/
|
72
|
-
export interface Skia {
|
73
|
-
Point: (x: number, y: number) => SkPoint;
|
74
|
-
XYWHRect: (x: number, y: number, width: number, height: number) => SkRect;
|
75
|
-
RRectXY: (rect: SkRect, rx: number, ry: number) => SkRRect;
|
76
|
-
RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;
|
77
|
-
Color: (color: Color) => SkColor;
|
78
|
-
parseColorString: (color: string) => SkColor | undefined;
|
79
|
-
ContourMeasureIter: (
|
80
|
-
path: SkPath,
|
81
|
-
forceClosed: boolean,
|
82
|
-
resScale: number
|
83
|
-
) => SkContourMeasureIter;
|
84
|
-
Paint: () => SkPaint;
|
85
|
-
PictureRecorder: () => SkPictureRecorder;
|
86
|
-
Picture: PictureFactory;
|
87
|
-
Path: PathFactory;
|
88
|
-
Matrix: () => SkMatrix;
|
89
|
-
ColorFilter: ColorFilterFactory;
|
90
|
-
Font: (typeface?: SkTypeface, size?: number) => SkFont;
|
91
|
-
Typeface: TypefaceFactory;
|
92
|
-
MaskFilter: MaskFilterFactory;
|
93
|
-
RuntimeEffect: RuntimeEffectFactory;
|
94
|
-
ImageFilter: ImageFilterFactory;
|
95
|
-
Shader: ShaderFactory;
|
96
|
-
PathEffect: PathEffectFactory;
|
97
|
-
/**
|
98
|
-
* Returns an Vertices based on the given positions and optional parameters.
|
99
|
-
* See SkVertices.h (especially the Builder) for more details.
|
100
|
-
* @param mode
|
101
|
-
* @param positions
|
102
|
-
* @param textureCoordinates
|
103
|
-
* @param colors - either a list of int colors or a flattened color array.
|
104
|
-
* @param indices
|
105
|
-
* @param isVolatile
|
106
|
-
*/
|
107
|
-
MakeVertices(
|
108
|
-
mode: VertexMode,
|
109
|
-
positions: SkPoint[],
|
110
|
-
textureCoordinates?: SkPoint[] | null,
|
111
|
-
colors?: SkColor[],
|
112
|
-
indices?: number[] | null,
|
113
|
-
isVolatile?: boolean
|
114
|
-
): SkVertices;
|
115
|
-
Data: DataFactory;
|
116
|
-
Image: ImageFactory;
|
117
|
-
SVG: SVGFactory;
|
118
|
-
FontMgr: FontMgrFactory;
|
119
|
-
TextBlob: TextBlobFactory;
|
120
|
-
Surface: SurfaceFactory;
|
121
|
-
}
|
3
|
+
import type { SkiaApi as SkSkiaApi } from "./SkiaApi";
|
122
4
|
|
123
5
|
/**
|
124
6
|
* Declares the SkiaApi as an available object in the global scope
|
125
7
|
*/
|
126
8
|
declare global {
|
127
|
-
var SkiaApi:
|
9
|
+
var SkiaApi: SkSkiaApi;
|
128
10
|
}
|
129
11
|
|
130
12
|
/**
|
@@ -148,15 +30,14 @@ export const Skia = {
|
|
148
30
|
Point: SkiaApi.Point,
|
149
31
|
XYWHRect: SkiaApi.XYWHRect,
|
150
32
|
RRectXY: SkiaApi.RRectXY,
|
33
|
+
RuntimeShaderBuilder: SkiaApi.RuntimeShaderBuilder,
|
151
34
|
Paint: SkiaApi.Paint,
|
152
35
|
PictureRecorder: SkiaApi.PictureRecorder,
|
153
36
|
Picture: SkiaApi.Picture,
|
154
37
|
Path: SkiaApi.Path,
|
155
38
|
ColorFilter: SkiaApi.ColorFilter,
|
156
39
|
ContourMeasureIter: SkiaApi.ContourMeasureIter,
|
157
|
-
|
158
|
-
Color: SkiaColor,
|
159
|
-
parseColorString: SkiaApi.parseColorString,
|
40
|
+
Color: SkiaApi.Color,
|
160
41
|
RSXform: SkiaApi.RSXform,
|
161
42
|
// For the following methods the factory symmetry is broken to be comptatible with CanvasKit
|
162
43
|
MakeSurface: SkiaApi.Surface.Make,
|
@@ -0,0 +1,86 @@
|
|
1
|
+
import type { ImageFilterFactory } from "./ImageFilter";
|
2
|
+
import type { PathFactory } from "./Path";
|
3
|
+
import type { ColorFilterFactory } from "./ColorFilter";
|
4
|
+
import type { SkFont } from "./Font";
|
5
|
+
import type { SkTypeface, TypefaceFactory } from "./Typeface";
|
6
|
+
import type { ImageFactory } from "./Image";
|
7
|
+
import type { MaskFilterFactory } from "./MaskFilter";
|
8
|
+
import type { SkPaint } from "./Paint";
|
9
|
+
import type { SkRect } from "./Rect";
|
10
|
+
import type { SkRRect } from "./RRect";
|
11
|
+
import type { RuntimeEffectFactory } from "./RuntimeEffect";
|
12
|
+
import type { ShaderFactory } from "./Shader";
|
13
|
+
import type { SkMatrix } from "./Matrix";
|
14
|
+
import type { PathEffectFactory } from "./PathEffect";
|
15
|
+
import type { SkPoint } from "./Point";
|
16
|
+
import type { SkVertices, VertexMode } from "./Vertices/Vertices";
|
17
|
+
import type { DataFactory } from "./Data";
|
18
|
+
import type { SVGFactory } from "./SVG";
|
19
|
+
import type { TextBlobFactory } from "./TextBlob";
|
20
|
+
import type { FontMgrFactory } from "./FontMgr/FontMgrFactory";
|
21
|
+
import type { SurfaceFactory } from "./Surface";
|
22
|
+
import "./NativeSetup";
|
23
|
+
import type { SkRSXform } from "./RSXform";
|
24
|
+
import type { SkPath } from "./Path/Path";
|
25
|
+
import type { SkContourMeasureIter } from "./ContourMeasure";
|
26
|
+
import type { PictureFactory, SkPictureRecorder } from "./Picture";
|
27
|
+
import type { Color, SkColor } from "./Color";
|
28
|
+
import type {
|
29
|
+
SkRuntimeShaderBuilder,
|
30
|
+
SkRuntimeEffect,
|
31
|
+
} from "./RuntimeEffect/RuntimeEffect";
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Declares the interface for the native Skia API
|
35
|
+
*/
|
36
|
+
export interface SkiaApi {
|
37
|
+
Point: (x: number, y: number) => SkPoint;
|
38
|
+
XYWHRect: (x: number, y: number, width: number, height: number) => SkRect;
|
39
|
+
RuntimeShaderBuilder: (rt: SkRuntimeEffect) => SkRuntimeShaderBuilder;
|
40
|
+
RRectXY: (rect: SkRect, rx: number, ry: number) => SkRRect;
|
41
|
+
RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;
|
42
|
+
Color: (color: Color) => SkColor;
|
43
|
+
parseColorString: (color: string) => SkColor | undefined;
|
44
|
+
ContourMeasureIter: (
|
45
|
+
path: SkPath,
|
46
|
+
forceClosed: boolean,
|
47
|
+
resScale: number
|
48
|
+
) => SkContourMeasureIter;
|
49
|
+
Paint: () => SkPaint;
|
50
|
+
PictureRecorder: () => SkPictureRecorder;
|
51
|
+
Picture: PictureFactory;
|
52
|
+
Path: PathFactory;
|
53
|
+
Matrix: () => SkMatrix;
|
54
|
+
ColorFilter: ColorFilterFactory;
|
55
|
+
Font: (typeface?: SkTypeface, size?: number) => SkFont;
|
56
|
+
Typeface: TypefaceFactory;
|
57
|
+
MaskFilter: MaskFilterFactory;
|
58
|
+
RuntimeEffect: RuntimeEffectFactory;
|
59
|
+
ImageFilter: ImageFilterFactory;
|
60
|
+
Shader: ShaderFactory;
|
61
|
+
PathEffect: PathEffectFactory;
|
62
|
+
/**
|
63
|
+
* Returns an Vertices based on the given positions and optional parameters.
|
64
|
+
* See SkVertices.h (especially the Builder) for more details.
|
65
|
+
* @param mode
|
66
|
+
* @param positions
|
67
|
+
* @param textureCoordinates
|
68
|
+
* @param colors - either a list of int colors or a flattened color array.
|
69
|
+
* @param indices
|
70
|
+
* @param isVolatile
|
71
|
+
*/
|
72
|
+
MakeVertices(
|
73
|
+
mode: VertexMode,
|
74
|
+
positions: SkPoint[],
|
75
|
+
textureCoordinates?: SkPoint[] | null,
|
76
|
+
colors?: SkColor[],
|
77
|
+
indices?: number[] | null,
|
78
|
+
isVolatile?: boolean
|
79
|
+
): SkVertices;
|
80
|
+
Data: DataFactory;
|
81
|
+
Image: ImageFactory;
|
82
|
+
SVG: SVGFactory;
|
83
|
+
FontMgr: FontMgrFactory;
|
84
|
+
TextBlob: TextBlobFactory;
|
85
|
+
Surface: SurfaceFactory;
|
86
|
+
}
|
@@ -3,7 +3,7 @@ import type { SkCanvas } from "../Canvas";
|
|
3
3
|
import type { SkJSIInstance } from "../JsiInstance";
|
4
4
|
import type { SkRect } from "../Rect";
|
5
5
|
|
6
|
-
export interface
|
6
|
+
export interface SkSurface extends SkJSIInstance<"Surface"> {
|
7
7
|
/** Returns Canvas that draws into the surface. Subsequent calls return the
|
8
8
|
same Canvas. Canvas returned is managed and owned by Surface, and is
|
9
9
|
deleted when Surface is deleted.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type {
|
1
|
+
import type { SkSurface } from "./Surface";
|
2
2
|
|
3
3
|
export interface SurfaceFactory {
|
4
4
|
/**
|
@@ -8,5 +8,5 @@ export interface SurfaceFactory {
|
|
8
8
|
* @param width - number of pixels of the width of the drawable area.
|
9
9
|
* @param height - number of pixels of the height of the drawable area.
|
10
10
|
*/
|
11
|
-
Make: (width: number, height: number) =>
|
11
|
+
Make: (width: number, height: number) => SkSurface | null;
|
12
12
|
}
|
package/src/values/api.ts
CHANGED
@@ -1,49 +1,10 @@
|
|
1
|
-
import type {
|
2
|
-
SkiaAnimation,
|
3
|
-
AnimationState,
|
4
|
-
SkiaReadonlyValue,
|
5
|
-
SkiaClockValue,
|
6
|
-
SkiaValue,
|
7
|
-
} from "./types";
|
8
|
-
|
9
|
-
export interface ISkiaValueApi {
|
10
|
-
/**
|
11
|
-
* Creates a new value that holds the initial value and that
|
12
|
-
* can be changed.
|
13
|
-
*/
|
14
|
-
createValue: <T>(initialValue: T) => SkiaValue<T>;
|
15
|
-
/**
|
16
|
-
* Creates a derived value. This is a calculated value that returns the result of
|
17
|
-
* a function that is called with the values of the dependencies.
|
18
|
-
*/
|
19
|
-
createDerivedValue: <R>(
|
20
|
-
cb: () => R,
|
21
|
-
values: Array<SkiaReadonlyValue<unknown>>
|
22
|
-
) => SkiaReadonlyValue<R>;
|
23
|
-
/**
|
24
|
-
* Creates a clock value where the value is the number of milliseconds elapsed
|
25
|
-
* since the clock was created
|
26
|
-
*/
|
27
|
-
createClockValue: () => SkiaClockValue;
|
28
|
-
/**
|
29
|
-
* Creates an animation that is driven from a clock and updated every frame.
|
30
|
-
* @param cb Callback to calculate next value from time.
|
31
|
-
* @returns An animation object that can control a value.
|
32
|
-
*/
|
33
|
-
createAnimation: <S extends AnimationState = AnimationState>(
|
34
|
-
cb: (t: number, state: S | undefined) => S
|
35
|
-
) => SkiaAnimation;
|
36
|
-
}
|
1
|
+
import type { ISkiaValueApi } from "./types";
|
37
2
|
|
38
3
|
declare global {
|
39
4
|
var SkiaValueApi: ISkiaValueApi;
|
40
5
|
}
|
41
6
|
|
42
|
-
|
43
|
-
|
44
|
-
createDerivedValue: global.SkiaValueApi.createDerivedValue,
|
45
|
-
createClockValue: global.SkiaValueApi.createClockValue,
|
46
|
-
createAnimation: global.SkiaValueApi.createAnimation,
|
47
|
-
};
|
7
|
+
const { SkiaValueApi } = global;
|
8
|
+
export const ValueApi = SkiaValueApi;
|
48
9
|
|
49
10
|
export const { createValue, createDerivedValue } = ValueApi;
|
package/src/values/index.ts
CHANGED
package/src/values/types.ts
CHANGED
@@ -30,7 +30,7 @@ export interface SkiaClockValue extends SkiaReadonlyValue<number> {
|
|
30
30
|
stop: () => void;
|
31
31
|
}
|
32
32
|
|
33
|
-
export interface SkiaAnimation {
|
33
|
+
export interface SkiaAnimation extends SkiaClockValue {
|
34
34
|
cancel: () => void;
|
35
35
|
}
|
36
36
|
|
@@ -38,3 +38,32 @@ export interface AnimationState {
|
|
38
38
|
current: number;
|
39
39
|
finished: boolean;
|
40
40
|
}
|
41
|
+
|
42
|
+
export interface ISkiaValueApi {
|
43
|
+
/**
|
44
|
+
* Creates a new value that holds the initial value and that
|
45
|
+
* can be changed.
|
46
|
+
*/
|
47
|
+
createValue: <T>(initialValue: T) => SkiaValue<T>;
|
48
|
+
/**
|
49
|
+
* Creates a derived value. This is a calculated value that returns the result of
|
50
|
+
* a function that is called with the values of the dependencies.
|
51
|
+
*/
|
52
|
+
createDerivedValue: <R>(
|
53
|
+
cb: () => R,
|
54
|
+
values: Array<SkiaReadonlyValue<unknown>>
|
55
|
+
) => SkiaReadonlyValue<R>;
|
56
|
+
/**
|
57
|
+
* Creates a clock value where the value is the number of milliseconds elapsed
|
58
|
+
* since the clock was created
|
59
|
+
*/
|
60
|
+
createClockValue: () => SkiaClockValue;
|
61
|
+
/**
|
62
|
+
* Creates an animation that is driven from a clock and updated every frame.
|
63
|
+
* @param cb Callback to calculate next value from time.
|
64
|
+
* @returns An animation object that can control a value.
|
65
|
+
*/
|
66
|
+
createAnimation: <S extends AnimationState = AnimationState>(
|
67
|
+
cb: (t: number, state: S | undefined) => S
|
68
|
+
) => SkiaAnimation;
|
69
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import type { AnimationState, SkiaAnimation } from "../types";
|
2
|
+
|
3
|
+
import { RNSkClockValue } from "./RNSkClockValue";
|
4
|
+
|
5
|
+
export class RNSkAnimation<S extends AnimationState = AnimationState>
|
6
|
+
extends RNSkClockValue
|
7
|
+
implements SkiaAnimation
|
8
|
+
{
|
9
|
+
constructor(
|
10
|
+
callback: (t: number, state: S | undefined) => S,
|
11
|
+
raf: (callback: (time: number) => void) => number
|
12
|
+
) {
|
13
|
+
super(raf);
|
14
|
+
this._callback = callback;
|
15
|
+
}
|
16
|
+
|
17
|
+
private _callback: (t: number, state: S | undefined) => S;
|
18
|
+
private _animationState: S | undefined = undefined;
|
19
|
+
|
20
|
+
public cancel() {
|
21
|
+
this.stop();
|
22
|
+
}
|
23
|
+
|
24
|
+
protected update(nextValue: number): void {
|
25
|
+
if (this._callback) {
|
26
|
+
this._animationState = this._callback(nextValue, this._animationState);
|
27
|
+
if (this._animationState?.finished) {
|
28
|
+
this.stop();
|
29
|
+
}
|
30
|
+
}
|
31
|
+
super.update(this._animationState?.current ?? nextValue);
|
32
|
+
}
|
33
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import type { SkiaClockValue } from "../types";
|
2
|
+
|
3
|
+
import { RNSkReadonlyValue } from "./RNSkReadonlyValue";
|
4
|
+
|
5
|
+
enum RNSkClockState {
|
6
|
+
NotStarted = 0,
|
7
|
+
Running = 1,
|
8
|
+
Stopped = 2,
|
9
|
+
}
|
10
|
+
|
11
|
+
export class RNSkClockValue
|
12
|
+
extends RNSkReadonlyValue<number>
|
13
|
+
implements SkiaClockValue
|
14
|
+
{
|
15
|
+
constructor(raf: (callback: (time: number) => void) => number) {
|
16
|
+
super(0);
|
17
|
+
this._raf = raf;
|
18
|
+
this.update(0);
|
19
|
+
}
|
20
|
+
|
21
|
+
private _raf: (callback: (time: number) => void) => number;
|
22
|
+
private _start: number | undefined;
|
23
|
+
private _stop: number | undefined;
|
24
|
+
private _state: RNSkClockState = RNSkClockState.NotStarted;
|
25
|
+
|
26
|
+
private notifyUpdate = (_: number) => {
|
27
|
+
if (this._state === RNSkClockState.Running) {
|
28
|
+
const now = Date.now();
|
29
|
+
const deltaFromStart = now - this._start!;
|
30
|
+
this.tick(deltaFromStart);
|
31
|
+
this._raf(this.notifyUpdate);
|
32
|
+
}
|
33
|
+
};
|
34
|
+
|
35
|
+
protected tick(value: number) {
|
36
|
+
this.update(value);
|
37
|
+
}
|
38
|
+
|
39
|
+
public start() {
|
40
|
+
if (this._state === RNSkClockState.NotStarted) {
|
41
|
+
this._start = Date.now();
|
42
|
+
this._stop = this._start;
|
43
|
+
}
|
44
|
+
// Subtract pause time from start
|
45
|
+
const timeSinceStop = Date.now() - this._stop!;
|
46
|
+
this._start! += timeSinceStop;
|
47
|
+
|
48
|
+
this._state = RNSkClockState.Running;
|
49
|
+
this._raf(this.notifyUpdate);
|
50
|
+
}
|
51
|
+
|
52
|
+
public stop() {
|
53
|
+
if (this._state === RNSkClockState.Running) {
|
54
|
+
this._state = RNSkClockState.Stopped;
|
55
|
+
this._stop = Date.now();
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import type { DependencyList } from "react";
|
2
|
+
|
3
|
+
import { RNSkReadonlyValue } from "./RNSkReadonlyValue";
|
4
|
+
|
5
|
+
export class RNSkDerivedValue<T> extends RNSkReadonlyValue<T> {
|
6
|
+
constructor(callback: () => T, dependencies: DependencyList) {
|
7
|
+
// Initialize dependencies - we can't call this yet, since
|
8
|
+
// super if not called and it requires a start value to be set.
|
9
|
+
const unsubscribers: Array<() => void> = [];
|
10
|
+
const notifyUpdateRef: { current: (() => void) | undefined } = {
|
11
|
+
current: undefined,
|
12
|
+
};
|
13
|
+
dependencies.forEach((dep) => {
|
14
|
+
if ("__typename__" in dep && "addListener" in dep) {
|
15
|
+
unsubscribers.push(
|
16
|
+
(dep as RNSkReadonlyValue<unknown>).addListener(() =>
|
17
|
+
notifyUpdateRef.current?.()
|
18
|
+
)
|
19
|
+
);
|
20
|
+
}
|
21
|
+
});
|
22
|
+
super(callback());
|
23
|
+
this._unsubscribers = unsubscribers;
|
24
|
+
notifyUpdateRef.current = this.dependecyUpdated.bind(this);
|
25
|
+
this._callback = callback;
|
26
|
+
}
|
27
|
+
|
28
|
+
private dependecyUpdated() {
|
29
|
+
this.update(this._callback());
|
30
|
+
}
|
31
|
+
|
32
|
+
private _callback: () => T;
|
33
|
+
private _unsubscribers: Array<() => void>;
|
34
|
+
|
35
|
+
public unsubscribe() {
|
36
|
+
this._unsubscribers.forEach((unsubscribe) => unsubscribe());
|
37
|
+
}
|
38
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import type { SkiaReadonlyValue } from "../types";
|
2
|
+
|
3
|
+
export class RNSkReadonlyValue<T> implements SkiaReadonlyValue<T> {
|
4
|
+
constructor(value: T) {
|
5
|
+
this._current = value;
|
6
|
+
}
|
7
|
+
|
8
|
+
private _current: T;
|
9
|
+
private _listeners: Array<(value: T) => void> = [];
|
10
|
+
|
11
|
+
private notifyListeners(): void {
|
12
|
+
this._listeners.forEach((cb) => cb(this._current));
|
13
|
+
}
|
14
|
+
|
15
|
+
protected update(nextValue: T): void {
|
16
|
+
this._current = nextValue;
|
17
|
+
this.notifyListeners();
|
18
|
+
}
|
19
|
+
|
20
|
+
public readonly __typename__ = "RNSkValue";
|
21
|
+
|
22
|
+
public get current(): T {
|
23
|
+
return this._current;
|
24
|
+
}
|
25
|
+
|
26
|
+
public addListener(cb: (value: T) => void) {
|
27
|
+
this._listeners.push(cb);
|
28
|
+
return () => {
|
29
|
+
this._listeners.splice(this._listeners.indexOf(cb), 1);
|
30
|
+
};
|
31
|
+
}
|
32
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import type { SkiaAnimation, SkiaValue } from "../types";
|
2
|
+
|
3
|
+
import { RNSkReadonlyValue } from "./RNSkReadonlyValue";
|
4
|
+
|
5
|
+
export class RNSkValue<T> extends RNSkReadonlyValue<T> implements SkiaValue<T> {
|
6
|
+
constructor(value: T) {
|
7
|
+
super(value);
|
8
|
+
this._unsubscribe = undefined;
|
9
|
+
}
|
10
|
+
|
11
|
+
public set current(value: T) {
|
12
|
+
this.update(value);
|
13
|
+
}
|
14
|
+
|
15
|
+
public get current(): T {
|
16
|
+
return super.current;
|
17
|
+
}
|
18
|
+
|
19
|
+
private _unsubscribe: (() => void) | undefined;
|
20
|
+
|
21
|
+
private unsubscribe() {
|
22
|
+
if (this._unsubscribe) {
|
23
|
+
this._unsubscribe();
|
24
|
+
this._unsubscribe = undefined;
|
25
|
+
}
|
26
|
+
if (this._animation) {
|
27
|
+
this._animation.cancel();
|
28
|
+
this._animation = undefined;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
private subscribe(animation: SkiaAnimation | undefined) {
|
33
|
+
this.unsubscribe();
|
34
|
+
if (animation) {
|
35
|
+
this._animation = animation;
|
36
|
+
this._unsubscribe = animation.addListener(
|
37
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
38
|
+
// @ts-ignore
|
39
|
+
this.animationDidUpdate.bind(this)
|
40
|
+
);
|
41
|
+
this._animation.start();
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
private animationDidUpdate(value: T) {
|
46
|
+
this.update(value);
|
47
|
+
}
|
48
|
+
|
49
|
+
private _animation: SkiaAnimation | undefined;
|
50
|
+
public get animation(): SkiaAnimation | undefined {
|
51
|
+
return this._animation;
|
52
|
+
}
|
53
|
+
|
54
|
+
public set animation(v: SkiaAnimation | undefined) {
|
55
|
+
this.subscribe(v);
|
56
|
+
}
|
57
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { RNSkAnimation } from "../RNSkAnimation";
|
2
|
+
import { RNSkValue } from "../RNSkValue";
|
3
|
+
|
4
|
+
describe("RNSkAnimation", () => {
|
5
|
+
it("should update a value", () => {
|
6
|
+
const valueToTest = new RNSkValue(0);
|
7
|
+
const raf = (cb: (t: number) => void) => {
|
8
|
+
cb(1);
|
9
|
+
return 1;
|
10
|
+
};
|
11
|
+
valueToTest.animation = new RNSkAnimation(
|
12
|
+
() => ({
|
13
|
+
finished: true,
|
14
|
+
current: 1,
|
15
|
+
}),
|
16
|
+
raf
|
17
|
+
);
|
18
|
+
valueToTest.animation.stop();
|
19
|
+
expect(valueToTest.current).toBe(1);
|
20
|
+
});
|
21
|
+
});
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { RNSkDerivedValue } from "../RNSkDerivedValue";
|
2
|
+
import { RNSkValue } from "../RNSkValue";
|
3
|
+
|
4
|
+
describe("RNSkDerivedValue", () => {
|
5
|
+
it("should update when dependency changes", () => {
|
6
|
+
const dependency = new RNSkValue(10);
|
7
|
+
const derived = new RNSkDerivedValue(
|
8
|
+
() => 10 * dependency.current,
|
9
|
+
[dependency]
|
10
|
+
);
|
11
|
+
expect(derived.current).toBe(100);
|
12
|
+
dependency.current = 20;
|
13
|
+
expect(derived.current).toBe(200);
|
14
|
+
});
|
15
|
+
});
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { RNSkReadonlyValue } from "../RNSkReadonlyValue";
|
2
|
+
|
3
|
+
describe("RNSkReadonlyValue", () => {
|
4
|
+
it("should expose __typename as RNSkValue", () => {
|
5
|
+
const valueToTest = new RNSkReadonlyValue(100);
|
6
|
+
expect(valueToTest.__typename__).toEqual("RNSkValue");
|
7
|
+
});
|
8
|
+
});
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { RNSkValue } from "../RNSkValue";
|
2
|
+
|
3
|
+
describe("RNSkValue", () => {
|
4
|
+
it("should notify on change", () => {
|
5
|
+
const valueToTest = new RNSkValue(100);
|
6
|
+
const spy = jest.fn();
|
7
|
+
valueToTest.addListener(spy);
|
8
|
+
valueToTest.current = 200;
|
9
|
+
expect(spy).toHaveBeenCalledWith(200);
|
10
|
+
});
|
11
|
+
});
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import type {
|
2
|
+
ISkiaValueApi,
|
3
|
+
SkiaValue,
|
4
|
+
SkiaReadonlyValue,
|
5
|
+
SkiaClockValue,
|
6
|
+
AnimationState,
|
7
|
+
SkiaAnimation,
|
8
|
+
} from "../types";
|
9
|
+
|
10
|
+
import { RNSkAnimation } from "./RNSkAnimation";
|
11
|
+
import { RNSkClockValue } from "./RNSkClockValue";
|
12
|
+
import { RNSkDerivedValue } from "./RNSkDerivedValue";
|
13
|
+
import { RNSkValue } from "./RNSkValue";
|
14
|
+
|
15
|
+
export const ValueApi: ISkiaValueApi = {
|
16
|
+
createValue: function <T>(initialValue: T): SkiaValue<T> {
|
17
|
+
return new RNSkValue(initialValue);
|
18
|
+
},
|
19
|
+
createDerivedValue: function <R>(
|
20
|
+
cb: () => R,
|
21
|
+
values: SkiaReadonlyValue<unknown>[]
|
22
|
+
): SkiaReadonlyValue<R> {
|
23
|
+
return new RNSkDerivedValue(cb, values);
|
24
|
+
},
|
25
|
+
createClockValue: function (): SkiaClockValue {
|
26
|
+
return new RNSkClockValue(requestAnimationFrame);
|
27
|
+
},
|
28
|
+
createAnimation: function <S extends AnimationState = AnimationState>(
|
29
|
+
cb: (t: number, state: S | undefined) => S
|
30
|
+
): SkiaAnimation {
|
31
|
+
return new RNSkAnimation(cb, requestAnimationFrame);
|
32
|
+
},
|
33
|
+
};
|