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

Fixed svg example #2821

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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 @@ -23,6 +23,7 @@ import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin
import com.facebook.flipper.plugins.fresco.FrescoFlipperRequestListener
import com.facebook.flipper.plugins.inspector.DescriptorMapping
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin
import com.facebook.fresco.samples.showcase.imageformat.svg.SvgDecoderExample
import com.facebook.fresco.samples.showcase.misc.DebugOverlaySupplierSingleton
import com.facebook.fresco.samples.showcase.misc.ImageUriProvider
import com.facebook.fresco.samples.showcase.misc.LogcatRequestListener2
Expand Down Expand Up @@ -164,6 +165,12 @@ class ShowcaseApplication : Application() {
resources: Resources,
vitoConfig: FrescoVitoConfig = DefaultFrescoVitoConfig(),
) {
val externalImageOptionsDrawableFactories = if (CustomImageFormatConfigurator.isSvgEnabled(this)) {
listOf(SvgDecoderExample.SvgDrawableFactory())
} else {
emptyList()
}

if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(KEY_VITO_KOTLIN, false)) {
FrescoVito.initialize(
KFrescoVitoProvider(
Expand All @@ -177,13 +184,18 @@ class ShowcaseApplication : Application() {
.executorSupplier
.forLightweightBackgroundTasks(),
NoOpCallerContextVerifier,
DebugOverlayHandler(DebugOverlaySupplierSingleton.getInstance(applicationContext))))
DebugOverlayHandler(DebugOverlaySupplierSingleton.getInstance(applicationContext)),
externalImageOptionsDrawableFactories,
)
)
} else {
FrescoVito.initialize(
vitoConfig = vitoConfig,
debugOverlayEnabledSupplier =
DebugOverlaySupplierSingleton.getInstance(applicationContext),
vitoImagePerfListener = imageTracker)
vitoImagePerfListener = imageTracker,
externalImageOptionsDrawableFactories = externalImageOptionsDrawableFactories
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.facebook.fresco.vito.provider.impl.NoOpCallerContextVerifier
import com.facebook.fresco.vito.provider.setup.FrescoVitoSetup
import com.facebook.imagepipeline.core.ImagePipeline
import com.facebook.imagepipeline.core.ImagePipelineFactory
import com.facebook.imagepipeline.drawable.DrawableFactory
import java.util.concurrent.Executor

class FrescoVito {
Expand Down Expand Up @@ -60,6 +61,7 @@ class FrescoVito {
imagePerfListenerSupplier: Supplier<ImagePerfLoggingListener>? = null,
showExtendedDebugOverlayInformation: Boolean = true,
showExtendedImageSourceExtraInformation: Boolean = false,
externalImageOptionsDrawableFactories: List<DrawableFactory> = emptyList(),
) {
if (isInitialized) {
return
Expand All @@ -84,7 +86,10 @@ class FrescoVito {
showExtendedImageSourceExtraInformation,
it)
} ?: NoOpDebugOverlayFactory2(),
imagePerfListenerSupplier))
imagePerfListenerSupplier,
externalImageOptionsDrawableFactories,
),
)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.facebook.fresco.vito.options.ImageOptionsDrawableFactory
import com.facebook.fresco.vito.provider.setup.FrescoVitoSetup
import com.facebook.imagepipeline.core.ImagePipeline
import com.facebook.imagepipeline.core.ImagePipelineFactory
import com.facebook.imagepipeline.drawable.DrawableFactory
import java.util.concurrent.Executor

class DefaultFrescoVitoProvider(
Expand All @@ -41,6 +42,7 @@ class DefaultFrescoVitoProvider(
vitoImagePerfListener: VitoImagePerfListener,
debugOverlayFactory: DebugOverlayFactory2 = NoOpDebugOverlayFactory2(),
imagePerfListenerSupplier: Supplier<ImagePerfLoggingListener>? = null,
externalImageOptionsDrawableFactories: List<DrawableFactory> = emptyList()
) : FrescoVitoSetup {

private val frescoController: FrescoController2
Expand All @@ -60,7 +62,7 @@ class DefaultFrescoVitoProvider(
frescoController =
FrescoController2Impl(
frescoVitoConfig,
HierarcherImpl(createDefaultDrawableFactory()),
HierarcherImpl(createDefaultDrawableFactory(externalImageOptionsDrawableFactories)),
lightweightBackgroundThreadExecutor,
uiThreadExecutor,
vitoImagePipeline,
Expand All @@ -79,15 +81,18 @@ class DefaultFrescoVitoProvider(
override fun getConfig(): FrescoVitoConfig = frescoVitoConfig

companion object {
private fun createDefaultDrawableFactory(): ImageOptionsDrawableFactory {
private fun createDefaultDrawableFactory(
externalImageOptionsDrawableFactories: List<DrawableFactory>
): ImageOptionsDrawableFactory {
val animatedDrawableFactory =
ImagePipelineFactory.getInstance()
.getAnimatedDrawableFactory(null)
?.let(DrawableFactoryWrapper::wrap)
val bitmapFactory = BitmapDrawableFactory()
val xmlFactory =
ImagePipelineFactory.getInstance().xmlDrawableFactory?.let(DrawableFactoryWrapper::wrap)
val factories = listOfNotNull(bitmapFactory, animatedDrawableFactory, xmlFactory)
val factories = listOfNotNull(bitmapFactory, animatedDrawableFactory, xmlFactory) +
externalImageOptionsDrawableFactories.map(DrawableFactoryWrapper::wrap)
return when (factories.size) {
1 -> factories[0]
else -> ArrayVitoDrawableFactory(*factories.toTypedArray())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.facebook.fresco.vito.provider.impl.NoOpCallerContextVerifier
import com.facebook.fresco.vito.provider.setup.FrescoVitoSetup
import com.facebook.imagepipeline.core.ImagePipeline
import com.facebook.imagepipeline.core.ImagePipelineFactory
import com.facebook.imagepipeline.drawable.DrawableFactory
import java.util.concurrent.Executor

class KFrescoVitoProvider(
Expand All @@ -33,7 +34,8 @@ class KFrescoVitoProvider(
private val uiThreadExecutor: Executor,
private val lightweightBackgroundExecutor: Executor,
private val callerContextVerifier: CallerContextVerifier = NoOpCallerContextVerifier,
private val debugOverlayHandler: DebugOverlayHandler? = null
private val debugOverlayHandler: DebugOverlayHandler? = null,
private val externalImageOptionsDrawableFactories: List<DrawableFactory> = emptyList()
) : FrescoVitoSetup {

private val _imagePipeline: VitoImagePipeline by lazy {
Expand Down Expand Up @@ -71,7 +73,8 @@ class KFrescoVitoProvider(
ImagePipelineFactory.getInstance()
.getXmlDrawableFactory()
?.let(DrawableFactoryWrapper::wrap)
val factories = listOfNotNull(animatedDrawableFactory, xmlFactory)
val factories = listOfNotNull(animatedDrawableFactory, xmlFactory) +
externalImageOptionsDrawableFactories.map(DrawableFactoryWrapper::wrap)
return when (factories.size) {
0 -> null
1 -> factories[0]
Expand Down