forked from software-mansion/react-native-reanimated
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Layout Reanimation (software-mansion#2058)
Introduce the very first version of Layout Animations in Reanimated Co-authored-by: Krzysztof Piaskowy <krzychu2956@gmail.com>
- Loading branch information
Showing
70 changed files
with
3,680 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "LayoutAnimationsProxy.h" | ||
#include "MutableValue.h" | ||
#include "ValueWrapper.h" | ||
#include "ShareableValue.h" | ||
#include "FrozenObject.h" | ||
|
||
namespace reanimated { | ||
|
||
const long long idOffset = 1e9; | ||
|
||
LayoutAnimationsProxy::LayoutAnimationsProxy(std::function<void(int, jsi::Object newProps)> _notifyAboutProgress, std::function<void(int, bool)> _notifyAboutEnd): notifyAboutProgress(std::move(_notifyAboutProgress)), notifyAboutEnd(std::move(_notifyAboutEnd)) { | ||
} | ||
|
||
void LayoutAnimationsProxy::startObserving(int tag, std::shared_ptr<MutableValue> sv, jsi::Runtime &rt) { | ||
observedValues[tag] = sv; | ||
sv->addListener(tag + idOffset, [sv, tag, this, &rt](){ | ||
std::shared_ptr<FrozenObject> newValue = ValueWrapper::asFrozenObject(sv->value->valueContainer); | ||
this->notifyAboutProgress(tag, newValue->shallowClone(rt)); | ||
}); | ||
} | ||
|
||
void LayoutAnimationsProxy::stopObserving(int tag, bool finished) { | ||
if (observedValues.count(tag) == 0) { | ||
return; | ||
} | ||
std::shared_ptr<MutableValue> sv = observedValues[tag]; | ||
sv->removeListener(tag + idOffset); | ||
observedValues.erase(tag); | ||
this->notifyAboutEnd(tag, !finished); | ||
} | ||
|
||
void LayoutAnimationsProxy::notifyAboutCancellation(int tag) { | ||
this->notifyAboutEnd(tag, false); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
Common/cpp/headers/LayoutAnimations/LayoutAnimationsProxy.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <stdio.h> | ||
#include <memory> | ||
#include <functional> | ||
#include <map> | ||
#include <jsi/jsi.h> | ||
|
||
namespace reanimated { | ||
|
||
using namespace facebook; | ||
|
||
class MutableValue; | ||
|
||
class LayoutAnimationsProxy { | ||
|
||
public: | ||
LayoutAnimationsProxy(std::function<void(int, jsi::Object newProps)> _notifyAboutProgress, std::function<void(int, bool)> _notifyAboutEnd); | ||
|
||
void startObserving(int tag, std::shared_ptr<MutableValue> sv, jsi::Runtime &rt); | ||
void stopObserving(int tag, bool finished); | ||
void notifyAboutCancellation(int tag); | ||
|
||
private: | ||
std::function<void(int, jsi::Object newProps)> notifyAboutProgress; | ||
std::function<void(int, bool)> notifyAboutEnd; | ||
std::map<int, std::shared_ptr<MutableValue>> observedValues; | ||
}; | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.