Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IOS] Animate a views left position affect the size of its child text components #20215

Closed
jacobrosenskold opened this issue Jul 15, 2018 · 2 comments
Labels
Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.

Comments

@jacobrosenskold
Copy link

Environment

Environment:
  OS: macOS High Sierra 10.13.5
  Node: 9.3.0
  Yarn: Not Found
  npm: 5.6.0
  Watchman: 4.9.0
  Xcode: Xcode 9.4.1 Build version 9F2000
  Android Studio: 3.1 AI-173.4670197

Packages: (wanted => installed)
  react: ^16.4.1 => 16.4.1
  react-native: ^0.55.4 => 0.55.4

Description

I'm trying to animate a views left position using an Animated.View component. The view contains some different components but for simplicity I've only included two text components wrapped in an extra view.
The problem is that when animating the left position to a minus value to move the view out of the screen a bit, the text components size reduces and the text gets truncated. If I remove the view that wrappes the text components, it works as expected, i.e. the text size doesn't change.

First it looks likes
skarmavbild 2018-07-15 kl 22 19 36

After pressing the button twice, i.e. animating the left position to -100 and then back to 0 it looks like
skarmavbild 2018-07-15 kl 22 19 52

Reproducible Demo

export default class Screen extends Component {
  anim = new Animated.Value(0);
  isLeft = true;

  render() {
    return (
      <View>
        <TouchableOpacity
          onPress={() => {
            Animated.timing(this.anim, {
              toValue: this.isLeft ? -100 : 0,
              duration: 500
            }).start();
            this.isLeft = !this.isLeft;
          }}
        >
          <Text>Animate left position</Text>
        </TouchableOpacity>

        <Animated.View
          style={{
            left: this.anim, // same effect if changed to marginLeft.
            height: 44,
            alignItems: 'flex-start',
            backgroundColor: 'grey',
            paddingHorizontal: 15,
            marginTop: 5
          }}
        >
          <View>
            <Text style={{ backgroundColor: 'rgb(255, 0, 0)' }}>This is some text</Text>
            <Text style={{ backgroundColor: 'rgb(0, 255, 51)' }}>More text</Text>
          </View>
        </Animated.View>
      </View>
    );
  }
}
@mysport12
Copy link
Contributor

Instead of using ‘left’, try using ‘translatex’. It worked for us in our swipeable component that faced the same issue you reported here.

style={{ transform: [{ translateX: contentPosition }] }}

@jacobrosenskold
Copy link
Author

That worked. Thank you very much!

@facebook facebook locked as resolved and limited conversation to collaborators Jul 18, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

3 participants