-
Hi, I just found out that the issue requesting for First, here's reproducible code for following issues:import { Button, StyleSheet, Text, View } from 'react-native';
import { useState } from 'react';
import { runOnJS, runOnUI, useSharedValue } from 'react-native-reanimated';
export default function HomeScreen() {
const testSet = useSharedValue<Set<string> | undefined>(undefined);
const [isSetObject, setIsSetObject] = useState<boolean | undefined>();
function fromJS() {
// This always crashes
testSet.value = new Set([]);
}
function fromUI() {
runOnUI(() => {
testSet.value = new Set([]);
})();
}
function checkFromUI() {
runOnUI(() => {
if (testSet.value == null) {
runOnJS(setIsSetObject)(undefined);
} else if (testSet.value.has == null) {
runOnJS(setIsSetObject)(false);
} else {
runOnJS(setIsSetObject)(true);
}
})();
}
function checkFromJS() {
if (testSet.value == null) {
setIsSetObject(undefined);
} else if (testSet.value.has == null) {
setIsSetObject(false);
} else {
setIsSetObject(true);
}
}
return (
<View style={styles.container}>
<Text style={styles.text}>
Set?{' '}
{isSetObject == null ? 'undefined' : isSetObject ? 'True' : 'False'}
</Text>
<Button title={'Assign from UI'} onPress={fromUI} />
<Button title={'Assign from JS (this crashes)'} onPress={fromJS} />
<Button title={'Check from UI'} onPress={checkFromUI} />
<Button title={'Check from JS'} onPress={checkFromJS} />
</View>
);
}
const styles = StyleSheet.create({
container: {
paddingTop: 80,
paddingHorizontal: 24,
alignItems: 'center',
},
text: {
fontSize: 32,
backgroundColor: '#dedede',
},
}); Assigning
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @thisisgit! The problem starts to happen when you want to access
You are right, they are supported only on a single runtime, so when you create them in worklets (on the UI runtime), they cannot be used in the JS runtime.
We may add support for this in the future, but currently we are focused on other things so it may take some time. For now, you can use a JS object instead of |
Beta Was this translation helpful? Give feedback.
Hey @thisisgit!
You can use
Set
andMap
only a single runtime at a time and transfer it between runtimes. That is why you can assignSet
to a SharedValue on the UI runtime (within therunOnUI
callback) and use all its methods. The same happens if you are usingSet
orMap
only on JS.The problem starts to happen when you want to access
Set
/Map
from the JS runtime when the object lives on the UI runtime (was created within a worklet executed on the UI thread) or access the object created in the JS runtime from the UI thread.You are right, they are support…