React-native-reanimated: `concat` issue with Integer Value on Android

Created on 23 Mar 2020  路  6Comments  路  Source: software-mansion/react-native-reanimated

Hi, first of all, thanks for the great work.
I'm trying to use the concat function to animate a text using ReText component from react-native-redash,
but look like the concat function always add ".0" to the end of the animated number node on Android .

My Code

const price = new Value(44);
const MyString = concat('$', price);  

Epcpectd Result

MyString should be $44

Result

IOS : $44
Android : $44.0

Note: The problem is Not related to Retext Component, I tried passing the MyString value to the javascript side using call function and noticed the same behavior.

Most helpful comment

Hi @yjose,
thanks for submitting this issue!
I confirmed it's reproducible.
Your workaround could be improved by using Double values directly, I'll prepare PR for this one.

All 6 comments

I think this is related to this issue in react-native. Since there is still only Number in ReadableType, one can't tell react-native to return the string representation of an integer.

I did manage to fix the issue by updating the evaluate method in ConcatNode implementation on Android
https://github.com/software-mansion/react-native-reanimated/blob/master/android/src/main/java/com/swmansion/reanimated/nodes/ConcatNode.java#L15

@Override
  protected String evaluate() {
     StringBuilder builder = new StringBuilder();
     for (int i = 0; i < mInputIDs.length; i++) {
       Node inputNodes = mNodesManager.findNodeById(mInputIDs[i], Node.class);
      String a = String.valueOf(inputNodes.value());
      if(a.endsWith(".0")) {
         a = a.substring(0, a.length() - 2);
       }
       builder.append(a);
     }
     return builder.toString();
  }

I know is not the best solution but At least it fixed my issue 馃榿.

Glad you found a workaround, don't think it's bad at all, given the limitations :)

@osdnk, @kmagiera Do you think my Solution deserve a PR, Any feedBack

Hi @yjose,
thanks for submitting this issue!
I confirmed it's reproducible.
Your workaround could be improved by using Double values directly, I'll prepare PR for this one.

Thanks, @yjose @jakub-gonet, I just tried your PR and it works great!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dinhmai74 picture dinhmai74  路  3Comments

jwhscholten picture jwhscholten  路  4Comments

mrousavy picture mrousavy  路  3Comments

robertgonzales picture robertgonzales  路  3Comments

sa8ab picture sa8ab  路  3Comments