react-native-reanimated icon indicating copy to clipboard operation
react-native-reanimated copied to clipboard

feat(Worklets): support for cloning Set and Map

Open tjzel opened this issue 9 months ago • 0 comments

Summary

Adding the possibility to clone Map and Set without init function tricks. Cloning works only from RN Runtime to the UI Runtime, do we want to make it symmetric even with legacy bundling?

I'm waiting to merge #7598 first so I can add relevant runtime checks.

Test plan

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { runOnUI } from 'react-native-worklets';

export default function EmptyExample() {
  const map = new Map<unknown, unknown>([
    [1, 1],
    ['2', '2'],
    [{ 3: 3 }, { 3: 3 }],
  ]);

  const set = new Set<unknown>([1, '2', { 3: 3 }]);

  React.useEffect(() => {
    runOnUI(() => {
      console.log('Map:', map);
      for (const [key, value] of map) {
        console.log('Key:', key, 'Value:', value);
      }

      console.log('Set', set);
      for (const value of set) {
        console.log('Value:', value);
      }
    })();
  });
  return (
    <View style={styles.container}>
      <Text>Hello world!</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
});

Screenshot 2025-06-16 at 16 29 40

tjzel avatar Mar 10 '25 14:03 tjzel