-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert views/image interface files (#43742)
Summary: Pull Request resolved: #43742 ## 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: https://internalfb.com/D55589946
- Loading branch information
1 parent
b52c7aa
commit eee8ec3
Showing
7 changed files
with
119 additions
and
150 deletions.
There are no files selected for viewing
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
26 changes: 0 additions & 26 deletions
26
.../ReactAndroid/src/main/java/com/facebook/react/views/image/ReactCallerContextFactory.java
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
...ve/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactCallerContextFactory.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,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? | ||
} |
80 changes: 0 additions & 80 deletions
80
...ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageDownloadListener.java
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
...e/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageDownloadListener.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 @@ | ||
/* | ||
* 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 | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
...ative/ReactAndroid/src/main/java/com/facebook/react/views/image/ScaleTypeStartInside.java
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
...-native/ReactAndroid/src/main/java/com/facebook/react/views/image/ScaleTypeStartInside.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,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() | ||
} | ||
} |