Skip to content
Open
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 @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<ab68be1fe69275aae7e13121d0827f0e>>
* @generated SignedSource<<f9148ea52fcf53102b5c95f1dcfb8d50>>
*/

/**
Expand Down Expand Up @@ -114,6 +114,12 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun enableAndroidTextMeasurementOptimizations(): Boolean = accessor.enableAndroidTextMeasurementOptimizations()

/**
* Runs multi-source image disk-cache checks asynchronously on Android.
*/
@JvmStatic
public fun enableAsyncDiskCacheCheckInMultiSourceImageAndroid(): Boolean = accessor.enableAsyncDiskCacheCheckInMultiSourceImageAndroid()

/**
* Feature flag to enable the new bridgeless architecture.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<00e1e0529cbef727ab81a6a75174c87e>>
* @generated SignedSource<<e5f26281df4716ac5e2b88403052c747>>
*/

/**
Expand Down Expand Up @@ -34,6 +34,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
private var enableAccumulatedUpdatesInRawPropsAndroidCache: Boolean? = null
private var enableAndroidAutoOffscreenCompositingForElevationCache: Boolean? = null
private var enableAndroidTextMeasurementOptimizationsCache: Boolean? = null
private var enableAsyncDiskCacheCheckInMultiSourceImageAndroidCache: Boolean? = null
private var enableBridgelessArchitectureCache: Boolean? = null
private var enableBufferedCallInvokerCache: Boolean? = null
private var enableCppPropsIteratorSetterCache: Boolean? = null
Expand Down Expand Up @@ -235,6 +236,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
return cached
}

override fun enableAsyncDiskCacheCheckInMultiSourceImageAndroid(): Boolean {
var cached = enableAsyncDiskCacheCheckInMultiSourceImageAndroidCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.enableAsyncDiskCacheCheckInMultiSourceImageAndroid()
enableAsyncDiskCacheCheckInMultiSourceImageAndroidCache = cached
}
return cached
}

override fun enableBridgelessArchitecture(): Boolean {
var cached = enableBridgelessArchitectureCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<427c98d364e8a0aec3a0834b6a8117c8>>
* @generated SignedSource<<ac82fd72cba29452d1604770ab19804f>>
*/

/**
Expand Down Expand Up @@ -56,6 +56,8 @@ public object ReactNativeFeatureFlagsCxxInterop {

@DoNotStrip @JvmStatic public external fun enableAndroidTextMeasurementOptimizations(): Boolean

@DoNotStrip @JvmStatic public external fun enableAsyncDiskCacheCheckInMultiSourceImageAndroid(): Boolean

@DoNotStrip @JvmStatic public external fun enableBridgelessArchitecture(): Boolean

@DoNotStrip @JvmStatic public external fun enableBufferedCallInvoker(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<b6c47b10d221b493df4038e492482961>>
* @generated SignedSource<<80a561079091b74aa3c682296ffe7da3>>
*/

/**
Expand Down Expand Up @@ -51,6 +51,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi

override fun enableAndroidTextMeasurementOptimizations(): Boolean = false

override fun enableAsyncDiskCacheCheckInMultiSourceImageAndroid(): Boolean = false

override fun enableBridgelessArchitecture(): Boolean = true

override fun enableBufferedCallInvoker(): Boolean = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<20a908f1ef475bb5f51b631e2d0f2038>>
* @generated SignedSource<<3dd1a8c6227c3a1186ceaad7e3f0fc24>>
*/

/**
Expand Down Expand Up @@ -38,6 +38,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
private var enableAccumulatedUpdatesInRawPropsAndroidCache: Boolean? = null
private var enableAndroidAutoOffscreenCompositingForElevationCache: Boolean? = null
private var enableAndroidTextMeasurementOptimizationsCache: Boolean? = null
private var enableAsyncDiskCacheCheckInMultiSourceImageAndroidCache: Boolean? = null
private var enableBridgelessArchitectureCache: Boolean? = null
private var enableBufferedCallInvokerCache: Boolean? = null
private var enableCppPropsIteratorSetterCache: Boolean? = null
Expand Down Expand Up @@ -253,6 +254,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
return cached
}

override fun enableAsyncDiskCacheCheckInMultiSourceImageAndroid(): Boolean {
var cached = enableAsyncDiskCacheCheckInMultiSourceImageAndroidCache
if (cached == null) {
cached = currentProvider.enableAsyncDiskCacheCheckInMultiSourceImageAndroid()
accessedFeatureFlags.add("enableAsyncDiskCacheCheckInMultiSourceImageAndroid")
enableAsyncDiskCacheCheckInMultiSourceImageAndroidCache = cached
}
return cached
}

override fun enableBridgelessArchitecture(): Boolean {
var cached = enableBridgelessArchitectureCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<ac56780559e180d552086f3c53a1f111>>
* @generated SignedSource<<7c81e9f6b6859f3bdc1ea8ad5539be5b>>
*/

