Skip to content

Commit f8e10f5

Browse files
author
farfromrefuge
committed
fix(android): improvement for future N
1 parent 9a933ba commit f8e10f5

File tree

1 file changed

+46
-24
lines changed
  • packages/image/platforms/android/java/com/nativescript/image

1 file changed

+46
-24
lines changed

packages/image/platforms/android/java/com/nativescript/image/DraweeView.java

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -123,34 +123,40 @@ public void setLegacyVisibilityHandlingEnabled(boolean legacyVisibilityHandlingE
123123
mLegacyVisibilityHandlingEnabled = legacyVisibilityHandlingEnabled;
124124
}
125125

126-
// private final Rect outlineRect = new RectF();
127-
public void updateOutlineProvider() {
126+
public void updateOutlineProvider() {
128127
Drawable drawable = getBackground();
129-
isUsingOutlineProvider = false;
130-
if (android.os.Build.VERSION.SDK_INT >= 21 && drawable instanceof BorderDrawable && (android.os.Build.VERSION.SDK_INT >= 33 || ((BorderDrawable)drawable).hasUniformBorderRadius())) {
131-
setOutlineProvider(new ViewOutlineProvider() {
132-
@Override
133-
public void getOutline(View view, Outline outline) {
134-
Drawable drawable = getBackground();
135-
if (drawable instanceof BorderDrawable) {
136-
BorderDrawable borderDrawable = (BorderDrawable) drawable;
137-
// that if test is only needed until N BorderDrawable is updated to do it
138-
if (borderDrawable.hasUniformBorderRadius()) {
139-
// outlineRect.set(borderDrawable.getBounds());
140-
outline.setRoundRect(borderDrawable.getBounds(), borderDrawable.getBorderBottomLeftRadius());
128+
if (android.os.Build.VERSION.SDK_INT >= 21) {
129+
// we try to support N setting outline provider now
130+
if (!isUsingOutlineProvider && getOutlineProvider() != null) {
131+
// already handled somewhere else
132+
return;
133+
}
134+
if (drawable instanceof BorderDrawable && (android.os.Build.VERSION.SDK_INT >= 33 || ((BorderDrawable)drawable).hasUniformBorderRadius())) {
135+
setOutlineProvider(new ViewOutlineProvider() {
136+
@Override
137+
public void getOutline(View view, Outline outline) {
138+
Drawable drawable = getBackground();
139+
if (drawable instanceof BorderDrawable) {
140+
BorderDrawable borderDrawable = (BorderDrawable) drawable;
141+
// that if test is only needed until N BorderDrawable is updated to do it
142+
if (borderDrawable.hasUniformBorderRadius()) {
143+
// outlineRect.set(borderDrawable.getBounds());
144+
outline.setRoundRect(borderDrawable.getBounds(), borderDrawable.getBorderBottomLeftRadius());
145+
} else {
146+
drawable.getOutline(outline);
147+
}
141148
} else {
142-
drawable.getOutline(outline);
149+
outline.setRect(100, 100, view.getWidth() - 200, view.getHeight() - 200);
143150
}
144-
} else {
145-
outline.setRect(100, 100, view.getWidth() - 200, view.getHeight() - 200);
146151
}
147-
}
148-
});
149-
setClipToOutline(true);
150-
isUsingOutlineProvider = true;
151-
} else if (android.os.Build.VERSION.SDK_INT >= 21) {
152-
setOutlineProvider(null);
153-
setClipToOutline(false);
152+
});
153+
setClipToOutline(true);
154+
isUsingOutlineProvider = true;
155+
// } else if (android.os.Build.VERSION.SDK_INT >= 21) {
156+
// isUsingOutlineProvider = false;
157+
// setOutlineProvider(null);
158+
// setClipToOutline(false);
159+
}
154160
}
155161
}
156162

@@ -293,6 +299,22 @@ public void setUri(android.net.Uri uri, String jsonOptions, com.facebook.drawee.
293299
}
294300

295301
ImageRequest request = requestBuilder.build();
302+
303+
// if (object != null && object.optBoolean("async") == false) {
304+
// DataSource<CloseableReference<CloseableImage>> dataSource =
305+
// imagePipeline.fetchImageFromBitmapCache(imageRequest, uri.toString());
306+
// try {
307+
// CloseableReference<CloseableImage> result = DataSources.waitForFinalResult(dataSource);
308+
// if (result != null) {
309+
// // Do something with the image, but do not keep the reference to it!
310+
// // The image may get recycled as soon as the reference gets closed below.
311+
// // If you need to keep a reference to the image, read the following sections.
312+
// }
313+
// } finally {
314+
// dataSource.close();
315+
// }
316+
// }
317+
296318
PipelineDraweeControllerBuilder builder = com.facebook.drawee.backends.pipeline.Fresco.newDraweeControllerBuilder();
297319
builder.setImageRequest(request);
298320
builder.setCallerContext(uri.toString());

0 commit comments

Comments
 (0)