react-native-wheel-picker icon indicating copy to clipboard operation
react-native-wheel-picker copied to clipboard

how to change seperator line color

Open mostafaolyai opened this issue 6 years ago • 17 comments

how to change seperator line color? tnx

mostafaolyai avatar May 08 '18 16:05 mostafaolyai

how to change seperator line color?

danaee123 avatar May 09 '18 09:05 danaee123

yes default color is white

mostafaolyai avatar May 10 '18 05:05 mostafaolyai

I think you can change the color only by editing directly the node_package which is anti pattern.

try editing your ReactWheelCurvedPicker.java

...
    @Override
    protected void drawForeground(Canvas canvas) {
        super.drawForeground(canvas);

        Paint paint = new Paint();
        paint.setColor(Color.WHITE); // try changing this to Color.BLACK
        int colorFrom = 0x00FFFFFF;//Color.BLACK;
        int colorTo = Color.WHITE;
        LinearGradient linearGradientShader = new LinearGradient(rectCurItem.left, rectCurItem.top, rectCurItem.right/2, rectCurItem.top, colorFrom, colorTo, Shader.TileMode.MIRROR);
        paint.setShader(linearGradientShader);
        canvas.drawLine(rectCurItem.left, rectCurItem.top, rectCurItem.right, rectCurItem.top, paint);
        canvas.drawLine(rectCurItem.left, rectCurItem.bottom, rectCurItem.right, rectCurItem.bottom, paint);
    }
...

I solved this issue by rendering a view with absolute position and styled borders top of the picker... which isn't good solution either.

jollimies avatar May 16 '18 10:05 jollimies

ill try this dude, tnx

mostafaolyai avatar May 19 '18 14:05 mostafaolyai

@jollimies one question when you edit this , line sep show correctly in ios & android?

mostafaolyai avatar May 19 '18 14:05 mostafaolyai

 @Override
    protected void drawForeground(Canvas canvas) {
        super.drawForeground(canvas);

        Paint paint = new Paint();
        paint.setColor(Color.BLACK); // change this 
        int colorFrom = 0x00FFFFFF;//Color.BLACK;
        int colorTo = Color.BLACK;  // change this 
        LinearGradient linearGradientShader = new LinearGradient(rectCurItem.left, rectCurItem.top, rectCurItem.right/2, rectCurItem.top, colorFrom, colorTo, Shader.TileMode.MIRROR);
        paint.setShader(linearGradientShader);
        canvas.drawLine(rectCurItem.left, rectCurItem.top, rectCurItem.right, rectCurItem.top, paint);
        canvas.drawLine(rectCurItem.left, rectCurItem.bottom, rectCurItem.right, rectCurItem.bottom, paint);
    }

for someone wants to change their border, you have to edit paint.setColor(Color.BLACK); // change this and int colorTo = Color.BLACK; // change this.

why?

 LinearGradient linearGradientShader = new LinearGradient(rectCurItem.left, rectCurItem.top, rectCurItem.right/2, rectCurItem.top, colorFrom, colorTo, Shader.TileMode.MIRROR);
        paint.setShader(linearGradientShader);

here is the key

Foveluy avatar Sep 01 '18 14:09 Foveluy

能不能加个props修改分隔线的颜色呢?作者不维护这个项目了吗? @lesliesam

KingAmo avatar Sep 17 '18 08:09 KingAmo

Has anyone been successful in updating the border colors by going into the Java file? I've tweaked it using different standard colors but it doesn't have any visible effect.

I'm also trying to update the itemSpace but that's a whole different can of worms.

mikeyamato avatar Dec 21 '18 23:12 mikeyamato

@mikeyamato check out the code i posted above

Foveluy avatar Dec 22 '18 10:12 Foveluy

@mikeyamato check out the code i posted above

@Foveluy I did but without success. That's why I was wondering if anyone was able to change it.

I changed the color from white to red but what I'm seeing (iOS) is still unchanged.

screen shot 2018-12-22 at 5 38 47 pm

screen shot 2018-12-22 at 5 39 15 pm

mikeyamato avatar Dec 23 '18 01:12 mikeyamato

@Foveluy out of curiosity were you able to update the line color in iOS or are you working with Android only?

mikeyamato avatar Dec 26 '18 20:12 mikeyamato

@mikeyamato very interesting. can you post all drawForeground function out?

i update this line color in Android for sure.

Foveluy avatar Dec 27 '18 15:12 Foveluy

@Foveluy I wonder if this is a iOS vs Android limitation.

As requested...

protected void drawForeground(Canvas canvas) {
    super.drawForeground(canvas);

    Paint paint = new Paint();
    paint.setColor(Color.RED);  // originally 'Color.WHITE'
    int colorFrom = 0x00FFFFFF;//Color.BLACK;
    int colorTo = Color.RED;  // originally 'Color.WHITE'
    LinearGradient linearGradientShader = new LinearGradient(rectCurItem.left, rectCurItem.top, rectCurItem.right/2, rectCurItem.top, colorFrom, colorTo, Shader.TileMode.MIRROR);
    paint.setShader(linearGradientShader);
    canvas.drawLine(rectCurItem.left, rectCurItem.top, rectCurItem.right, rectCurItem.top, paint);
    canvas.drawLine(rectCurItem.left, rectCurItem.bottom, rectCurItem.right, rectCurItem.bottom, paint);
}

mikeyamato avatar Dec 29 '18 01:12 mikeyamato

I took a look at PR #8 and even changed my code to how it was done but was unsuccessful 🙁

mikeyamato avatar Jan 01 '19 03:01 mikeyamato

Okay, so the following solution is a temporary solution for iOS that worked for me. You'll need to go into the RCTPicker.m file through the following path: */node_modules/react-native/React/Views/RCTPicker.m

Right below the line label.font = _font; place the following:

pickerView.subviews[1].backgroundColor = [UIColor darkGrayColor];
pickerView.subviews[2].backgroundColor = [UIColor darkGrayColor];

You'll need to stop your current Metro Bundler process then re-start react-native run-ios.

Although I'm using darkGray you can find additional color options here.

Just remember, since this is saved to your node_modules anytime you re-install you'll need to repeat this process.

screen shot 2019-01-05 at 10 27 51 am

mikeyamato avatar Jan 05 '19 21:01 mikeyamato

Has anyone been successful in updating the separator color ??? If so please give the solution

AarshOza avatar Jan 23 '19 07:01 AarshOza

Has anyone been successful in updating the separator color ??? If so please give the solution

I have forked and exposed the line color, and gradient start, gradient end (if gradient is necessary. otherwise solid color can be set from line color prop) as react props. check this out.

https://github.com/m3rlin94/react-native-wheel-picker

m3rlin94 avatar May 10 '19 07:05 m3rlin94