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

Convert views/image interface files #43742

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.views.image;
package com.facebook.react.views.image

import android.net.Uri;
import android.net.Uri

/** Listener interface for global image loading events. */
public interface GlobalImageLoadListener {

/** Called when a source has been set on an ImageView, but before it is actually loaded. */
void onLoadAttempt(Uri uri);
public fun onLoadAttempt(uri: Uri?)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.views.image

/**
* This interface is used from [ReactImageManager] to customize the CallerContext object associated
* with each instance of [ReactImageView].
*/
public fun interface ReactCallerContextFactory {
/**
* This method will be called at the time [ReactImageManager] creates [ReactImageView]
*
* @param surfaceName [String] used to log the name of the surface
* @return an [Object] that represents the CallerContext.
*/
public fun getOrCreateCallerContext(surfaceName: String?, analyticTag: String?): Any?
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.views.image

import android.graphics.Canvas
import android.graphics.ColorFilter
import android.graphics.PixelFormat
import android.graphics.drawable.Animatable
import android.graphics.drawable.Drawable
import com.facebook.drawee.controller.ControllerListener
import com.facebook.drawee.drawable.ForwardingDrawable

internal open class ReactImageDownloadListener<INFO> :
ForwardingDrawable(EmptyDrawable()), ControllerListener<INFO> {
open fun onProgressChange(loaded: Int, total: Int) = Unit

override fun onLevelChange(level: Int): Boolean {
onProgressChange(level, MAX_LEVEL)
return super.onLevelChange(level)
}

override fun onSubmit(id: String, callerContext: Any) = Unit

override fun onFinalImageSet(id: String, imageInfo: INFO?, animatable: Animatable?) = Unit

override fun onIntermediateImageSet(id: String, imageInfo: INFO?) = Unit

override fun onIntermediateImageFailed(id: String, throwable: Throwable) = Unit

override fun onFailure(id: String, throwable: Throwable) = Unit

override fun onRelease(id: String) = Unit

/** A [Drawable] that renders nothing. */
private class EmptyDrawable : Drawable() {
override fun draw(canvas: Canvas) = Unit

override fun setAlpha(alpha: Int) = Unit

override fun setColorFilter(colorFilter: ColorFilter?) = Unit

override fun getOpacity(): Int = PixelFormat.OPAQUE
}

companion object {
private const val MAX_LEVEL = 10000
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.views.image

import android.graphics.Matrix
import android.graphics.Rect
import com.facebook.drawee.drawable.ScalingUtils
import com.facebook.drawee.drawable.ScalingUtils.AbstractScaleType
import kotlin.math.min

internal class ScaleTypeStartInside : AbstractScaleType() {
override fun getTransformImpl(
outTransform: Matrix,
parentRect: Rect,
childWidth: Int,
childHeight: Int,
focusX: Float,
focusY: Float,
scaleX: Float,
scaleY: Float
) {
val scale = min(scaleX, scaleY).coerceAtMost(1.0f)
val dx = parentRect.left.toFloat()
val dy = parentRect.top.toFloat()
outTransform.setScale(scale, scale)
outTransform.postTranslate(Math.round(dx).toFloat(), Math.round(dy).toFloat())
}

override fun toString(): String {
return "start_inside"
}

companion object {
val INSTANCE: ScalingUtils.ScaleType = ScaleTypeStartInside()
}
}
Loading