Skip to content

Commit

Permalink
Start working on making interpolators stateless
Browse files Browse the repository at this point in the history
  • Loading branch information
MatiPl01 committed Feb 6, 2025
1 parent ff6d892 commit 52ec510
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { flex } from '@/theme';
const AnimatedView = createAnimatedComponent(View);

export default function Playground() {
console.log(`animation: ${styles.child.animationName[0]} 1s ease`);

return (
<Screen style={flex.center}>
<Text>Hello world!</Text>
Expand Down
2 changes: 1 addition & 1 deletion apps/fabric-example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2250,7 +2250,7 @@ SPEC CHECKSUMS:
RNCMaskedView: 308c763227e237d4d260bd8841870e099572bb3e
RNFlashList: b799a0cdd1189c1f5064331548400dd79a7e3047
RNGestureHandler: 70069ab3e0431b03f6e465b65745f87a1a02c6c0
RNReanimated: 537897c4ac8d319041d74cd19b633a694fff3895
RNReanimated: 046c859afe6454f541abddad6fb755d8abc83351
RNScreens: 5d61e452b51e7c23b3fcb9f16c4967d683a60a9d
RNSVG: 2089e8b3a145acb2f392017279790f007f934567
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Expand Down
2 changes: 1 addition & 1 deletion apps/tvos-example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,7 @@ SPEC CHECKSUMS:
ReactAppDependencyProvider: be4ae5b0ab2fcc7a26f9d1f3112b361649564fc7
ReactCodegen: d92b8ace8f895b98583e4c8e435598f3b36d6df4
ReactCommon: 6f652903c0e2db5459f031d2d2a65f3943cfb6c3
RNReanimated: 2c45b58e1d18e890221300ef979318217e5a0965
RNReanimated: 6b1cfb8a52b0bcae358f02492886b762d3648f95
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: ef409d2acea4e78ceb422d45fbed7f184c734a44

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ class PropertyInterpolator {
virtual jsi::Value getStyleValue(
jsi::Runtime &rt,
const ShadowNode::Shared &shadowNode) const = 0;
virtual jsi::Value getCurrentValue(
jsi::Runtime &rt,
const ShadowNode::Shared &shadowNode) const = 0;
virtual jsi::Value getFirstKeyframeValue(jsi::Runtime &rt) const = 0;
virtual jsi::Value getLastKeyframeValue(jsi::Runtime &rt) const = 0;

Expand All @@ -42,7 +39,9 @@ class PropertyInterpolator {
virtual void updateKeyframesFromStyleChange(
jsi::Runtime &rt,
const jsi::Value &oldStyleValue,
const jsi::Value &newStyleValue) = 0;
const jsi::Value &newStyleValue,
const jsi::Value &previousValue,
const jsi::Value &reversingAdjustedStartValue) = 0;

virtual jsi::Value update(
jsi::Runtime &rt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ void ArrayPropertiesInterpolator::updateKeyframes(
void ArrayPropertiesInterpolator::updateKeyframesFromStyleChange(
jsi::Runtime &rt,
const jsi::Value &oldStyleValue,
const jsi::Value &newStyleValue) {
const jsi::Value &newStyleValue,
const jsi::Value &previousValue,
const jsi::Value &reversingAdjustedStartValue) {
auto getArrayFromStyle = [&rt](const jsi::Value &style) {
if (!style.isObject()) {
return jsi::Array(rt, 0);
Expand All @@ -78,7 +80,8 @@ void ArrayPropertiesInterpolator::updateKeyframesFromStyleChange(
? newStyleArray.getValueAtIndex(rt, i)
: jsi::Value::undefined();

interpolators_[i]->updateKeyframesFromStyleChange(rt, oldValue, newValue);
interpolators_[i]->updateKeyframesFromStyleChange(
rt, oldValue, newValue, previousValue, reversingAdjustedStartValue);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class ArrayPropertiesInterpolator : public GroupPropertiesInterpolator {
void updateKeyframesFromStyleChange(
jsi::Runtime &rt,
const jsi::Value &oldStyleValue,
const jsi::Value &newStyleValue) override;
const jsi::Value &newStyleValue,
const jsi::Value &previousValue,
const jsi::Value &reversingAdjustedStartValue) override;

protected:
void forEachInterpolator(const std::function<void(PropertyInterpolator &)>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ jsi::Value GroupPropertiesInterpolator::getStyleValue(
});
}

jsi::Value GroupPropertiesInterpolator::getCurrentValue(
jsi::Runtime &rt,
const ShadowNode::Shared &shadowNode) const {
return mapInterpolators(
rt, [&](PropertyInterpolator &interpolator) -> jsi::Value {
return interpolator.getCurrentValue(rt, shadowNode);
});
}

jsi::Value GroupPropertiesInterpolator::getFirstKeyframeValue(
jsi::Runtime &rt) const {
return mapInterpolators(
Expand All @@ -63,15 +54,6 @@ jsi::Value GroupPropertiesInterpolator::update(
});
}

jsi::Value GroupPropertiesInterpolator::reset(
jsi::Runtime &rt,
const ShadowNode::Shared &shadowNode) {
return mapInterpolators(
rt, [&](PropertyInterpolator &interpolator) -> jsi::Value {
return interpolator.reset(rt, shadowNode);
});
}

} // namespace reanimated

#endif // RCT_NEW_ARCH_ENABLED
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ void RecordPropertiesInterpolator::updateKeyframes(
void RecordPropertiesInterpolator::updateKeyframesFromStyleChange(
jsi::Runtime &rt,
const jsi::Value &oldStyleValue,
const jsi::Value &newStyleValue) {
const jsi::Value &newStyleValue,
const jsi::Value &previousValue,
const jsi::Value &reversingAdjustedStartValue) {
// TODO - maybe add a possibility to remove interpolators that are no longer
// used (for now, for simplicity, we only add new ones)

Expand Down Expand Up @@ -92,7 +94,11 @@ void RecordPropertiesInterpolator::updateKeyframesFromStyleChange(

interpolators_.at(propertyName)
->updateKeyframesFromStyleChange(
rt, getValue(oldStyleObject), getValue(newStyleObject));
rt,
getValue(oldStyleObject),
getValue(newStyleObject),
previousValue,
reversingAdjustedStartValue);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class RecordPropertiesInterpolator : public GroupPropertiesInterpolator {
void updateKeyframesFromStyleChange(
jsi::Runtime &rt,
const jsi::Value &oldStyleValue,
const jsi::Value &newStyleValue) override;
const jsi::Value &newStyleValue,
const jsi::Value &previousValue,
const jsi::Value &reversingAdjustedStartValue) override;

protected:
void forEachInterpolator(const std::function<void(PropertyInterpolator &)>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ class AnimationStyleInterpolator : public RecordPropertiesInterpolator {
{},
progressProvider,
viewStylesRepository) {}

jsi::Value getCurrentInterpolationStyle(
jsi::Runtime &rt,
const ShadowNode::Shared &shadowNode) const {
return getCurrentValue(rt, shadowNode);
}
};

} // namespace reanimated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ void TransitionStyleInterpolator::discardIrrelevantInterpolators(

void TransitionStyleInterpolator::updateInterpolatedProperties(
jsi::Runtime &rt,
const ChangedProps &changedProps,
const TransitionPropertyProgressProviders &progressProviders) {
const jsi::Value &oldStyleValue,
const jsi::Value &newStyleValue,
const jsi::Value &previousValue,
const jsi::Value &reversingAdjustedStartValue) {
const auto oldPropsObj = changedProps.oldProps.asObject(rt);
const auto newPropsObj = changedProps.newProps.asObject(rt);

Expand Down Expand Up @@ -117,7 +119,7 @@ void TransitionStyleInterpolator::updateInterpolatedProperties(
}

interpolatorIt->second->updateKeyframesFromStyleChange(
rt, oldValue, newValue);
rt, oldValue, newValue, previousValue, reversingAdjustedStartValue);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ jsi::Value TransformsStyleInterpolator::getStyleValue(
rt, shadowNode->getTag(), propertyPath_);
}

jsi::Value TransformsStyleInterpolator::getCurrentValue(
jsi::Runtime &rt,
const ShadowNode::Shared &shadowNode) const {
if (previousResult_.has_value()) {
return convertResultToJSI(rt, previousResult_.value());
}
return getStyleValue(rt, shadowNode);
}

jsi::Value TransformsStyleInterpolator::getFirstKeyframeValue(
jsi::Runtime &rt) const {
return convertResultToJSI(
Expand Down Expand Up @@ -156,7 +147,9 @@ void TransformsStyleInterpolator::updateKeyframes(
void TransformsStyleInterpolator::updateKeyframesFromStyleChange(
jsi::Runtime &rt,
const jsi::Value &oldStyleValue,
const jsi::Value &newStyleValue) {
const jsi::Value &newStyleValue,
const jsi::Value &previousValue,
const jsi::Value &reversingAdjustedStartValue) {
keyframeIndex_ = 0;
keyframes_.clear();
keyframes_.reserve(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,24 @@ class TransformsStyleInterpolator final : public PropertyInterpolator {
jsi::Value getStyleValue(
jsi::Runtime &rt,
const ShadowNode::Shared &shadowNode) const override;
jsi::Value getCurrentValue(
jsi::Runtime &rt,
const ShadowNode::Shared &shadowNode) const override;
jsi::Value getFirstKeyframeValue(jsi::Runtime &rt) const override;
jsi::Value getLastKeyframeValue(jsi::Runtime &rt) const override;

bool equalsReversingAdjustedStartValue(
jsi::Runtime &rt,
const jsi::Value &propertyValue) const override;

jsi::Value update(jsi::Runtime &rt, const ShadowNode::Shared &shadowNode)
override;
jsi::Value reset(jsi::Runtime &rt, const ShadowNode::Shared &shadowNode)
override;

void updateKeyframes(jsi::Runtime &rt, const jsi::Value &keyframes) override;
void updateKeyframesFromStyleChange(
jsi::Runtime &rt,
const jsi::Value &oldStyleValue,
const jsi::Value &newStyleValue) override;
const jsi::Value &newStyleValue,
const jsi::Value &previousValue,
const jsi::Value &reversingAdjustedStartValue) override;

private:
const std::shared_ptr<TransformInterpolators> interpolators_;
static const TransformOperations defaultStyleValue_;

size_t keyframeIndex_ = 0;
std::vector<std::shared_ptr<TransformKeyframe>> keyframes_;
std::shared_ptr<TransformKeyframe> currentKeyframe_;
// Previous interpolation result
Expand Down
Loading

0 comments on commit 52ec510

Please sign in to comment.