40
40
/** A {@link FrameLayout} than is able to mask itself and all children. */
41
41
public class MaskableFrameLayout extends FrameLayout implements Maskable , Shapeable {
42
42
43
- private float maskXPercentage = 0F ;
43
+ private static final int NOT_SET = -1 ;
44
+
45
+ private float maskXPercentage = NOT_SET ;
44
46
private final RectF maskRect = new RectF ();
45
47
@ Nullable private OnMaskChangedListener onMaskChangedListener ;
46
48
@ NonNull private ShapeAppearanceModel shapeAppearanceModel ;
@@ -65,7 +67,9 @@ public MaskableFrameLayout(
65
67
@ Override
66
68
protected void onSizeChanged (int w , int h , int oldw , int oldh ) {
67
69
super .onSizeChanged (w , h , oldw , oldh );
68
- onMaskChanged ();
70
+ if (maskXPercentage != NOT_SET ) {
71
+ updateMaskRectForMaskXPercentage ();
72
+ }
69
73
}
70
74
71
75
@ Override
@@ -123,10 +127,16 @@ public void setMaskXPercentage(float percentage) {
123
127
percentage = MathUtils .clamp (percentage , 0F , 1F );
124
128
if (maskXPercentage != percentage ) {
125
129
this .maskXPercentage = percentage ;
126
- // Translate the percentage into an actual pixel value of how much of this view should be
127
- // masked away.
128
- float maskWidth = AnimationUtils .lerp (0f , getWidth () / 2F , 0f , 1f , maskXPercentage );
129
- setMaskRectF (new RectF (maskWidth , 0F , (getWidth () - maskWidth ), getHeight ()));
130
+ updateMaskRectForMaskXPercentage ();
131
+ }
132
+ }
133
+
134
+ private void updateMaskRectForMaskXPercentage () {
135
+ if (maskXPercentage != NOT_SET ) {
136
+ // Translate the percentage into an actual pixel value of how much of this view should be
137
+ // masked away.
138
+ float maskWidth = AnimationUtils .lerp (0f , getWidth () / 2F , 0f , 1f , maskXPercentage );
139
+ setMaskRectF (new RectF (maskWidth , 0F , (getWidth () - maskWidth ), getHeight ()));
130
140
}
131
141
}
132
142
0 commit comments