/**
Expand Down Expand Up @@ -51,6 +51,8 @@ public interface ReactNativeFeatureFlagsProvider {

@DoNotStrip public fun enableAndroidTextMeasurementOptimizations(): Boolean

@DoNotStrip public fun enableAsyncDiskCacheCheckInMultiSourceImageAndroid(): Boolean

@DoNotStrip public fun enableBridgelessArchitecture(): Boolean

@DoNotStrip public fun enableBufferedCallInvoker(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ import com.facebook.imagepipeline.request.Postprocessor
import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.UiThreadUtil.runOnUiThread
import com.facebook.react.common.annotations.UnstableReactNativeAPI
import com.facebook.react.common.annotations.VisibleForTesting
import com.facebook.react.common.build.ReactBuildConfig
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags
import com.facebook.react.internal.featureflags.ReactNativeNewArchitectureFeatureFlags
import com.facebook.react.modules.fresco.ImageCacheControl
import com.facebook.react.modules.fresco.ReactNetworkImageRequest
Expand All @@ -72,6 +74,7 @@ import com.facebook.react.views.image.ImageResizeMode.defaultValue
import com.facebook.react.views.image.MultiPostprocessor.Companion.from
import com.facebook.react.views.imagehelper.ImageSource
import com.facebook.react.views.imagehelper.ImageSource.Companion.getTransparentBitmapImageSource
import com.facebook.react.views.imagehelper.MultiSourceHelper
import com.facebook.react.views.imagehelper.MultiSourceHelper.getBestSourceForSize
import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper
import kotlin.math.abs
Expand Down Expand Up @@ -106,6 +109,7 @@ public class ReactImageView(
private var headers: ReadableMap? = null
private var resizeMultiplier = 1.0f
private var resizeMethod = ImageResizeMethod.AUTO
private var sourceGeneration = 0

init {
// Workaround Android bug where ImageView visibility is not propagated to the Drawable, so you
Expand Down Expand Up @@ -313,6 +317,7 @@ public class ReactImageView(

this.sources.clear()
this.sources.addAll(tmpSources)
sourceGeneration++
isDirty = true
}

Expand Down Expand Up @@ -544,6 +549,7 @@ public class ReactImageView(
protected override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
if (w > 0 && h > 0) {
sourceGeneration++
isDirty = isDirty || hasMultipleSources() || isTiled
maybeUpdateView()
}
Expand All @@ -555,13 +561,38 @@ public class ReactImageView(
get() = tileMode != TileMode.CLAMP

private fun setSourceImage() {
sourceGeneration++
imageSource = null
cachedImageSource = null
if (sources.isEmpty()) {
sources.add(getTransparentBitmapImageSource(context))
} else if (hasMultipleSources()) {
val multiSource = getBestSourceForSize(width, height, sources)
imageSource = multiSource.bestResult
cachedImageSource = multiSource.bestResultInCache
val selectedSource = imageSource
if (
selectedSource != null &&
selectedSource.cacheControl != ImageCacheControl.RELOAD &&
ReactNativeFeatureFlags.enableAsyncDiskCacheCheckInMultiSourceImageAndroid()
) {
val generation = sourceGeneration
MultiSourceHelper.findBestCachedSourceFromDiskAsync(width, height, sources, 1.0) { result ->
runOnUiThread {
if (
generation != sourceGeneration ||
!isAttachedToWindow ||
result == null ||
result.source == cachedImageSource?.source ||
imageSource?.source != selectedSource.source
) {
return@runOnUiThread
}
cachedImageSource = result
maybeUpdateViewFromRequest(shouldResize(selectedSource))
}
}
}
return
}
imageSource = sources[0]
Expand Down
Loading
Loading