question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

percentage support for transform translate

See original GitHub issue

Description

3f49e74 added support for percentages in some style properties, and its awesome. we should also have support for transform translates.

Reproduction

I want to absolutely position a view and center it vertically. I can now do top: '50%', but thats not centered. To make it centered I would also need transform: [{translateY: '50%'}].

Solution

Add support for percentages for translates

Additional Information

  • React Native version: 0.42.3
  • Platform: iOS
  • Development Operating System: MacOS
  • Dev tools: Xcode

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:28
  • Comments:25 (4 by maintainers)

github_iconTop GitHub Comments

21reactions
pviniscommented, May 26, 2017

i think it is important, since we have percentages for the top-level styles, to also have it for transforms.

3reactions
leggomuhgreggocommented, Feb 14, 2018

Example Workaround with RN onLayout event:

class Foo extends Component {
  ...
  onLayout = event => {
    const { width } = event.nativeEvent.layout;
    this.setState({ myWidth: width });
  };
  ...
  render() {
    const { myWidth } = this.state;

    return(
      <View
        onLayout={this.onLayout}
        style={{transform: [{translateY: myWidth / 2 }]}}>
          ...
      <View/>
    )
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

translate() - CSS: Cascading Style Sheets - MDN Web Docs
This value describes two <length> or <percentage> values representing both the abscissa (x-coordinate) and the ordinate (y-coordinate) of the ...
Read more >
Translate X and Y percentage values based on elements ...
CSS translation by percentage takes the % of the element that is being translated to figure the distance to move. It does not...
Read more >
CSS transform translate seems to only work with pixels ...
css > transform > translateY seems to only work with pixel values and ... Percentage-based transforms are based on the size of the...
Read more >
Forums - CSS - transform translate percentages and Android
This is odd, since transform percentages are specified as relating to the full box model of the element being transformed — and computed...
Read more >
Transforms
Transforms are style properties that will help you modify the appearance and position of your components using 2D or 3D transformations.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found