React-native: percentage support for transform translate

Created on 23 Mar 2017  路  25Comments  路  Source: facebook/react-native

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
Locked

Most helpful comment

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

All 25 comments

We're cutting down on the number of outstanding issues, in order to allow us to focus. I'm closing this issue because it has been open for over 60 days with no activity. If you think it should still be opened let us know why. PRs are always welcome.

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

It seems like this is more of an enhancement request, which we track using Canny.io.

+1 for this

100% need this!

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1 please update on this issue

+1 this is a huge deal when attempting fluid layouts for Android devices in particular.

+1

+1

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/>
    )
  }
}

+1

+1

+1

+1

Was this page helpful?
0 / 5 - 0 ratings