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.

[Android] Incorrect visual initialization of transform scale 0

See original GitHub issue

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Environment: OS: macOS High Sierra Node: 8.7.0 Yarn: 1.3.2 npm: 5.5.1 Xcode: Xcode 9

Packages: (wanted => installed) react-native: 0.49.3 => 0.49.3 react: 16.0.0

Target Platform: Android (7)

Initializing a component with transform: [{scale: 0}] visually initializes it as transfrom: [{scale: 1}]. However, when animating the component it animates as if the initial value was actually 0. Using a float (0.0) doesn’t work either.

The example code below demonstrates this problem. Tested on Android.

Initially pressing “Animate to 0” doesn’t animate the first box at all because its “real” scale is 0. Pressing the other two texts makes it jump to 0 and animate to x from there.

The example also shows how normal components look visually identical when given scales of 0 and 1.

Expected Behavior

Initializing a component with scale: 0 should result in an invisible component

Actual Behavior

Component is visualized with scale: 1

Reproducible Demo

import React, {
  Animated,
  Component,
  StyleSheet,
  Text,
  View,
} from "react-native";

export default class TransformExample extends Component {
  constructor() {
    super(arguments[0]);
    this.state = {
      value1: new Animated.Value(0),
      value2: new Animated.Value(0.5),
      value3: new Animated.Value(1),
    }
  }

  animateTo(val) {
    Animated.spring(this.state.value1, {toValue: val}).start();
    Animated.spring(this.state.value2, {toValue: val}).start();
    Animated.spring(this.state.value3, {toValue: val}).start();
  };

  render() {
    const boxStyle = {
      width: 150,
      height: 50,
      backgroundColor: "#3fc6ae",
      margin: 10,
    }

    return (
      <View style={{alignItems: "center"}}>
        <Text onPress={() => this.animateTo(0)}>Animate to 0</Text>
        <Text onPress={() => this.animateTo(1)}>Animate to 1</Text>
        <Text onPress={() => this.animateTo(1.2)}>Animate to 1.2</Text>

        <Animated.Text style={[
          boxStyle,
          {transform: [{scale: this.state.value1}]}
        ]}>
          Initial scale: 0
        </Animated.Text>

        <Animated.Text style={[
          boxStyle,
          {transform: [{scale: this.state.value2}]}
        ]}>
          Initial scale: 0.5
        </Animated.Text>

        <Animated.Text style={[
          boxStyle,
          {transform: [{scale: this.state.value3}]}
        ]}>
          Initial scale: 1
        </Animated.Text>

        <Text style={[
          boxStyle,
          {transform: [{scale: 0}]}
        ]}>
          Fixed scale: 0
        </Text>

        <Text style={[
          boxStyle,
          {transform: [{scale: 1}]}
        ]}>
          Fixed scale: 1
        </Text>
      </View>
    )
  }
}

Reopened from #6278

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:14
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
Annihilcommented, Feb 26, 2018

Issue still there in v0.53.0

3reactions
chrismllrcommented, Jan 9, 2018

I am also experiencing the issue - adding opacity to pair with the transform seems to fix the issue for the time being.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Transform scale animation begins from wrong position
The animation begins from the position that is defined by top and left properties and it doesn't take into account transform: translate(-50%, - ......
Read more >
CaptureResult - Android Developers
The transform should keep the magnitude of the output color values within [0, 1.0] (assuming input color values is within the normalized range...
Read more >
Changelog for Web SDK - Braze
Fixed an issue where sites with globally-scoped svg and img CSS caused certain elements of the built-in UI to display incorrectly. 4.5.0. Added....
Read more >
Instantiating Prefabs at run time - Unity - Manual
Sin(angle) * radius; Vector3 pos = transform.position + new Vector3(x, 0, z); float angleDegrees = -angle*Mathf.Rad2Deg; Quaternion rot = Quaternion.Euler(0 ...
Read more >
Unity 2022.2.0
Unity 2022.2.0 download and release notes. ... Android: Added new PlayerSettings Resolution Scaling Mode ... Core: Added Transform.
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