Skip to content

Commit

Permalink
fix(🐛): Fix Android bug when dealing with string animated values (#311)
Browse files Browse the repository at this point in the history
This PR takes @msand and @osdnk  from #176 into consideration.

fixes #300
  • Loading branch information
wcandillon authored and kmagiera committed Sep 26, 2019
1 parent c9ce607 commit 89bf75e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ public class PropsNode extends Node implements FinalNode {
private final JavaOnlyMap mPropMap;
private final ReactStylesDiffMap mDiffMap;

private static void addProp(WritableMap propMap, String key, Object value) {
if (value == null) {
propMap.putNull(key);
} else if (value instanceof Double) {
propMap.putDouble(key, (Double) value);
} else if (value instanceof Integer) {
propMap.putInt(key, (Integer) value);
} else if (value instanceof Number) {
propMap.putDouble(key, ((Number) value).doubleValue());
} else if (value instanceof Boolean) {
propMap.putBoolean(key, (Boolean) value);
} else if (value instanceof String) {
propMap.putString(key, (String) value);
} else if (value instanceof WritableArray) {
propMap.putArray(key, (WritableArray)value);
} else if (value instanceof WritableMap) {
propMap.putMap(key, (WritableMap)value);
} else {
throw new IllegalStateException("Unknown type of animated value");
}
}

public PropsNode(
int nodeID,
ReadableMap config,
Expand Down Expand Up @@ -89,12 +111,13 @@ protected Double evaluate() {
}
} else {
String key = entry.getKey();
Object value = node.value();
if (mNodesManager.uiProps.contains(key)) {
hasUIProps = true;
mPropMap.putDouble(key, node.doubleValue());
addProp(mPropMap, key, value);
} else {
hasNativeProps = true;
nativeProps.putDouble(key, node.doubleValue());
addProp(nativeProps, key, value);
}
}
}
Expand Down
8 changes: 1 addition & 7 deletions react-native-reanimated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,7 @@ declare module 'react-native-reanimated' {
): void

// configuration

// `addWhitelistedNativeProps` will likely be removed soon, and so is
// intentionally not exposed to TypeScript. If it is needed, it could be
// uncommented here, or just use
// `(Animated as any).addWhitelistedNativeProps({ myProp: true });`

// addWhitelistedNativeProps(props: { [key: string]: true }): void;
export function addWhitelistedNativeProps(props: { [key: string]: true }): void;
}

export default Animated;
Expand Down

0 comments on commit 89bf75e

Please sign in to comment.