Skip to content

Conversation

@armenbadalyan
Copy link
Contributor

@armenbadalyan armenbadalyan commented Dec 30, 2018

Slider component is relying on transform: [{ rotate: '90deg' }] style to implement vertical orientation. This seems to cause issues similar to the ones described in #1281. This PR refactors the Slider component to use flexbox layout thus making Slider size and position more predictable in both vertical and horizontal orientations.

@armenbadalyan armenbadalyan changed the title Fix common vertical slider orientation issues by using flexbox for sl… Slider flexbox layout Dec 30, 2018
@iRoachie
Copy link
Collaborator

Can you resolve the conflicts?

@codecov
Copy link

codecov bot commented Dec 31, 2018

Codecov Report

Merging #1698 into next will increase coverage by 7.16%.
The diff coverage is 95%.

Impacted file tree graph

@@            Coverage Diff             @@
##             next    #1698      +/-   ##
==========================================
+ Coverage   87.74%   94.91%   +7.16%     
==========================================
  Files          33       33              
  Lines         555      570      +15     
  Branches       68       73       +5     
==========================================
+ Hits          487      541      +54     
+ Misses         57       25      -32     
+ Partials       11        4       -7
Impacted Files Coverage Δ
src/slider/Slider.js 88.13% <95%> (+39.59%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 940c407...1c33879. Read the comment docs.

@Monte9
Copy link
Collaborator

Monte9 commented Jan 5, 2019

@armenbadalyan changes make sense to me. Thanks for taking the time to fix it and submit a PR! 💯

I see you wrote additional tests for it as well. Great job!

Although have you tested the vertical orientation of the slider. Usually it helps to include a screenshot of the change/component so we can visualize what it looks like.

I tried your code locally and I wasn't able to get the vertical slider to work. Here's what I did:

Horizontal slider:

screen shot 2019-01-05 at 3 23 41 pm

<Slider orientation="horizontal"
  minimumValue={0}
  maximumValue={100}
  minimumTrackTintColor="blue"
  maximumTrackTintColor="black"
  trackStyle={{ height: 7, borderRadius: 5 }}
  thumbStyle={{ backgroundColor: 'green', width: 30, height: 30, borderRadius: 15 }}
  value={this.state.value}
  onValueChange={(value) => this.setState({ value })}
  style={{ marginHorizontal: 20 }}
  step={10}
/>

Then I changed the orientation prop to "vertical" to the above code snippet and got this:

screen shot 2019-01-05 at 3 24 47 pm

Let me know if I might have missed something or did something wrong. Also it would help if you can include a code snippet that shows horizontal/vertical so anyone can just c/p it and try it out.

@armenbadalyan
Copy link
Contributor Author

armenbadalyan commented Jan 6, 2019

@Monte9 , thank you for taking the time to review my PR. In horizontal orientation, since the width in your example was not specified explicitly, according to react-native layout rules it takes 100% of the parent container width. In vertical orientation one should specify the height either explicitly or using flexbox layout. In other words it behaves just like a regular View.
Here's an example of vertically oriented slider:

<Slider
        orientation="vertical"
        minimumValue={0}
        maximumValue={100}
        minimumTrackTintColor="blue"
        maximumTrackTintColor="black"
        trackStyle={{ height: 7, borderRadius: 5 }}
        thumbStyle={{
          backgroundColor: "green",
          width: 30,
          height: 30,
          borderRadius: 15
        }}
        value={this.state.value}
        onValueChange={value => this.setState({ value })}
        style={{ height: 200 }}
        step={10}
      />

@Monte9
Copy link
Collaborator

Monte9 commented Jan 13, 2019

Ah that makes sense. Thanks for the detailed explanation.
screen shot 2019-01-13 at 10 55 19 am

Looks good on my end. Lets just make sure we add a note on the docs mentioning that when in "vertical" orientation, height is also required.

Copy link
Collaborator

@Monte9 Monte9 left a comment

Choose a reason for hiding this comment

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

lgtm

@Monte9
Copy link
Collaborator

Monte9 commented Jan 13, 2019

Also appreciate you submitting the PR! We use OpenCollective to give back to contributors like yourself so I'd be happy to send $20 your way for your efforts. Let me know if this sounds good to you and I can tell you how to submit your expense.

@iRoachie
Copy link
Collaborator

Are we waiting on the change to the docs ?

@iRoachie iRoachie merged commit e2555a6 into react-native-elements:next Jan 17, 2019
@iRoachie
Copy link
Collaborator

Thanks again @armenbadalyan 💯

@armenbadalyan
Copy link
Contributor Author

Thank you guys, it was my pleasure :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants