Skip to content
Open
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 @@ -18,6 +18,7 @@ import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.ReadableType
import com.facebook.react.common.ReactConstants
import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.modules.fresco.FrescoModule
import com.facebook.react.uimanager.BackgroundStyleApplicator
import com.facebook.react.uimanager.LengthPercentage
import com.facebook.react.uimanager.LengthPercentageType
Expand Down Expand Up @@ -92,12 +93,24 @@ public constructor(
?: callerContextFactory?.getOrCreateCallerContext(context.moduleName, null)
return ReactImageView(
context,
draweeControllerBuilder ?: Fresco.newDraweeControllerBuilder(),
draweeControllerBuilder ?: newDraweeControllerBuilder(context),
globalImageLoadListener,
callerContext,
)
}

private fun newDraweeControllerBuilder(
context: ThemedReactContext
): AbstractDraweeControllerBuilder<*, *, *, *> {
if (!FrescoModule.hasBeenInitialized()) {
// FrescoModule initializes Fresco on the native modules thread while the JS bundle loads, so
// the first Image can be created before that finishes. Getting the module waits for it.
// Fresco.hasBeenInitialized() doesn't help here: it turns true when initialization starts.
context.reactApplicationContext.getNativeModule(FrescoModule::class.java)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fresco initialization can be pretty costly, and the createViewInstance method is called on the main thread. Since the builder isn't called until the image mounts and has dimensions, could we instead make the constructor argument a Provider<T> for a drawee controller builder?

}
return Fresco.newDraweeControllerBuilder()
}

public override fun getName(): String = REACT_CLASS

@ReactProp(name = "accessible")
Expand Down
Loading