Skip to content

Commit

Permalink
fix: fix#176 Fresco 3.1.3 compatibility issues with RN 0.73.0, compil…
Browse files Browse the repository at this point in the history
…eDebugKotlin FAILED
  • Loading branch information
JimmyDaddy committed Dec 21, 2023
1 parent 10d71e1 commit 2fd4fef
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Test
name: CI
on:
pull_request:
types: [opened, synchronize, reopened]
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -165,6 +166,7 @@ jobs:
assets/**
package.json
!example/ios/**
example/e2e/**
- uses: actions/cache@v3
name: Cache node_modules
Expand Down Expand Up @@ -247,6 +249,7 @@ jobs:
assets/**
package.json
!example/android/**
example/e2e/**
- uses: actions/cache@v3
name: Cache node_modules
Expand Down Expand Up @@ -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:
Expand Down
18 changes: 15 additions & 3 deletions android/src/main/java/com/jimmydaddy/imagemarker/ImageLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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> {
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)
}
}
Expand Down
18 changes: 9 additions & 9 deletions ios/RCTImageMarker/ImageMarker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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).")
}
}
}
Expand All @@ -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).")
}
}
}
Expand Down

0 comments on commit 2fd4fef

Please sign in to comment.