Skip to content

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

Closed
@jacobrosenskold

Description

@jacobrosenskold

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions