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

Animated: Restore AnimatedNode.prototype.toJSON #46498

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ describe('Animated tests', () => {
expect(anim.__getValue()).toBe(15);
});

it('convert to JSON', () => {
expect(JSON.stringify(new Animated.Value(10))).toBe('10');
});

it('bypasses `setNativeProps` in test environments', async () => {
const opacity = new Animated.Value(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,12 @@ export default class AnimatedNode {
__setPlatformConfig(platformConfig: ?PlatformConfig) {
this._platformConfig = platformConfig;
}

/**
* NOTE: This is intended to prevent `JSON.stringify` from throwing "cyclic
* structure" errors in React DevTools. Avoid depending on this!
*/
toJSON(): mixed {
return this.__getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ exports[`public API should not change unintentionally Libraries/Animated/nodes/A
__getNativeConfig(): Object;
__getPlatformConfig(): ?PlatformConfig;
__setPlatformConfig(platformConfig: ?PlatformConfig): void;
toJSON(): mixed;
}
"
`;
Expand Down
Loading