software-mansion / react-native-svg

SVG library for React Native, React Native Web, and plain React web projects.
MIT License
7.53k stars 1.14k forks source link

error: switch rules are not supported in -source 11 #2551

Open Hugo-Tek opened 4 days ago

Hugo-Tek commented 4 days ago

Description

Hi, I have a problem that I don't understand how to solve, can you help me?

I upgraded my react-native-svg version from ‘^15.4.0’ to ‘15.9.0’.

yet my FeBlendView.java file is different than the one in the repo (on Github) :

package com.horcrux.svg;

import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import com.facebook.react.bridge.ReactContext;
import java.util.HashMap;

@SuppressLint("ViewConstructor")
class FeBlendView extends FilterPrimitiveView {
  String mIn1;
  String mIn2;
  FilterProperties.FeBlendMode mMode;

  public FeBlendView(ReactContext reactContext) {
    super(reactContext);
    super.mFilterSubregion.mX = new SVGLength(0);
    super.mFilterSubregion.mY = new SVGLength(0);
    super.mFilterSubregion.mW = new SVGLength("100%");
    super.mFilterSubregion.mH = new SVGLength("100%");
  }

  public void setIn1(String in1) {
    this.mIn1 = in1;
    invalidate();
  }

  public void setIn2(String in2) {
    this.mIn2 = in2;
    invalidate();
  }

  public void setMode(String mode) {
    this.mMode = FilterProperties.FeBlendMode.getEnum(mode);
    invalidate();
  }

  @Override
  public Bitmap applyFilter(HashMap<String, Bitmap> resultsMap, Bitmap prevResult) {
    Bitmap in1 = getSource(resultsMap, prevResult, this.mIn1);
    Bitmap in2 = getSource(resultsMap, prevResult, this.mIn2);

    if (this.mMode == FilterProperties.FeBlendMode.MULTIPLY) {
      CustomFilterFunction multiply =
          (src, dst) -> {
            float[] res = new float[4];
            res[0] = 1f - (1f - src[0]) * (1f - dst[0]);
            res[1] =
                src[1] * src[0] * (1f - dst[0])
                    + dst[1] * dst[0] * (1f - src[0])
                    + src[1] * src[0] * dst[1] * dst[0];
            res[2] =
                src[2] * src[0] * (1f - dst[0])
                    + dst[2] * dst[0] * (1f - src[0])
                    + src[2] * src[0] * dst[2] * dst[0];
            res[3] =
                src[3] * src[0] * (1f - dst[0])
                    + dst[3] * dst[0] * (1f - src[0])
                    + src[3] * src[0] * dst[3] * dst[0];
            return res;
          };
      return CustomFilter.apply(in1, in2, multiply);
    }

    Bitmap result = Bitmap.createBitmap(in1.getWidth(), in1.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    canvas.drawBitmap(in1, 0, 0, paint);

    switch (this.mMode) {
      case NORMAL -> {
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OVER));
      }
      case SCREEN -> {
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN));
      }
      case LIGHTEN -> {
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.LIGHTEN));
      }
      case DARKEN -> {
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DARKEN));
      }
      case MULTIPLY -> {}
    }
    canvas.drawBitmap(in2, 0, 0, paint);

    return result;
  }
}

Steps to reproduce

When I tried to build, this error appear :

> Task :react-native-svg:compileDebugJavaWithJavac FAILED
/Users/usr/Documents/Projects/prj/node_modules/react-native-svg/android/src/main/java/com/horcrux/svg/FeBlendView.java:74: error: switch rules are not supported in -source 11
      case NORMAL -> {
                  ^
  (use -source 14 or higher to enable switch rules)
/Users/usr/Documents/Projects/prj/node_modules/react-native-svg/android/src/main/java/com/horcrux/svg/FeCompositeView.java:71: error: switch rules are not supported in -source 11
      case OVER -> {
                ^
  (use -source 14 or higher to enable switch rules)

Snack or a link to a repository

don't have

SVG version

15.9.0

React Native version

0.72.3

Platforms

Android

JavaScript runtime

None

Workflow

React Native

Architecture

None

Build type

None

Device

None

Device model

No response

Acknowledgements

Yes

github-actions[bot] commented 4 days ago

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

jakex7 commented 3 days ago

Hey @Hugo-Tek, These changes have not been published yet and will land in the next release, likely at the beginning of next week.

ngioldasis commented 3 days ago

I have the same problem. Did anyone manage to solve it?