Skip to content

Commit

Permalink
Add lacking transformation of useAnimatedScrollHandler function argum…
Browse files Browse the repository at this point in the history
…ent to plugin (#4355)

## Summary

`useAnimatedScrollHandler` can take a single function as an argument
instead of an object containing functions. Functionality for this
transformation was lacking in plugin and this PR adds it.

I duplicated current tests for `objectHooks` for both
`useAnimatedGestureHandler` and `useAnimatedScrollHandler` to have them
separated and added tests according to this PR.

## Test plan

Run tests and build Example app to see that `useAnimatedScrollHandler`
works properly now.
  • Loading branch information
tjzel committed Apr 12, 2023
1 parent 827f75a commit 7a6424a
Show file tree
Hide file tree
Showing 5 changed files with 316 additions and 89 deletions.
240 changes: 160 additions & 80 deletions __tests__/__snapshots__/plugin.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -586,86 +586,6 @@ var foo = function () {
}();"
`;

exports[`babel plugin workletizes object hook wrapped ArrowFunctionExpression automatically 1`] = `
"var _worklet_1022605193782_init_data = {
code: \\"function anonymous(event){console.log(event);}\\",
location: \\"${ process.cwd() }/jest tests fixture\\"
};
useAnimatedGestureHandler({
onStart: function () {
var _e = [new global.Error(), 1, -27];
var _f = function _f(event) {
console.log(event);
};
_f._closure = {};
_f.__initData = _worklet_1022605193782_init_data;
_f.__workletHash = 1022605193782;
_f.__stackDetails = _e;
return _f;
}()
});"
`;

exports[`babel plugin workletizes object hook wrapped ObjectMethod automatically 1`] = `
"var _worklet_338158776260_init_data = {
code: \\"function onStart(event){console.log(event);}\\",
location: \\"${ process.cwd() }/jest tests fixture\\"
};
useAnimatedGestureHandler({
onStart: function () {
var _e = [new global.Error(), 1, -27];
var _f = function _f(event) {
console.log(event);
};
_f._closure = {};
_f.__initData = _worklet_338158776260_init_data;
_f.__workletHash = 338158776260;
_f.__stackDetails = _e;
return _f;
}()
});"
`;

exports[`babel plugin workletizes object hook wrapped named FunctionExpression automatically 1`] = `
"var _worklet_338158776260_init_data = {
code: \\"function onStart(event){console.log(event);}\\",
location: \\"${ process.cwd() }/jest tests fixture\\"
};
useAnimatedGestureHandler({
onStart: function () {
var _e = [new global.Error(), 1, -27];
var _f = function _f(event) {
console.log(event);
};
_f._closure = {};
_f.__initData = _worklet_338158776260_init_data;
_f.__workletHash = 338158776260;
_f.__stackDetails = _e;
return _f;
}()
});"
`;

exports[`babel plugin workletizes object hook wrapped unnamed FunctionExpression automatically 1`] = `
"var _worklet_1022605193782_init_data = {
code: \\"function anonymous(event){console.log(event);}\\",
location: \\"${ process.cwd() }/jest tests fixture\\"
};
useAnimatedGestureHandler({
onStart: function () {
var _e = [new global.Error(), 1, -27];
var _f = function _f(event) {
console.log(event);
};
_f._closure = {};
_f.__initData = _worklet_1022605193782_init_data;
_f.__workletHash = 1022605193782;
_f.__stackDetails = _e;
return _f;
}()
});"
`;

exports[`babel plugin workletizes possibly chained gesture object callback functions automatically 1`] = `
"var _reactNativeGestureHandler = require(\\"react-native-gesture-handler\\");
var _worklet_15393478329680_init_data = {
Expand Down Expand Up @@ -760,3 +680,163 @@ var foo = function () {
return _f;
}();"
`;

exports[`babel plugin workletizes useAnimatedGestureHandler wrapped ArrowFunctionExpression automatically 1`] = `
"var _worklet_1022605193782_init_data = {
code: \\"function anonymous(event){console.log(event);}\\",
location: \\"${ process.cwd() }/jest tests fixture\\"
};
useAnimatedGestureHandler({
onStart: function () {
var _e = [new global.Error(), 1, -27];
var _f = function _f(event) {
console.log(event);
};
_f._closure = {};
_f.__initData = _worklet_1022605193782_init_data;
_f.__workletHash = 1022605193782;
_f.__stackDetails = _e;
return _f;
}()
});"
`;

exports[`babel plugin workletizes useAnimatedGestureHandler wrapped ObjectMethod automatically 1`] = `
"var _worklet_338158776260_init_data = {
code: \\"function onStart(event){console.log(event);}\\",
location: \\"${ process.cwd() }/jest tests fixture\\"
};
useAnimatedGestureHandler({
onStart: function () {
var _e = [new global.Error(), 1, -27];
var _f = function _f(event) {
console.log(event);
};
_f._closure = {};
_f.__initData = _worklet_338158776260_init_data;
_f.__workletHash = 338158776260;
_f.__stackDetails = _e;
return _f;
}()
});"
`;

exports[`babel plugin workletizes useAnimatedGestureHandler wrapped named FunctionExpression automatically 1`] = `
"var _worklet_338158776260_init_data = {
code: \\"function onStart(event){console.log(event);}\\",
location: \\"${ process.cwd() }/jest tests fixture\\"
};
useAnimatedGestureHandler({
onStart: function () {
var _e = [new global.Error(), 1, -27];
var _f = function _f(event) {
console.log(event);
};
_f._closure = {};
_f.__initData = _worklet_338158776260_init_data;
_f.__workletHash = 338158776260;
_f.__stackDetails = _e;
return _f;
}()
});"
`;

exports[`babel plugin workletizes useAnimatedGestureHandler wrapped unnamed FunctionExpression automatically 1`] = `
"var _worklet_1022605193782_init_data = {
code: \\"function anonymous(event){console.log(event);}\\",
location: \\"${ process.cwd() }/jest tests fixture\\"
};
useAnimatedGestureHandler({
onStart: function () {
var _e = [new global.Error(), 1, -27];
var _f = function _f(event) {
console.log(event);
};
_f._closure = {};
_f.__initData = _worklet_1022605193782_init_data;
_f.__workletHash = 1022605193782;
_f.__stackDetails = _e;
return _f;
}()
});"
`;

exports[`babel plugin workletizes useAnimatedScrollHandler wrapped ArrowFunctionExpression automatically 1`] = `
"var _worklet_1022605193782_init_data = {
code: \\"function anonymous(event){console.log(event);}\\",
location: \\"${ process.cwd() }/jest tests fixture\\"
};
useAnimatedScrollHandler({
onScroll: function () {
var _e = [new global.Error(), 1, -27];
var _f = function _f(event) {
console.log(event);
};
_f._closure = {};
_f.__initData = _worklet_1022605193782_init_data;
_f.__workletHash = 1022605193782;
_f.__stackDetails = _e;
return _f;
}()
});"
`;

exports[`babel plugin workletizes useAnimatedScrollHandler wrapped ObjectMethod automatically 1`] = `
"var _worklet_947458829673_init_data = {
code: \\"function onScroll(event){console.log(event);}\\",
location: \\"${ process.cwd() }/jest tests fixture\\"
};
useAnimatedGestureHandler({
onScroll: function () {
var _e = [new global.Error(), 1, -27];
var _f = function _f(event) {
console.log(event);
};
_f._closure = {};
_f.__initData = _worklet_947458829673_init_data;
_f.__workletHash = 947458829673;
_f.__stackDetails = _e;
return _f;
}()
});"
`;

exports[`babel plugin workletizes useAnimatedScrollHandler wrapped named FunctionExpression automatically 1`] = `
"var _worklet_947458829673_init_data = {
code: \\"function onScroll(event){console.log(event);}\\",
location: \\"${ process.cwd() }/jest tests fixture\\"
};
useAnimatedScrollHandler({
onScroll: function () {
var _e = [new global.Error(), 1, -27];
var _f = function _f(event) {
console.log(event);
};
_f._closure = {};
_f.__initData = _worklet_947458829673_init_data;
_f.__workletHash = 947458829673;
_f.__stackDetails = _e;
return _f;
}()
});"
`;

exports[`babel plugin workletizes useAnimatedScrollHandler wrapped unnamed FunctionExpression automatically 1`] = `
"var _worklet_1022605193782_init_data = {
code: \\"function anonymous(event){console.log(event);}\\",
location: \\"${ process.cwd() }/jest tests fixture\\"
};
useAnimatedScrollHandler({
onScroll: function () {
var _e = [new global.Error(), 1, -27];
var _f = function _f(event) {
console.log(event);
};
_f._closure = {};
_f.__initData = _worklet_1022605193782_init_data;
_f.__workletHash = 1022605193782;
_f.__stackDetails = _e;
return _f;
}()
});"
`;
Loading

0 comments on commit 7a6424a

Please sign in to comment.