-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: resize on Android * refactor: turbo image listener * refactor: transformations * refactor: transformations
- Loading branch information
Showing
3 changed files
with
114 additions
and
85 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
android/src/main/java/com/turboimage/TurboImageListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.turboimage | ||
|
||
import coil.request.ErrorResult | ||
import coil.request.ImageRequest | ||
import coil.request.SuccessResult | ||
import com.facebook.react.bridge.ReactContext | ||
import com.facebook.react.bridge.WritableNativeMap | ||
import com.facebook.react.uimanager.events.RCTEventEmitter | ||
|
||
class TurboImageListener(private val view: TurboImageView) : ImageRequest.Listener { | ||
|
||
override fun onStart(request: ImageRequest) { | ||
super.onStart(request) | ||
val payload = WritableNativeMap().apply { | ||
putString("state", "running") | ||
} | ||
val reactContext = view.context as ReactContext | ||
reactContext.getJSModule(RCTEventEmitter::class.java) | ||
.receiveEvent(view.id, "onStart", payload) | ||
} | ||
|
||
override fun onSuccess(request: ImageRequest, result: SuccessResult) { | ||
super.onSuccess(request, result) | ||
val successPayload = WritableNativeMap().apply { | ||
putInt("width", result.drawable.intrinsicWidth) | ||
putInt("height", result.drawable.intrinsicHeight) | ||
putString("source", request.data.toString()) | ||
} | ||
val reactContext = view.context as ReactContext | ||
reactContext.getJSModule(RCTEventEmitter::class.java) | ||
.receiveEvent(view.id, "onSuccess", successPayload) | ||
val completionPayload = WritableNativeMap().apply { | ||
putString("state", "completed") | ||
} | ||
reactContext.getJSModule(RCTEventEmitter::class.java) | ||
.receiveEvent(view.id, "onCompletion", completionPayload) | ||
} | ||
|
||
override fun onError(request: ImageRequest, result: ErrorResult) { | ||
super.onError(request, result) | ||
val failurePayload = WritableNativeMap().apply { | ||
putString("error", result.throwable.message) | ||
} | ||
val reactContext = view.context as ReactContext | ||
reactContext.getJSModule(RCTEventEmitter::class.java) | ||
.receiveEvent(view.id, "onFailure", failurePayload) | ||
val completionPayload = WritableNativeMap().apply { | ||
putString("state", "completed") | ||
} | ||
reactContext.getJSModule(RCTEventEmitter::class.java) | ||
.receiveEvent(view.id, "onCompletion", completionPayload) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters