From 2fd4feff34e3bf9ada3de0dbb6f9789facbd0500 Mon Sep 17 00:00:00 2001 From: JimmyDaddy Date: Tue, 19 Dec 2023 15:32:14 +0800 Subject: [PATCH] fix: fix#176 Fresco 3.1.3 compatibility issues with RN 0.73.0, compileDebugKotlin FAILED --- .github/workflows/ci.yml | 11 +++++++---- .../com/jimmydaddy/imagemarker/ImageLoader.kt | 18 +++++++++++++++--- ios/RCTImageMarker/ImageMarker.swift | 18 +++++++++--------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a0c96cc6..280e5bcc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Build and Test +name: CI on: pull_request: types: [opened, synchronize, reopened] @@ -74,7 +74,8 @@ jobs: assets/** package.json !example/ios/** - + example/e2e/** + - uses: actions/cache@v3 name: Cache node_modules if: steps.verify-android-changed-files.outputs.any_changed == 'true' @@ -143,7 +144,7 @@ jobs: name: app-release-${{ github.sha }}.apk path: ${{ github.workspace }}/example/android/app-release-${{ github.sha }}.apk - android-test: + android-api-level-test: runs-on: macos-latest needs: android-build name: Android Test @@ -165,6 +166,7 @@ jobs: assets/** package.json !example/ios/** + example/e2e/** - uses: actions/cache@v3 name: Cache node_modules @@ -247,6 +249,7 @@ jobs: assets/** package.json !example/android/** + example/e2e/** - uses: actions/cache@v3 name: Cache node_modules @@ -309,7 +312,7 @@ jobs: ci-complete: name: Complete CI - needs: [android-build, android-test, ios-build-test] + needs: [android-build, android-api-level-test, ios-build-test] if: ${{ always() }} runs-on: ubuntu-latest steps: diff --git a/android/src/main/java/com/jimmydaddy/imagemarker/ImageLoader.kt b/android/src/main/java/com/jimmydaddy/imagemarker/ImageLoader.kt index ec3747cb..c3bf64d7 100644 --- a/android/src/main/java/com/jimmydaddy/imagemarker/ImageLoader.kt +++ b/android/src/main/java/com/jimmydaddy/imagemarker/ImageLoader.kt @@ -7,9 +7,11 @@ import android.graphics.BitmapFactory import android.os.Build import android.util.Log import androidx.annotation.RequiresApi +import com.facebook.common.internal.Supplier import com.facebook.common.references.CloseableReference import com.facebook.datasource.DataSource import com.facebook.drawee.backends.pipeline.Fresco +import com.facebook.imagepipeline.cache.MemoryCacheParams import com.facebook.imagepipeline.common.ResizeOptions import com.facebook.imagepipeline.core.ImagePipelineConfig import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber @@ -134,9 +136,19 @@ class ImageLoader(private val context: ReactApplicationContext, private val maxS patch.toString() ) >= 0 ) { - val config = - ImagePipelineConfig.newBuilder(context).experiment().setMaxBitmapSize(maxSize) - .build() + val bitmapMemoryCacheParamsSupplier = Supplier { + MemoryCacheParams( + maxSize, // max cache entry size + Integer.MAX_VALUE, // max cache entries + maxSize, // max cache size + Integer.MAX_VALUE, // max cache eviction size + Integer.MAX_VALUE // max cache eviction count + ) + } + + val config = ImagePipelineConfig.newBuilder(context) + .setBitmapMemoryCacheParamsSupplier(bitmapMemoryCacheParamsSupplier) + .build() Fresco.initialize(context, config) } } diff --git a/ios/RCTImageMarker/ImageMarker.swift b/ios/RCTImageMarker/ImageMarker.swift index 0e603376..b0d65501 100644 --- a/ios/RCTImageMarker/ImageMarker.swift +++ b/ios/RCTImageMarker/ImageMarker.swift @@ -116,7 +116,7 @@ public final class ImageMarker: NSObject, RCTBridgeModule { } } - func markerImgWithText(_ image: UIImage, _ opts: MarkTextOptions) -> UIImage? { + func markImgWithText(_ image: UIImage, _ opts: MarkTextOptions) -> UIImage? { var bg = image; let w = bg.size.width @@ -271,8 +271,8 @@ public final class ImageMarker: NSObject, RCTBridgeModule { return aimg } - func markeImage(with image: UIImage, waterImages: [UIImage], options: MarkImageOptions) -> UIImage? { - + func markImage(with image: UIImage, waterImages: [UIImage], options: MarkImageOptions) -> UIImage? { + var bg = image; let w = bg.size.width let h = bg.size.height @@ -388,12 +388,12 @@ public final class ImageMarker: NSObject, RCTBridgeModule { Task(priority: .userInitiated) { do { let images = try await loadImages(with: [(markOpts?.backgroundImage)!]) - let scaledImage = self.markerImgWithText(images[0], markOpts!) + let scaledImage = self.markImgWithText(images[0], markOpts!) let res = self.saveImageForMarker(scaledImage!, with: markOpts!) resolver(res) - print("Loaded images:", images) + print("Loaded images: \(images)") } catch { - print("Failed to load images:", error) + print("Failed to load images, error: \(error).") } } } @@ -408,12 +408,12 @@ public final class ImageMarker: NSObject, RCTBridgeModule { do { let waterImages = markOpts?.watermarkImages.map { $0.imageOption } var images = try await loadImages(with: [(markOpts?.backgroundImage)!] + waterImages!) - let scaledImage = self.markeImage(with: images.remove(at: 0), waterImages: images, options: markOpts!) + let scaledImage = self.markImage(with: images.remove(at: 0), waterImages: images, options: markOpts!) let res = self.saveImageForMarker(scaledImage!, with: markOpts!) resolver(res) - print("Loaded images:", images) + print("Loaded images: \(images), waterImages: \(String(describing: waterImages))") } catch { - print("Failed to load images:", error) + print("Failed to load images, error: \(error).") } } }