Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Hugo-Tek opened this issue Nov 27, 2024 · 3 comments
Open

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

Hugo-Tek opened this issue Nov 27, 2024 · 3 comments
Labels
Missing repro This issue need minimum repro scenario

Comments

@Hugo-Tek
Copy link

Hugo-Tek commented Nov 27, 2024

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 github-actions bot added the Missing repro This issue need minimum repro scenario label Nov 27, 2024
Copy link

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
Copy link
Member

jakex7 commented Nov 28, 2024

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Missing repro This issue need minimum repro scenario
Projects
None yet
Development

No branches or pull requests

3 participants