Skip to content

Commit eeb6432

Browse files
committed
update Android scroll views to support wide gamut color
1 parent b3a8eba commit eeb6432

File tree

4 files changed

+34
-25
lines changed

4 files changed

+34
-25
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import android.content.Context;
1818
import android.graphics.Canvas;
1919
import android.graphics.Color;
20+
import android.graphics.Paint;
2021
import android.graphics.Rect;
2122
import android.graphics.drawable.ColorDrawable;
2223
import android.graphics.drawable.Drawable;
@@ -96,7 +97,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
9697
private @Nullable FpsListener mFpsListener = null;
9798
private @Nullable String mScrollPerfTag;
9899
private @Nullable Drawable mEndBackground;
99-
private int mEndFillColor = Color.TRANSPARENT;
100+
private long mEndFillColor = Color.pack(Color.TRANSPARENT);
100101
private boolean mDisableIntervalMomentum = false;
101102
private int mSnapInterval = 0;
102103
private @Nullable List<Integer> mSnapOffsets;
@@ -780,7 +781,7 @@ private View getContentView() {
780781
return getChildAt(0);
781782
}
782783

783-
public void setEndFillColor(int color) {
784+
public void setEndFillColor(long color) {
784785
if (color != mEndFillColor) {
785786
mEndFillColor = color;
786787
mEndBackground = new ColorDrawable(mEndFillColor);
@@ -857,9 +858,10 @@ private boolean isScrollPerfLoggingEnabled() {
857858
public void draw(Canvas canvas) {
858859
if (mEndFillColor != Color.TRANSPARENT) {
859860
final View content = getContentView();
860-
if (mEndBackground != null && content != null && content.getRight() < getWidth()) {
861-
mEndBackground.setBounds(content.getRight(), 0, getWidth(), getHeight());
862-
mEndBackground.draw(canvas);
861+
if (content != null && content.getRight() < getWidth()) {
862+
Paint paint = new Paint();
863+
paint.setColor(mEndFillColor);
864+
canvas.drawRect(content.getRight(), 0, getWidth(), getHeight(), paint);
863865
}
864866
}
865867
super.draw(canvas);
@@ -1273,12 +1275,16 @@ public void setBackgroundColor(int color) {
12731275
mReactBackgroundManager.setBackgroundColor(color);
12741276
}
12751277

1278+
public void setBackgroundColor(long color) {
1279+
mReactBackgroundManager.setBackgroundColor(color);
1280+
}
1281+
12761282
public void setBorderWidth(int position, float width) {
12771283
mReactBackgroundManager.setBorderWidth(position, width);
12781284
}
12791285

1280-
public void setBorderColor(int position, float color, float alpha) {
1281-
mReactBackgroundManager.setBorderColor(position, color, alpha);
1286+
public void setBorderColor(int position, long color) {
1287+
mReactBackgroundManager.setBorderColor(position, color);
12821288
}
12831289

12841290
public void setBorderRadius(float borderRadius) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public void scrollToEnd(
236236
* @param color
237237
*/
238238
@ReactProp(name = "endFillColor", defaultInt = Color.TRANSPARENT, customType = "Color")
239-
public void setBottomFillColor(ReactHorizontalScrollView view, int color) {
239+
public void setBottomFillColor(ReactHorizontalScrollView view, long color) {
240240
view.setEndFillColor(color);
241241
}
242242

@@ -291,11 +291,9 @@ public void setBorderWidth(ReactHorizontalScrollView view, int index, float widt
291291
"borderBottomColor"
292292
},
293293
customType = "Color")
294-
public void setBorderColor(ReactHorizontalScrollView view, int index, Integer color) {
295-
float rgbComponent =
296-
color == null ? YogaConstants.UNDEFINED : (float) ((int) color & 0x00FFFFFF);
297-
float alphaComponent = color == null ? YogaConstants.UNDEFINED : (float) ((int) color >>> 24);
298-
view.setBorderColor(SPACING_TYPES[index], rgbComponent, alphaComponent);
294+
public void setBorderColor(ReactHorizontalScrollView view, int index, Long color) {
295+
long borderColor = color == null ? 0 : color;
296+
view.setBorderColor(SPACING_TYPES[index], borderColor);
299297
}
300298

301299
@ReactProp(name = "overflow")

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import android.content.Context;
1818
import android.graphics.Canvas;
1919
import android.graphics.Color;
20+
import android.graphics.Paint;
2021
import android.graphics.Rect;
2122
import android.graphics.drawable.ColorDrawable;
2223
import android.graphics.drawable.Drawable;
@@ -97,7 +98,7 @@ public class ReactScrollView extends ScrollView
9798
private @Nullable FpsListener mFpsListener = null;
9899
private @Nullable String mScrollPerfTag;
99100
private @Nullable Drawable mEndBackground;
100-
private int mEndFillColor = Color.TRANSPARENT;
101+
private long mEndFillColor = Color.pack(Color.TRANSPARENT);
101102
private boolean mDisableIntervalMomentum = false;
102103
private int mSnapInterval = 0;
103104
private @Nullable List<Integer> mSnapOffsets;
@@ -622,9 +623,10 @@ public void setStateWrapper(StateWrapper stateWrapper) {
622623
public void draw(Canvas canvas) {
623624
if (mEndFillColor != Color.TRANSPARENT) {
624625
final View contentView = getContentView();
625-
if (mEndBackground != null && contentView != null && contentView.getBottom() < getHeight()) {
626-
mEndBackground.setBounds(0, contentView.getBottom(), getWidth(), getHeight());
627-
mEndBackground.draw(canvas);
626+
if (contentView != null && contentView.getBottom() < getHeight()) {
627+
Paint paint = new Paint();
628+
paint.setColor(mEndFillColor);
629+
canvas.drawRect(0, contentView.getBottom(), getWidth(), getHeight(), paint);
628630
}
629631
}
630632
getDrawingRect(mRect);
@@ -1003,7 +1005,7 @@ private int getSnapInterval() {
10031005
return getHeight();
10041006
}
10051007

1006-
public void setEndFillColor(int color) {
1008+
public void setEndFillColor(long color) {
10071009
if (color != mEndFillColor) {
10081010
mEndFillColor = color;
10091011
mEndBackground = new ColorDrawable(mEndFillColor);
@@ -1151,12 +1153,16 @@ public void setBackgroundColor(int color) {
11511153
mReactBackgroundManager.setBackgroundColor(color);
11521154
}
11531155

1156+
public void setBackgroundColor(long color) {
1157+
mReactBackgroundManager.setBackgroundColor(color);
1158+
}
1159+
11541160
public void setBorderWidth(int position, float width) {
11551161
mReactBackgroundManager.setBorderWidth(position, width);
11561162
}
11571163

1158-
public void setBorderColor(int position, float color, float alpha) {
1159-
mReactBackgroundManager.setBorderColor(position, color, alpha);
1164+
public void setBorderColor(int position, long color) {
1165+
mReactBackgroundManager.setBorderColor(position, color);
11601166
}
11611167

11621168
public void setBorderRadius(float borderRadius) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public void setPagingEnabled(ReactScrollView view, boolean pagingEnabled) {
173173
* @param color
174174
*/
175175
@ReactProp(name = "endFillColor", defaultInt = Color.TRANSPARENT, customType = "Color")
176-
public void setBottomFillColor(ReactScrollView view, int color) {
176+
public void setBottomFillColor(ReactScrollView view, long color) {
177177
view.setEndFillColor(color);
178178
}
179179

@@ -272,10 +272,9 @@ public void setBorderWidth(ReactScrollView view, int index, float width) {
272272
"borderBottomColor"
273273
},
274274
customType = "Color")
275-
public void setBorderColor(ReactScrollView view, int index, Integer color) {
276-
float rgbComponent = color == null ? YogaConstants.UNDEFINED : (float) (color & 0x00FFFFFF);
277-
float alphaComponent = color == null ? YogaConstants.UNDEFINED : (float) (color >>> 24);
278-
view.setBorderColor(SPACING_TYPES[index], rgbComponent, alphaComponent);
275+
public void setBorderColor(ReactScrollView view, int index, Long color) {
276+
long borderColor = color == null ? 0 : color;
277+
view.setBorderColor(SPACING_TYPES[index], borderColor);
279278
}
280279

281280
@ReactProp(name = "overflow")

0 commit comments

Comments
 (0)