将react-native更新到0.75.1后-react-native-fast-image在android上运行应用程序时出现错误

问题描述 投票:0回答:1

我已经将react-native更新到最新的0.75.1版本,现在在Android上运行该应用程序后出现以下错误。

node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java:14: 错误:无法从最终 ImageSource 公共类继承 FastImageSource 扩展了 ImageSource {

以下是应用程序中使用的版本

 "react": "18.3.1",
 "react-native": "0.75.1",
 "react-native-fast-image": "^8.6.3",
javascript android react-native react-native-fast-image react-native-upgrade
1个回答
0
投票

我遇到了同样的问题,并通过在 RN 75+ 中修补包来解决

public class FastImageSource {
private final ImageSource imageSource;
private static final String DATA_SCHEME = "data";
private static final String LOCAL_RESOURCE_SCHEME = "res";
private static final String ANDROID_RESOURCE_SCHEME = "android.resource";
private static final String ANDROID_CONTENT_SCHEME = "content";
private static final String LOCAL_FILE_SCHEME = "file";
private final Headers mHeaders;
private Uri mUri;

public static boolean isBase64Uri(Uri uri) {
    return DATA_SCHEME.equals(uri.getScheme());
}

public static boolean isLocalResourceUri(Uri uri) {
    return LOCAL_RESOURCE_SCHEME.equals(uri.getScheme());
}

public static boolean isResourceUri(Uri uri) {
    return ANDROID_RESOURCE_SCHEME.equals(uri.getScheme());
}

public String getSource() {
    return imageSource.getSource();
}

public static boolean isContentUri(Uri uri) {
    return ANDROID_CONTENT_SCHEME.equals(uri.getScheme());
}

public static boolean isLocalFileUri(Uri uri) {
    return LOCAL_FILE_SCHEME.equals(uri.getScheme());
}

public FastImageSource(Context context, String source) {
    this(context, source, null);
}

public FastImageSource(Context context, String source, @Nullable Headers headers) {
    this(context, source, 0.0d, 0.0d, headers);
}

public FastImageSource(Context context, String source, double width, double height, @Nullable Headers headers) {
    imageSource = new ImageSource(context, source, width, height);
    mHeaders = headers == null ? Headers.DEFAULT : headers;
    mUri = imageSource.getUri();

    if (isResource() && TextUtils.isEmpty(mUri.toString())) {
        throw new Resources.NotFoundException("Local Resource Not Found. Resource: '" + imageSource + "'.");
    }

    if (isLocalResourceUri(mUri)) {
        // Convert res:/ scheme to android.resource:// so
        // glide can understand the uri.
        mUri = Uri.parse(mUri.toString().replace("res:/", ANDROID_RESOURCE_SCHEME + "://" + context.getPackageName() + "/"));
    }
}


public boolean isBase64Resource() {
    return mUri != null && FastImageSource.isBase64Uri(mUri);
}

public boolean isResource() {
    return mUri != null && FastImageSource.isResourceUri(mUri);
}

public boolean isLocalFile() {
    return mUri != null && FastImageSource.isLocalFileUri(mUri);
}

public boolean isContentUri() {
    return mUri != null && FastImageSource.isContentUri(mUri);
}

public Object getSourceForLoad() {
    if (isContentUri()) {
        return getSource();
    }
    if (isBase64Resource()) {
        return getSource();
    }
    if (isResource()) {
        return getUri();
    }
    if (isLocalFile()) {
        return getUri().toString();
    }
    return getGlideUrl();
}

public Uri getUri() {
    return mUri;
}

public Headers getHeaders() {
    return mHeaders;
}

public GlideUrl getGlideUrl() {
    return new GlideUrl(getUri().toString(), getHeaders());
}
 }

有一些变化,

  1. 删除扩展类
  2. 添加了 ImageSource 变量来保存 ImageSource,无需扩展类
  3. 超级图像源设置器
  4. 删除 getURI 上的覆盖 // 不再需要,因为扩展已被删除
  5. 添加了 getSource 以将自定义 ImageSource 导出到类之外

到现在为止已测试并进行生产构建两周没有任何问题

© www.soinside.com 2019 - 2024. All rights reserved.