@shopify/react-native-skia 0.1.123 → 0.1.126
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +3 -0
- package/android/build.gradle +1 -1
- package/android/cpp/rnskia-android/RNSkDrawViewImpl.cpp +5 -5
- package/android/cpp/rnskia-android/RNSkDrawViewImpl.h +4 -4
- 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/RNSkAnimation.h +0 -2
- package/cpp/rnskia/RNSkDrawView.cpp +10 -13
- package/cpp/rnskia/RNSkDrawView.h +2 -2
- package/cpp/rnskia/RNSkValueApi.h +6 -2
- package/cpp/rnskia/values/RNSkClockValue.h +2 -2
- package/cpp/rnskia/values/RNSkDerivedValue.h +12 -5
- package/cpp/rnskia/values/RNSkReadonlyValue.h +14 -12
- package/cpp/rnskia/values/RNSkValue.h +8 -3
- package/ios/RNSkia-iOS/PlatformContext.h +30 -4
- package/ios/RNSkia-iOS/RNSkDrawViewImpl.h +4 -4
- package/ios/RNSkia-iOS/SkiaDrawView.mm +9 -13
- 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 +14 -5
- package/lib/commonjs/renderer/Canvas.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/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/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/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 +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 +10 -4
- package/lib/module/renderer/Canvas.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/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/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/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 +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/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 +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 +11 -4
- 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/processors/Circles.ts +2 -1
- package/src/renderer/processors/Font.ts +1 -1
- 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/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/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/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
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./api";
|
package/src/views/SkiaView.tsx
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
import React from "react";
|
2
|
-
import type { ViewProps } from "react-native";
|
3
2
|
import { requireNativeComponent } from "react-native";
|
4
3
|
|
5
|
-
import type {
|
4
|
+
import type { SkRect } from "../skia";
|
6
5
|
import type { SkiaReadonlyValue } from "../values";
|
7
6
|
|
8
|
-
import
|
9
|
-
|
10
|
-
RNSkiaDrawCallback,
|
11
|
-
NativeSkiaViewProps,
|
12
|
-
} from "./types";
|
7
|
+
import { SkiaViewApi } from "./api";
|
8
|
+
import type { DrawMode, NativeSkiaViewProps, SkiaViewProps } from "./types";
|
13
9
|
|
14
10
|
let SkiaViewNativeId = 1000;
|
15
11
|
|
@@ -17,48 +13,6 @@ const NativeSkiaView = requireNativeComponent<NativeSkiaViewProps>(
|
|
17
13
|
"ReactNativeSkiaView"
|
18
14
|
);
|
19
15
|
|
20
|
-
declare global {
|
21
|
-
var SkiaViewApi: {
|
22
|
-
invalidateSkiaView: (nativeId: number) => void;
|
23
|
-
makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;
|
24
|
-
setDrawCallback: (
|
25
|
-
nativeId: number,
|
26
|
-
callback: RNSkiaDrawCallback | undefined
|
27
|
-
) => void;
|
28
|
-
setDrawMode: (nativeId: number, mode: DrawMode) => void;
|
29
|
-
registerValuesInView: (
|
30
|
-
nativeId: number,
|
31
|
-
values: SkiaReadonlyValue<unknown>[]
|
32
|
-
) => () => void;
|
33
|
-
};
|
34
|
-
}
|
35
|
-
|
36
|
-
const { SkiaViewApi } = global;
|
37
|
-
|
38
|
-
export interface SkiaViewProps extends ViewProps {
|
39
|
-
/**
|
40
|
-
* Sets the drawing mode for the skia view. There are two drawing
|
41
|
-
* modes, "continuous" and "default", where the continuous mode will
|
42
|
-
* continuously redraw the view, and the default mode will only
|
43
|
-
* redraw when any of the regular react properties are changed like
|
44
|
-
* sizes and margins.
|
45
|
-
*/
|
46
|
-
mode?: DrawMode;
|
47
|
-
/**
|
48
|
-
* When set to true the view will display information about the
|
49
|
-
* average time it takes to render.
|
50
|
-
*/
|
51
|
-
debug?: boolean;
|
52
|
-
/**
|
53
|
-
* Draw callback. Will be called whenever the view is invalidated and
|
54
|
-
* needs to redraw. This is either caused by a change in a react
|
55
|
-
* property, a touch event, or a call to redraw. If the view is in
|
56
|
-
* continuous mode the callback will be called 60 frames per second
|
57
|
-
* by the native view.
|
58
|
-
*/
|
59
|
-
onDraw?: RNSkiaDrawCallback;
|
60
|
-
}
|
61
|
-
|
62
16
|
export class SkiaView extends React.Component<SkiaViewProps> {
|
63
17
|
constructor(props: SkiaViewProps) {
|
64
18
|
super(props);
|
package/src/views/api.ts
ADDED
package/src/views/types.ts
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
import type { ViewProps } from "react-native";
|
2
2
|
|
3
|
+
import type { SkImage, SkRect } from "../skia";
|
3
4
|
import type { SkCanvas } from "../skia/Canvas";
|
5
|
+
import type { SkiaReadonlyValue } from "../values";
|
4
6
|
|
5
7
|
export type DrawMode = "continuous" | "default";
|
6
8
|
|
@@ -54,3 +56,41 @@ export interface ValueListener {
|
|
54
56
|
addListener: (callback: () => void) => number;
|
55
57
|
removeListener: (id: number) => void;
|
56
58
|
}
|
59
|
+
|
60
|
+
export interface ISkiaViewApi {
|
61
|
+
invalidateSkiaView: (nativeId: number) => void;
|
62
|
+
makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;
|
63
|
+
setDrawCallback: (
|
64
|
+
nativeId: number,
|
65
|
+
callback: RNSkiaDrawCallback | undefined
|
66
|
+
) => void;
|
67
|
+
setDrawMode: (nativeId: number, mode: DrawMode) => void;
|
68
|
+
registerValuesInView: (
|
69
|
+
nativeId: number,
|
70
|
+
values: SkiaReadonlyValue<unknown>[]
|
71
|
+
) => () => void;
|
72
|
+
}
|
73
|
+
|
74
|
+
export interface SkiaViewProps extends ViewProps {
|
75
|
+
/**
|
76
|
+
* Sets the drawing mode for the skia view. There are two drawing
|
77
|
+
* modes, "continuous" and "default", where the continuous mode will
|
78
|
+
* continuously redraw the view, and the default mode will only
|
79
|
+
* redraw when any of the regular react properties are changed like
|
80
|
+
* sizes and margins.
|
81
|
+
*/
|
82
|
+
mode?: DrawMode;
|
83
|
+
/**
|
84
|
+
* When set to true the view will display information about the
|
85
|
+
* average time it takes to render.
|
86
|
+
*/
|
87
|
+
debug?: boolean;
|
88
|
+
/**
|
89
|
+
* Draw callback. Will be called whenever the view is invalidated and
|
90
|
+
* needs to redraw. This is either caused by a change in a react
|
91
|
+
* property, a touch event, or a call to redraw. If the view is in
|
92
|
+
* continuous mode the callback will be called 60 frames per second
|
93
|
+
* by the native view.
|
94
|
+
*/
|
95
|
+
onDraw?: RNSkiaDrawCallback;
|
96
|
+
}
|
@@ -1 +0,0 @@
|
|
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 \"../../api\";\nimport type { SkiaValue } from \"../../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"]}
|
@@ -1,139 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.interpolate = interpolate;
|
7
|
-
|
8
|
-
// eslint-disable-next-line max-len
|
9
|
-
// Taken from https://github.com/facebook/react-native/blob/0b9ea60b4fee8cacc36e7160e31b91fc114dbc0d/Libraries/Animated/src/nodes/AnimatedInterpolation.js
|
10
|
-
function interpolateFunction(input, inputRange, outputRange, options) {
|
11
|
-
const {
|
12
|
-
extrapolateLeft,
|
13
|
-
extrapolateRight,
|
14
|
-
easing
|
15
|
-
} = options;
|
16
|
-
let result = input;
|
17
|
-
const [inputMin, inputMax] = inputRange;
|
18
|
-
const [outputMin, outputMax] = outputRange;
|
19
|
-
|
20
|
-
if (result < inputMin) {
|
21
|
-
if (extrapolateLeft === "identity") {
|
22
|
-
return result;
|
23
|
-
}
|
24
|
-
|
25
|
-
if (extrapolateLeft === "clamp") {
|
26
|
-
result = inputMin;
|
27
|
-
} else if (extrapolateLeft === "extend") {// noop
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
if (result > inputMax) {
|
32
|
-
if (extrapolateRight === "identity") {
|
33
|
-
return result;
|
34
|
-
}
|
35
|
-
|
36
|
-
if (extrapolateRight === "clamp") {
|
37
|
-
result = inputMax;
|
38
|
-
} else if (extrapolateRight === "extend") {// noop
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
if (outputMin === outputMax) {
|
43
|
-
return outputMin;
|
44
|
-
} // Input Range
|
45
|
-
|
46
|
-
|
47
|
-
result = (result - inputMin) / (inputMax - inputMin); // Easing
|
48
|
-
|
49
|
-
result = easing(result); // Output Range
|
50
|
-
|
51
|
-
result = result * (outputMax - outputMin) + outputMin;
|
52
|
-
return result;
|
53
|
-
}
|
54
|
-
|
55
|
-
function findRange(input, inputRange) {
|
56
|
-
let i;
|
57
|
-
|
58
|
-
for (i = 1; i < inputRange.length - 1; ++i) {
|
59
|
-
if (inputRange[i] >= input) {
|
60
|
-
break;
|
61
|
-
}
|
62
|
-
}
|
63
|
-
|
64
|
-
return i - 1;
|
65
|
-
}
|
66
|
-
|
67
|
-
function checkValidInputRange(arr) {
|
68
|
-
for (let i = 1; i < arr.length; ++i) {
|
69
|
-
if (!(arr[i] > arr[i - 1])) {
|
70
|
-
throw new Error(`inputRange must be strictly monotonically non-decreasing but got [${arr.join(",")}]`);
|
71
|
-
}
|
72
|
-
}
|
73
|
-
}
|
74
|
-
|
75
|
-
function checkInfiniteRange(name, arr) {
|
76
|
-
if (arr.length < 2) {
|
77
|
-
throw new Error(name + " must have at least 2 elements");
|
78
|
-
}
|
79
|
-
|
80
|
-
for (const index in arr) {
|
81
|
-
if (typeof arr[index] !== "number") {
|
82
|
-
throw new Error(`${name} must contain only numbers`);
|
83
|
-
}
|
84
|
-
|
85
|
-
if (arr[index] === -Infinity || arr[index] === Infinity) {
|
86
|
-
throw new Error(`${name} must contain only finite numbers, but got [${arr.join(",")}]`);
|
87
|
-
}
|
88
|
-
}
|
89
|
-
}
|
90
|
-
|
91
|
-
function interpolate(input, inputRange, outputRange, options) {
|
92
|
-
var _options$easing;
|
93
|
-
|
94
|
-
if (typeof input === "undefined") {
|
95
|
-
throw new Error("input can not be undefined");
|
96
|
-
}
|
97
|
-
|
98
|
-
if (typeof inputRange === "undefined") {
|
99
|
-
throw new Error("inputRange can not be undefined");
|
100
|
-
}
|
101
|
-
|
102
|
-
if (typeof outputRange === "undefined") {
|
103
|
-
throw new Error("outputRange can not be undefined");
|
104
|
-
}
|
105
|
-
|
106
|
-
if (inputRange.length !== outputRange.length) {
|
107
|
-
throw new Error("inputRange (" + inputRange.length + ") and outputRange (" + outputRange.length + ") must have the same length");
|
108
|
-
}
|
109
|
-
|
110
|
-
checkInfiniteRange("inputRange", inputRange);
|
111
|
-
checkInfiniteRange("outputRange", outputRange);
|
112
|
-
checkValidInputRange(inputRange);
|
113
|
-
const easing = (_options$easing = options === null || options === void 0 ? void 0 : options.easing) !== null && _options$easing !== void 0 ? _options$easing : num => num;
|
114
|
-
let extrapolateLeft = "extend";
|
115
|
-
|
116
|
-
if ((options === null || options === void 0 ? void 0 : options.extrapolateLeft) !== undefined) {
|
117
|
-
// eslint-disable-next-line prefer-destructuring
|
118
|
-
extrapolateLeft = options.extrapolateLeft;
|
119
|
-
}
|
120
|
-
|
121
|
-
let extrapolateRight = "extend";
|
122
|
-
|
123
|
-
if ((options === null || options === void 0 ? void 0 : options.extrapolateRight) !== undefined) {
|
124
|
-
// eslint-disable-next-line prefer-destructuring
|
125
|
-
extrapolateRight = options.extrapolateRight;
|
126
|
-
}
|
127
|
-
|
128
|
-
if (typeof input !== "number") {
|
129
|
-
throw new TypeError("Cannot interpolate an input which is not a number");
|
130
|
-
}
|
131
|
-
|
132
|
-
const range = findRange(input, inputRange);
|
133
|
-
return interpolateFunction(input, [inputRange[range], inputRange[range + 1]], [outputRange[range], outputRange[range + 1]], {
|
134
|
-
easing,
|
135
|
-
extrapolateLeft,
|
136
|
-
extrapolateRight
|
137
|
-
});
|
138
|
-
}
|
139
|
-
//# sourceMappingURL=interpolate.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["interpolate.ts"],"names":["interpolateFunction","input","inputRange","outputRange","options","extrapolateLeft","extrapolateRight","easing","result","inputMin","inputMax","outputMin","outputMax","findRange","i","length","checkValidInputRange","arr","Error","join","checkInfiniteRange","name","index","Infinity","interpolate","num","undefined","TypeError","range"],"mappings":"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","sourcesContent":["// eslint-disable-next-line max-len\n// Taken from https://github.com/facebook/react-native/blob/0b9ea60b4fee8cacc36e7160e31b91fc114dbc0d/Libraries/Animated/src/nodes/AnimatedInterpolation.js\n\ntype ExtrapolateType = \"extend\" | \"identity\" | \"clamp\";\n\nfunction interpolateFunction(\n input: number,\n inputRange: [number, number],\n outputRange: [number, number],\n options: {\n easing: (input: number) => number;\n extrapolateLeft: ExtrapolateType;\n extrapolateRight: ExtrapolateType;\n }\n): number {\n const { extrapolateLeft, extrapolateRight, easing } = options;\n\n let result = input;\n const [inputMin, inputMax] = inputRange;\n const [outputMin, outputMax] = outputRange;\n\n if (result < inputMin) {\n if (extrapolateLeft === \"identity\") {\n return result;\n }\n\n if (extrapolateLeft === \"clamp\") {\n result = inputMin;\n } else if (extrapolateLeft === \"extend\") {\n // noop\n }\n }\n\n if (result > inputMax) {\n if (extrapolateRight === \"identity\") {\n return result;\n }\n\n if (extrapolateRight === \"clamp\") {\n result = inputMax;\n } else if (extrapolateRight === \"extend\") {\n // noop\n }\n }\n\n if (outputMin === outputMax) {\n return outputMin;\n }\n\n // Input Range\n result = (result - inputMin) / (inputMax - inputMin);\n\n // Easing\n result = easing(result);\n\n // Output Range\n result = result * (outputMax - outputMin) + outputMin;\n\n return result;\n}\n\nfunction findRange(input: number, inputRange: readonly number[]) {\n let i;\n for (i = 1; i < inputRange.length - 1; ++i) {\n if (inputRange[i] >= input) {\n break;\n }\n }\n\n return i - 1;\n}\n\nfunction checkValidInputRange(arr: readonly number[]) {\n for (let i = 1; i < arr.length; ++i) {\n if (!(arr[i] > arr[i - 1])) {\n throw new Error(\n `inputRange must be strictly monotonically non-decreasing but got [${arr.join(\n \",\"\n )}]`\n );\n }\n }\n}\n\nfunction checkInfiniteRange(name: string, arr: readonly number[]) {\n if (arr.length < 2) {\n throw new Error(name + \" must have at least 2 elements\");\n }\n\n for (const index in arr) {\n if (typeof arr[index] !== \"number\") {\n throw new Error(`${name} must contain only numbers`);\n }\n\n if (arr[index] === -Infinity || arr[index] === Infinity) {\n throw new Error(\n `${name} must contain only finite numbers, but got [${arr.join(\",\")}]`\n );\n }\n }\n}\n\nexport function interpolate(\n input: number,\n inputRange: readonly number[],\n outputRange: readonly number[],\n options?: {\n easing?: (input: number) => number;\n extrapolateLeft?: ExtrapolateType;\n extrapolateRight?: ExtrapolateType;\n }\n): number {\n if (typeof input === \"undefined\") {\n throw new Error(\"input can not be undefined\");\n }\n\n if (typeof inputRange === \"undefined\") {\n throw new Error(\"inputRange can not be undefined\");\n }\n\n if (typeof outputRange === \"undefined\") {\n throw new Error(\"outputRange can not be undefined\");\n }\n\n if (inputRange.length !== outputRange.length) {\n throw new Error(\n \"inputRange (\" +\n inputRange.length +\n \") and outputRange (\" +\n outputRange.length +\n \") must have the same length\"\n );\n }\n\n checkInfiniteRange(\"inputRange\", inputRange);\n checkInfiniteRange(\"outputRange\", outputRange);\n\n checkValidInputRange(inputRange);\n\n const easing = options?.easing ?? ((num: number): number => num);\n\n let extrapolateLeft: ExtrapolateType = \"extend\";\n if (options?.extrapolateLeft !== undefined) {\n // eslint-disable-next-line prefer-destructuring\n extrapolateLeft = options.extrapolateLeft;\n }\n\n let extrapolateRight: ExtrapolateType = \"extend\";\n if (options?.extrapolateRight !== undefined) {\n // eslint-disable-next-line prefer-destructuring\n extrapolateRight = options.extrapolateRight;\n }\n\n if (typeof input !== \"number\") {\n throw new TypeError(\"Cannot interpolate an input which is not a number\");\n }\n\n const range = findRange(input, inputRange);\n return interpolateFunction(\n input,\n [inputRange[range], inputRange[range + 1]],\n [outputRange[range], outputRange[range + 1]],\n {\n easing,\n extrapolateLeft,\n extrapolateRight,\n }\n );\n}\n"]}
|