Skip to content

small adjustments to when value listener is fired #52063

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 2 commits into from
Closed
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
@@ -325,6 +325,11 @@ describe('Value.flattenOffset', () => {
root.render(<PressableWithNativeDriver />);
});

const fn = jest.fn();
Fantom.runTask(() => {
_onScroll.addListener(fn);
});

const scrollViewelement = ensureInstance(
scrollViewRef.current,
ReactNativeElement,
@@ -336,15 +341,21 @@ describe('Value.flattenOffset', () => {
y: 10,
});

expect(fn).toBeCalledWith({value: 10});

Fantom.runTask(() => {
_onScroll.setOffset(15);
_onScroll.flattenOffset();
});

expect(fn).toHaveBeenCalledTimes(1);

Fantom.runTask(() => {
_onScroll.setOffset(15);
});

expect(fn).toHaveBeenCalledTimes(1);

let transform =
// $FlowFixMe[incompatible-use]
Fantom.unstable_getDirectManipulationProps(viewElement).transform[0];
@@ -401,6 +412,11 @@ describe('Value.extractOffset', () => {
root.render(<PressableWithNativeDriver />);
});

const fn = jest.fn();
Fantom.runTask(() => {
_onScroll.addListener(fn);
});

const scrollViewelement = ensureInstance(
scrollViewRef.current,
ReactNativeElement,
@@ -412,12 +428,16 @@ describe('Value.extractOffset', () => {
y: 10,
});

expect(fn).toBeCalledWith({value: 10});

Fantom.runTask(() => {
_onScroll.setOffset(15);
// Sets offset to be 15 + 10 = 25 (this is not observable from JS).
_onScroll.extractOffset();
});

expect(fn).toHaveBeenCalledTimes(1);

let transform =
// $FlowFixMe[incompatible-use]
Fantom.unstable_getDirectManipulationProps(viewElement).transform[0];
@@ -431,6 +451,8 @@ describe('Value.extractOffset', () => {
_onScroll.setOffset(35);
});

expect(fn).toHaveBeenCalledTimes(1);

transform =
// $FlowFixMe[incompatible-use]
Fantom.unstable_getDirectManipulationProps(viewElement).transform[0];
Original file line number Diff line number Diff line change
@@ -56,7 +56,9 @@ void AnimatedModule::updateAnimatedNodeConfig(
jsi::Runtime& rt,
Tag tag,
jsi::Object config) {
// TODO(T196513045): missing implementation
// TODO(T196513045): missing implementation. This API is only used by Animated
// when PlatformColor API is used and animation is updated with a new value
// through AnimatedColor.setValue.
}

void AnimatedModule::getValue(
@@ -191,11 +193,15 @@ void AnimatedModule::removeAnimatedEventFromView(
void AnimatedModule::addListener(
jsi::Runtime& /*rt*/,
const std::string& /*eventName*/) {
// TODO(T225953415): missing implementation
// Not needed in C++ Animated. addListener is used to synchronise event
// animations like onScroll with React and Fabric. However C++ Animated
// synchronises with Fabric directly.
}

void AnimatedModule::removeListeners(jsi::Runtime& /*rt*/, int /*count*/) {
// TODO(T225953457): missing implementation
// Not needed in C++ Animated. removeListeners is used to synchronise event
// animations like onScroll with React and Fabric. However C++ Animated
// synchronises with Fabric directly.
}

void AnimatedModule::queueAndExecuteBatchedOperations(
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ std::optional<double> NativeAnimatedNodesManager::getValue(Tag tag) noexcept {
}
}

// graph
#pragma mark - Graph

std::unique_ptr<AnimatedNode> NativeAnimatedNodesManager::animatedNode(
Tag tag,
@@ -235,7 +235,7 @@ void NativeAnimatedNodesManager::dropAnimatedNode(Tag tag) noexcept {
animatedNodes_.erase(tag);
}

// mutations
#pragma mark - Mutations

void NativeAnimatedNodesManager::setAnimatedNodeValue(Tag tag, double value) {
if (auto node = getAnimatedNode<ValueAnimatedNode>(tag)) {
@@ -280,7 +280,7 @@ void NativeAnimatedNodesManager::stopAnimationsForNode(Tag nodeTag) {
}
}

// drivers
#pragma mark - Drivers

void NativeAnimatedNodesManager::startAnimatingNode(
int animationId,
@@ -701,7 +701,8 @@ bool NativeAnimatedNodesManager::isOnRenderThread() const noexcept {
return isOnRenderThread_;
}

// listeners
#pragma mark - Listeners

void NativeAnimatedNodesManager::startListeningToAnimatedNodeValue(
Tag tag,
ValueListenerCallback&& callback) noexcept {
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ class NativeAnimatedNodesManager {

std::optional<double> getValue(Tag tag) noexcept;

// graph
#pragma mark - Graph

void createAnimatedNode(Tag tag, const folly::dynamic& config) noexcept;

@@ -102,7 +102,7 @@ class NativeAnimatedNodesManager {

void setAnimatedNodeOffset(Tag tag, double offset);

// drivers
#pragma mark - Drivers

void startAnimatingNode(
int animationId,
@@ -127,7 +127,8 @@ class NativeAnimatedNodesManager {
std::shared_ptr<EventEmitterListener> getEventEmitterListener() noexcept {
return ensureEventEmitterListener();
}
// listeners

#pragma mark - Listeners

void startListeningToAnimatedNodeValue(
Tag tag,
Original file line number Diff line number Diff line change
@@ -53,8 +53,6 @@ double ValueAnimatedNode::getOffset() const noexcept {
bool ValueAnimatedNode::setOffset(double offset) noexcept {
if (offset_ != offset) {
offset_ = offset;

onValueUpdate();
return true;
}
return true;
@@ -67,13 +65,11 @@ double ValueAnimatedNode::getValue() const noexcept {
void ValueAnimatedNode::flattenOffset() noexcept {
value_ = value_ + offset_;
offset_ = 0;
onValueUpdate();
}

void ValueAnimatedNode::extractOffset() noexcept {
offset_ += value_;
value_ = 0;
onValueUpdate();
}

void ValueAnimatedNode::onValueUpdate() noexcept {
Loading
Oops, something went wrong.