1919import android .graphics .Rect ;
2020import android .graphics .drawable .ColorDrawable ;
2121import android .graphics .drawable .Drawable ;
22- import android .graphics .drawable .LayerDrawable ;
2322import android .support .v4 .widget .NestedScrollView ;
2423import android .util .Log ;
2524import android .view .MotionEvent ;
3837import com .facebook .react .uimanager .ReactClippingViewGroup ;
3938import com .facebook .react .uimanager .ReactClippingViewGroupHelper ;
4039import com .facebook .infer .annotation .Assertions ;
41- import com .facebook .react .views .view .ReactViewBackgroundDrawable ;
40+ import com .facebook .react .views .view .ReactViewBackgroundManager ;
4241
4342/**
4443 * Forked from https://github.com/facebook/react-native/blob/0.45-stable/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java
@@ -70,7 +69,7 @@ public class ReactNestedScrollView extends NestedScrollView implements ReactClip
7069 private @ Nullable Drawable mEndBackground ;
7170 private int mEndFillColor = Color .TRANSPARENT ;
7271 private View mContentView ;
73- private @ Nullable ReactViewBackgroundDrawable mReactBackgroundDrawable ;
72+ private ReactViewBackgroundManager mReactBackgroundManager ;
7473
7574 public ReactNestedScrollView (ReactContext context ) {
7675 this (context , null );
@@ -79,6 +78,7 @@ public ReactNestedScrollView(ReactContext context) {
7978 public ReactNestedScrollView (ReactContext context , @ Nullable FpsListener fpsListener ) {
8079 super (context );
8180 mFpsListener = fpsListener ;
81+ mReactBackgroundManager = new ReactViewBackgroundManager (this );
8282
8383 if (!sTriedToGetScrollerField ) {
8484 sTriedToGetScrollerField = true ;
@@ -405,48 +405,29 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom, int
405405 }
406406 }
407407
408+ @ Override
408409 public void setBackgroundColor (int color ) {
409- if (color == Color .TRANSPARENT && mReactBackgroundDrawable == null ) {
410- // don't do anything, no need to allocate ReactBackgroundDrawable for transparent background
411- } else {
412- getOrCreateReactViewBackground ().setColor (color );
413- }
410+ mReactBackgroundManager .setBackgroundColor (color );
414411 }
415412
416413 public void setBorderWidth (int position , float width ) {
417- getOrCreateReactViewBackground () .setBorderWidth (position , width );
414+ mReactBackgroundManager .setBorderWidth (position , width );
418415 }
419416
420417 public void setBorderColor (int position , float color , float alpha ) {
421- getOrCreateReactViewBackground () .setBorderColor (position , color , alpha );
418+ mReactBackgroundManager .setBorderColor (position , color , alpha );
422419 }
423420
424421 public void setBorderRadius (float borderRadius ) {
425- getOrCreateReactViewBackground (). setRadius (borderRadius );
422+ mReactBackgroundManager . setBorderRadius (borderRadius );
426423 }
427424
428425 public void setBorderRadius (float borderRadius , int position ) {
429- getOrCreateReactViewBackground (). setRadius (borderRadius , position );
426+ mReactBackgroundManager . setBorderRadius (borderRadius , position );
430427 }
431428
432429 public void setBorderStyle (@ Nullable String style ) {
433- getOrCreateReactViewBackground ().setBorderStyle (style );
434- }
435-
436- private ReactViewBackgroundDrawable getOrCreateReactViewBackground () {
437- if (mReactBackgroundDrawable == null ) {
438- mReactBackgroundDrawable = new ReactViewBackgroundDrawable ();
439- Drawable backgroundDrawable = getBackground ();
440- super .setBackground (null ); // required so that drawable callback is cleared before we add the
441- // drawable back as a part of LayerDrawable
442- if (backgroundDrawable == null ) {
443- super .setBackground (mReactBackgroundDrawable );
444- } else {
445- LayerDrawable layerDrawable =
446- new LayerDrawable (new Drawable []{mReactBackgroundDrawable , backgroundDrawable });
447- super .setBackground (layerDrawable );
448- }
449- }
450- return mReactBackgroundDrawable ;
430+ mReactBackgroundManager .setBorderStyle (style );
451431 }
432+
452433}
0 commit comments