Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
Expand Down Expand Up @@ -95,8 +96,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
private boolean mSendMomentumEvents;
private @Nullable FpsListener mFpsListener = null;
private @Nullable String mScrollPerfTag;
private @Nullable Drawable mEndBackground;
private int mEndFillColor = Color.TRANSPARENT;
private long mEndFillColor = Color.pack(Color.TRANSPARENT);
private boolean mDisableIntervalMomentum = false;
private int mSnapInterval = 0;
private @Nullable List<Integer> mSnapOffsets;
Expand Down Expand Up @@ -780,10 +780,9 @@ private View getContentView() {
return getChildAt(0);
}

public void setEndFillColor(int color) {
public void setEndFillColor(long color) {
if (color != mEndFillColor) {
mEndFillColor = color;
mEndBackground = new ColorDrawable(mEndFillColor);
}
}

Expand Down Expand Up @@ -855,11 +854,12 @@ private boolean isScrollPerfLoggingEnabled() {

@Override
public void draw(Canvas canvas) {
if (mEndFillColor != Color.TRANSPARENT) {
if (mEndFillColor != Color.pack(Color.TRANSPARENT)) {
final View content = getContentView();
if (mEndBackground != null && content != null && content.getRight() < getWidth()) {
mEndBackground.setBounds(content.getRight(), 0, getWidth(), getHeight());
mEndBackground.draw(canvas);
if (content != null && content.getRight() < getWidth()) {
Paint paint = new Paint();
paint.setColor(mEndFillColor);
canvas.drawRect(content.getRight(), 0, getWidth(), getHeight(), paint);
}
}
super.draw(canvas);
Expand Down Expand Up @@ -1273,12 +1273,16 @@ public void setBackgroundColor(int color) {
mReactBackgroundManager.setBackgroundColor(color);
}

public void setBackgroundColor(long color) {
mReactBackgroundManager.setBackgroundColor(color);
}

public void setBorderWidth(int position, float width) {
mReactBackgroundManager.setBorderWidth(position, width);
}

public void setBorderColor(int position, float color, float alpha) {
mReactBackgroundManager.setBorderColor(position, color, alpha);
public void setBorderColor(int position, long color) {
mReactBackgroundManager.setBorderColor(position, color);
}

public void setBorderRadius(float borderRadius) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public void scrollToEnd(
* @param color
*/
@ReactProp(name = "endFillColor", defaultInt = Color.TRANSPARENT, customType = "Color")
public void setBottomFillColor(ReactHorizontalScrollView view, int color) {
public void setBottomFillColor(ReactHorizontalScrollView view, long color) {
view.setEndFillColor(color);
}

Expand Down Expand Up @@ -291,11 +291,9 @@ public void setBorderWidth(ReactHorizontalScrollView view, int index, float widt
"borderBottomColor"
},
customType = "Color")
public void setBorderColor(ReactHorizontalScrollView view, int index, Integer color) {
float rgbComponent =
color == null ? YogaConstants.UNDEFINED : (float) ((int) color & 0x00FFFFFF);
float alphaComponent = color == null ? YogaConstants.UNDEFINED : (float) ((int) color >>> 24);
view.setBorderColor(SPACING_TYPES[index], rgbComponent, alphaComponent);
public void setBorderColor(ReactHorizontalScrollView view, int index, Long color) {
long borderColor = color == null ? 0 : color;
view.setBorderColor(SPACING_TYPES[index], borderColor);
}

@ReactProp(name = "overflow")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
Expand Down Expand Up @@ -96,8 +97,7 @@ public class ReactScrollView extends ScrollView
private boolean mSendMomentumEvents;
private @Nullable FpsListener mFpsListener = null;
private @Nullable String mScrollPerfTag;
private @Nullable Drawable mEndBackground;
private int mEndFillColor = Color.TRANSPARENT;
private long mEndFillColor = Color.pack(Color.TRANSPARENT);
private boolean mDisableIntervalMomentum = false;
private int mSnapInterval = 0;
private @Nullable List<Integer> mSnapOffsets;
Expand Down Expand Up @@ -620,11 +620,12 @@ public void setStateWrapper(StateWrapper stateWrapper) {

@Override
public void draw(Canvas canvas) {
if (mEndFillColor != Color.TRANSPARENT) {
if (mEndFillColor != Color.pack(Color.TRANSPARENT)) {
final View contentView = getContentView();
if (mEndBackground != null && contentView != null && contentView.getBottom() < getHeight()) {
mEndBackground.setBounds(0, contentView.getBottom(), getWidth(), getHeight());
mEndBackground.draw(canvas);
if (contentView != null && contentView.getBottom() < getHeight()) {
Paint paint = new Paint();
paint.setColor(mEndFillColor);
canvas.drawRect(0, contentView.getBottom(), getWidth(), getHeight(), paint);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we do this if we are creating mEndBackground from new color?

Copy link
Contributor Author

@ryanlntn ryanlntn Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was an oversight. I meant to remove mEndBackground as we need to draw on the canvas directly in order to use paint.

}
}
getDrawingRect(mRect);
Expand Down Expand Up @@ -1003,10 +1004,9 @@ private int getSnapInterval() {
return getHeight();
}

public void setEndFillColor(int color) {
public void setEndFillColor(long color) {
if (color != mEndFillColor) {
mEndFillColor = color;
mEndBackground = new ColorDrawable(mEndFillColor);
}
}

Expand Down Expand Up @@ -1198,12 +1198,16 @@ public void setBackgroundColor(int color) {
mReactBackgroundManager.setBackgroundColor(color);
}

public void setBackgroundColor(long color) {
mReactBackgroundManager.setBackgroundColor(color);
}

public void setBorderWidth(int position, float width) {
mReactBackgroundManager.setBorderWidth(position, width);
}

public void setBorderColor(int position, float color, float alpha) {
mReactBackgroundManager.setBorderColor(position, color, alpha);
public void setBorderColor(int position, long color) {
mReactBackgroundManager.setBorderColor(position, color);
}

public void setBorderRadius(float borderRadius) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void setPagingEnabled(ReactScrollView view, boolean pagingEnabled) {
* @param color
*/
@ReactProp(name = "endFillColor", defaultInt = Color.TRANSPARENT, customType = "Color")
public void setBottomFillColor(ReactScrollView view, int color) {
public void setBottomFillColor(ReactScrollView view, long color) {
view.setEndFillColor(color);
}

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

@ReactProp(name = "overflow")
Expand Down