Skip to content

Sync offset value to native immediately #50941

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

Closed
wants to merge 1 commit into from
Closed
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 @@ -38,6 +38,7 @@ describe('AnimatedValue', () => {
removeListeners: jest.fn(),
startListeningToAnimatedNodeValue: jest.fn(),
stopListeningToAnimatedNodeValue: jest.fn(),
extractAnimatedNodeOffset: jest.fn(),
// ...
},
}));
Expand All @@ -49,6 +50,8 @@ describe('AnimatedValue', () => {
jest.spyOn(NativeAnimatedHelper.API, 'createAnimatedNode');
jest.spyOn(NativeAnimatedHelper.API, 'dropAnimatedNode');
jest.spyOn(NativeAnimatedHelper.API, 'startListeningToAnimatedNodeValue');
jest.spyOn(NativeAnimatedHelper.API, 'setWaitingForIdentifier');
jest.spyOn(NativeAnimatedHelper.API, 'unsetWaitingForIdentifier');
});

it('emits update events for listeners added', () => {
Expand Down Expand Up @@ -161,4 +164,39 @@ describe('AnimatedValue', () => {
).toBeCalledTimes(0);
});
});

describe('when extractOffset is called', () => {
it('flushes changes to native immediately when native', () => {
const node = new AnimatedValue(0, {useNativeDriver: true});

expect(NativeAnimatedHelper.API.setWaitingForIdentifier).toBeCalledTimes(
0,
);
expect(
NativeAnimatedHelper.API.unsetWaitingForIdentifier,
).toBeCalledTimes(0);

node.extractOffset();

expect(NativeAnimatedHelper.API.setWaitingForIdentifier).toBeCalledTimes(
1,
);
expect(
NativeAnimatedHelper.API.unsetWaitingForIdentifier,
).toBeCalledTimes(1);
});

it('does not flush changes when not native', () => {
const node = new AnimatedValue(0, {useNativeDriver: false});

node.extractOffset();

expect(NativeAnimatedHelper.API.setWaitingForIdentifier).toBeCalledTimes(
0,
);
expect(
NativeAnimatedHelper.API.unsetWaitingForIdentifier,
).toBeCalledTimes(0);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ export default class AnimatedValue extends AnimatedWithChildren {
this._offset += this._value;
this._value = 0;
if (this.__isNative) {
NativeAnimatedAPI.extractAnimatedNodeOffset(this.__getNativeTag());
_executeAsAnimatedBatch(this.__getNativeTag().toString(), () =>
NativeAnimatedAPI.extractAnimatedNodeOffset(this.__getNativeTag()),
);
}
}

Expand Down