[iOS] interpolateColor - Attempt to assign to readonly property
See original GitHub issueDescription
When you try to render a component with some color interpolation using interpolateColor after another component with color interpolation is already rendered you get an error - Attempt to assign to readonly property.

This only happens on iOS.
Expected behavior
You shouldn’t get this error on iOS.
Actual behavior & steps to reproduce
Render some component that uses interpolateColor and then render another component that also uses interpolateColor in a few seconds, for example. This also works for different screens in the navigation stack.
Snack or minimal code example
Here is a reproducible demo: https://github.com/yaroslavnikiforov/InterpolateColor/tree/main/android
Code example:
import React, {useState, useEffect} from 'react';
import {StyleSheet} from 'react-native';
import Animated, {
useAnimatedStyle,
useSharedValue,
interpolateColor,
} from 'react-native-reanimated';
const styles = StyleSheet.create({
container: {flex: 1},
});
export default function App() {
const [isVisible, setIsVisible] = useState(false);
useEffect(() => {
setTimeout(() => setIsVisible(true), 3000);
}, []);
return (
<>
<BlockOne />
{isVisible ? <BlockTwo /> : null}
</>
);
}
function BlockOne() {
const animatedValue = useSharedValue(300);
const animatedStyles = useAnimatedStyle(() => {
const backgroundColor = interpolateColor(
animatedValue.value,
[0, 234, 468],
['red', 'orange', 'yellow'],
);
return {backgroundColor};
}, [animatedValue]);
return <Animated.View style={[styles.container, animatedStyles]} />;
}
function BlockTwo() {
const animatedValue = useSharedValue(0.3);
const animatedStyles = useAnimatedStyle(() => {
const backgroundColor = interpolateColor(
animatedValue.value,
[0, 1],
['green', 'cyan'],
);
return {backgroundColor};
}, [animatedValue]);
return <Animated.View style={[styles.container, animatedStyles]} />;
}
Package versions
- React Native: 0.66.4 (the same with 0.63.4)
- React Native Reanimated: ^2.3.0
- NodeJS: 14.15.0
- Xcode: 13.1
- Java & Gradle: 15.0.2 & 6.7.1
Affected platforms
- iOS
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Attempted to assign to read only property on using Animated ...
Once I Stopped doing interpolate multiple times on the same value and made it independent of state, the error went away. Share.
Read more >Attempted to assign to readonly property react native ... - abc-baltin.de
But this throws the attempted to assign to read-only property exception: const ... using interpolateColor after another component with color. import React, ...
Read more >"Attempted to assign to readonly property." iOS 8 TypeError
A webkit bug that shipped in iOS 8 beta 5 and appears to have been partially included in the launch of iOS 8...
Read more >Safari Technology Preview Release Notes - Apple Developer
Added support for AVIF images on macOS Ventura and iOS 16 (251850@main) ... Added support for interpolating colors with “missing”/“none” components via ...
Read more >visibility - CSS: Cascading Style Sheets - MDN Web Docs
The visibility CSS property shows or hides an element without changing the layout of a document. The property can also hide rows or...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Same as https://github.com/software-mansion/react-native-reanimated/issues/2329. It seems like enabling hermes fixes that (https://github.com/software-mansion/react-native-reanimated/issues/2329#issuecomment-981553091), if that’s not an option for you, you can apply a patch (orig - https://github.com/software-mansion/react-native-reanimated/issues/2329#issuecomment-907619489) until the issue is resolved, didn’t notice any issues in production.
Duplicate of: https://github.com/software-mansion/react-native-reanimated/issues/2329 I will try to fix it soon. Please be patient 🙏