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

Workletize top-level functions in a file with 'worklet' directive #5554

Merged
merged 21 commits into from
Jul 17, 2024
Merged
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 @@ -68,6 +68,12 @@ export default function RuntimeTestsExample() {
// require('./tests/advancedAPI/measure.test'); // crash on Android
},
},
{
testSuiteName: 'babelPlugin',
importTest: () => {
require('./tests/plugin/fileWorkletization.test');
},
},
{
skipByDefault: true,
testSuiteName: 'self-tests',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { useEffect } from 'react';
import { View } from 'react-native';
import { useSharedValue, runOnUI } from 'react-native-reanimated';
import {
render,
wait,
describe,
getRegisteredValue,
registerValue,
test,
expect,
} from '../../ReanimatedRuntimeTestsRunner/RuntimeTestsApi';
import { getThree } from './fileWorkletization';

const SHARED_VALUE_REF = 'SHARED_VALUE_REF';

describe('Test workletization', () => {
const ExampleComponent = () => {
const output = useSharedValue<number | null>(null);
registerValue(SHARED_VALUE_REF, output);

useEffect(() => {
runOnUI(() => {
output.value = getThree();
})();
});

return <View />;
};

test('Test file workletization', async () => {
await render(<ExampleComponent />);
await wait(100);
const sharedValue = await getRegisteredValue(SHARED_VALUE_REF);
expect(sharedValue.onUI).toBe(3);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'worklet';

const getOne = () => {
return 1;
};

const getterContainer = {
getTwo: () => {
return 2;
},
};

export const getThree = () => {
return getOne() + getterContainer.getTwo();
};
Loading
Loading