From 2c0679bed12bfdd4f6359282eb2feb3018ce636c Mon Sep 17 00:00:00 2001 From: Alexander Blom Date: Fri, 27 Nov 2015 02:05:56 -0800 Subject: [PATCH] Reuse DraweeControllerBuilder instead of allocating one for every image Reviewed By: astreet Differential Revision: D2699801 fb-gh-sync-id: 883e788f0a5c7231bf26f1ba4149115a15487366 --- .../facebook/react/views/image/ReactImageManager.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageManager.java index 19ff9420533259..8803652d11538c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageManager.java @@ -32,7 +32,7 @@ public String getName() { return REACT_CLASS; } - private final @Nullable AbstractDraweeControllerBuilder mDraweeControllerBuilder; + private @Nullable AbstractDraweeControllerBuilder mDraweeControllerBuilder; private final @Nullable Object mCallerContext; public ReactImageManager( @@ -43,16 +43,20 @@ public ReactImageManager( } public ReactImageManager() { + // Lazily initialize as FrescoModule have not been initialized yet mDraweeControllerBuilder = null; mCallerContext = null; } @Override public ReactImageView createViewInstance(ThemedReactContext context) { + if (mDraweeControllerBuilder == null) { + mDraweeControllerBuilder = Fresco.newDraweeControllerBuilder(); + } + return new ReactImageView( context, - mDraweeControllerBuilder == null ? - Fresco.newDraweeControllerBuilder() : mDraweeControllerBuilder, + mDraweeControllerBuilder, mCallerContext); }