Skip to content

Commit

Permalink
Convert views/image interface files
Browse files Browse the repository at this point in the history
Summary:
## Changelog:
[Internal] -

As in the title - taking a subset of the views/image Java files, those that are related to interfaces, and convert them to Kotlin.

Differential Revision: D55589946
  • Loading branch information
rshest authored and facebook-github-bot committed Apr 1, 2024
1 parent 2205880 commit c41ba8c
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 150 deletions.
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()
}
}

0 comments on commit c41ba8c

Please sign in to comment.