Skip to content
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

Shareable value rewrite #3722

Merged
merged 128 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from 107 commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
0fa7649
Stashing work
kmagiera Apr 22, 2022
fd6bc69
Stashing moar work
kmagiera Apr 26, 2022
bcfa8e3
Stashing moar work
kmagiera Apr 26, 2022
ae65f1a
Fix entering animation flicker
kmagiera Apr 27, 2022
35d72a4
Even moar changes
kmagiera May 4, 2022
75e963a
Sort out ref dependency cycle between animations manager and layout p…
kmagiera Jun 28, 2022
e6ad2ad
Naming cleanup
kmagiera Jun 28, 2022
53fc972
Work on interrupting entering with layout animation
kmagiera Jul 4, 2022
65447aa
Fix overriding enter with layout
kmagiera Jul 5, 2022
d1d7116
Fix lint and some warnings
kmagiera Jul 5, 2022
754720a
Remove even more old, unused code
kmagiera Jul 6, 2022
cf59766
Stashing work on Android
kmagiera Jul 6, 2022
4546aab
Stashing work
kmagiera Sep 23, 2022
f91bddb
Further work
kmagiera Sep 26, 2022
982a08f
Moar work
kmagiera Sep 30, 2022
0c4ce7c
Shared values are working
kmagiera Sep 30, 2022
b674501
Prepare mappers to support shareables (not working yet)
kmagiera Oct 13, 2022
752add2
entering
jwajgelt Oct 17, 2022
46b0306
layout, exiting
jwajgelt Oct 17, 2022
cc11277
Fix build issues + mappers are sort-of working
kmagiera Oct 17, 2022
1d04df5
Move reactive value logic to JS allowing for better flexibility (not …
kmagiera Oct 18, 2022
9e80046
Introduce ShareableHandle and build SV and mapper prototype on top of it
kmagiera Oct 19, 2022
3cdc33a
Drop traces of ShareableReactive concept
kmagiera Oct 19, 2022
e7287d1
Merge branch 'layoutanim_rewrite' into @jwajgelt/layout-animations
jwajgelt Oct 19, 2022
2a3f974
Get remote objects to work and test timing animation
kmagiera Oct 20, 2022
d63126c
SVs and styles are working
kmagiera Oct 20, 2022
d010ffb
Some cleanup
kmagiera Oct 20, 2022
d308c65
Add UI->JS calls
kmagiera Oct 20, 2022
3c65659
use NativeHierarchyManager to resolve ViewManagers
jwajgelt Oct 21, 2022
7990c04
keep only exiting views in AnimationsManager
jwajgelt Oct 21, 2022
fe273e4
Hook up events
kmagiera Oct 21, 2022
fa14885
Transfer runOnJS to the new implementation
kmagiera Oct 21, 2022
82158b4
Drop code that is no longer going to be used
kmagiera Oct 21, 2022
a68f0b7
Rewrite view deletion logic in AnimationsManager
jwajgelt Oct 24, 2022
4188d76
Updating layout animations
kmagiera Oct 24, 2022
c47a848
Updating keyboard listeners
kmagiera Oct 24, 2022
a0989c0
Updating sensors
kmagiera Oct 24, 2022
e0b728e
Add two-way option for new mutables
kmagiera Oct 24, 2022
e9112eb
Implement mapper ordering
kmagiera Oct 24, 2022
04dbdf9
Update mapper sort algorithm + handle shared style
kmagiera Oct 25, 2022
e0883e6
Types cleanup and stuff
kmagiera Oct 25, 2022
dc126a8
Moar cleanup
kmagiera Oct 25, 2022
834085f
Moar cleanup
kmagiera Oct 26, 2022
cbc53c3
Even more typescript cleanup
kmagiera Oct 26, 2022
f9e76f0
fix nested `exiting` animations
jwajgelt Oct 24, 2022
d1dde6b
Merge remote-tracking branch 'origin/main' into shareable_rewrite
kmagiera Oct 27, 2022
91c1f26
Responding to review comments
kmagiera Oct 27, 2022
61631de
fix ios nested exiting animations, disable view interaction on android
jwajgelt Oct 28, 2022
f69a5ae
Merge branch 'main' into layoutanim_rewrite
kmagiera Oct 28, 2022
2e0e1d6
Fix more comments & fix exiting animations
kmagiera Oct 28, 2022
a5f038f
Stashing web implementation updates
kmagiera Oct 31, 2022
16122cc
Revert "Stashing web implementation updates"
kmagiera Oct 31, 2022
3e47a8e
Revert "Revert "Stashing web implementation updates""
kmagiera Oct 31, 2022
982ff39
Implement sync data read/writes to speedup two-way values
kmagiera Oct 31, 2022
a605322
Renaming private fields
kmagiera Oct 31, 2022
1be6025
Responding to review comments
kmagiera Oct 31, 2022
deac27b
fix exiting not running for entering views
jwajgelt Oct 28, 2022
a17b6f3
Android cleanup
jwajgelt Nov 2, 2022
cc5ac2c
fix linter errors
jwajgelt Nov 2, 2022
f04a6e6
Fix color handling
piaskowyk Nov 3, 2022
a23325a
Fix typescriptz
kmagiera Nov 3, 2022
a457f3a
Formatting c++
kmagiera Nov 3, 2022
d6bb8da
code review changes
jwajgelt Nov 4, 2022
8314587
handle startLayoutAnimation being called before initializing LayoutAn…
jwajgelt Nov 4, 2022
6a5817b
Splitting core into smaller files to facilitate work on web compatibi…
kmagiera Nov 4, 2022
6312882
code review changes
jwajgelt Nov 4, 2022
fcae36c
fix fabric ios
jwajgelt Nov 4, 2022
3c8ac7a
add layout animation examples
jwajgelt Nov 4, 2022
17beed4
add remaining types
jwajgelt Nov 4, 2022
690f37b
more code review changes
jwajgelt Nov 4, 2022
89c7326
Use prototype instead of bind to extact closure in order to support r…
kmagiera Nov 4, 2022
99c5edb
remove layout animation configs when not needed
jwajgelt Nov 7, 2022
7aba259
remove animation config when removing views on iOS
jwajgelt Nov 7, 2022
c042065
Merge branch 'main' into layoutanim_rewrite
piaskowyk Nov 8, 2022
d4f6010
Fix nativeProxy for Fabric
piaskowyk Nov 8, 2022
66d5375
Fix recursive functions
kmagiera Nov 9, 2022
eec9cd0
Fix recursion for real
kmagiera Nov 9, 2022
292a973
Update plugin tests
kmagiera Nov 9, 2022
9bbd3d0
Add fast-path for handling undefined items in objects and arrays
kmagiera Nov 9, 2022
b81203e
add comment about magic constant
jwajgelt Nov 9, 2022
be4410b
Clear dirty flag after mapper is run
kmagiera Nov 9, 2022
f8be26e
Fix web
kmagiera Nov 9, 2022
06f3e49
Add new examples
tomekzaw Nov 10, 2022
0d66c07
add code review changes
jwajgelt Nov 10, 2022
06713ef
fix ios reporting error on removing views
jwajgelt Nov 10, 2022
7a7a367
Update android/src/main/cpp/NativeProxy.cpp
jwajgelt Nov 10, 2022
03a1f1e
code review fixes
jwajgelt Nov 14, 2022
47cc15f
fix cleanup of layout animations
jwajgelt Nov 14, 2022
a84d5a7
fix typo
jwajgelt Nov 14, 2022
1ef44f1
fix imports
jwajgelt Nov 14, 2022
9744ae5
Merge branch 'main' into layoutanim_rewrite
jwajgelt Nov 14, 2022
dfc6da6
remove only roots of to-be-removed trees on Android
jwajgelt Nov 14, 2022
a5ae203
remove only roots of to-be-removed trees on iOS
jwajgelt Nov 14, 2022
7ee21b1
Update jest runner stuff
kmagiera Nov 14, 2022
2a4a519
Fix runtime ref loop causing single instance checker crashes
kmagiera Nov 14, 2022
7ea1247
Try make it work on JSC
kmagiera Nov 15, 2022
0a76fc2
Responding to review comments
kmagiera Nov 16, 2022
c3f0d7f
Merge branch 'layoutanim_rewrite' into rewrite_all_the_things
kmagiera Nov 16, 2022
f2d13fd
Fix layout anims rewrite merge
kmagiera Nov 17, 2022
44ef3d2
Merge remote-tracking branch 'origin/main' into shareable_rewrite
kmagiera Nov 17, 2022
6f0fbb3
Revert example changes
kmagiera Nov 17, 2022
8bce1ee
More adjustments after layout animations rewrite merge
kmagiera Nov 18, 2022
dbbf38d
Make android compile again
kmagiera Nov 18, 2022
f03f9e4
Revert changes in REAUIManager
kmagiera Nov 18, 2022
933ab83
Fix bad merge again
kmagiera Nov 18, 2022
1c6fd8d
Fix JSC
kmagiera Nov 18, 2022
24c2504
Warn about reading value for oneWay SV
kmagiera Nov 19, 2022
e333b5b
Responding to review comments
kmagiera Nov 22, 2022
ca4f7ac
Add proper error when attempting to runOnUI for non-worklet
kmagiera Nov 23, 2022
baae29b
Avoid deallocating WekObjects when the runtime is already torn down
kmagiera Nov 24, 2022
2b4e8ab
Same fix but for ShareableHandle
kmagiera Nov 24, 2022
075cefa
Fix animated refs
kmagiera Nov 24, 2022
77823ac
FIx pointer bad access crashes on reload for realz
kmagiera Nov 24, 2022
87f6961
Use unique ptr for better readability
kmagiera Nov 25, 2022
18b98cc
Use two-way-values by default
kmagiera Nov 25, 2022
cae589f
Some typos
kmagiera Nov 25, 2022
3b7130a
Fix cpplint
kmagiera Nov 25, 2022
01008f7
Add better error description when scheduleOnJS is called with wrong i…
kmagiera Nov 25, 2022
fe2e18d
Suppressing the linter
kmagiera Nov 25, 2022
6006162
Fix some final bad access crashes on reload
kmagiera Nov 25, 2022
5104c9b
Just trying to debug why unit tests are failing on CI
kmagiera Nov 25, 2022
d7c95d9
try with node 18
kmagiera Nov 25, 2022
31a83e1
Revert adding upterm for CI debugging
kmagiera Nov 25, 2022
4abb553
Try out node 16 to see if jest tests are passing
kmagiera Nov 25, 2022
2e568b1
Use Date.now for jest tests and try again with node 14
kmagiera Nov 25, 2022
53a51c6
Fix fabric builds on iOS
kmagiera Nov 29, 2022
d7d8569
Fix mappers cleanup
kmagiera Nov 29, 2022
c8a77da
Use frame callbacks for things scheduled via runOnUI
kmagiera Nov 29, 2022
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
69 changes: 32 additions & 37 deletions Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
#include "AnimatedSensorModule.h"
#include "MutableValue.h"
#include "ValueWrapper.h"

#include <memory>
#include <utility>

#include "Shareables.h"

namespace reanimated {

AnimatedSensorModule::AnimatedSensorModule(
const PlatformDepMethodsHolder &platformDepMethodsHolder,
RuntimeManager *runtimeManager)
const PlatformDepMethodsHolder &platformDepMethodsHolder)
: platformRegisterSensorFunction_(platformDepMethodsHolder.registerSensor),
platformUnregisterSensorFunction_(
platformDepMethodsHolder.unregisterSensor),
runtimeManager_(runtimeManager) {}
platformDepMethodsHolder.unregisterSensor) {}

AnimatedSensorModule::~AnimatedSensorModule() {
// It is called during app reload because app reload doesn't call hooks
Expand All @@ -25,41 +23,38 @@ AnimatedSensorModule::~AnimatedSensorModule() {

jsi::Value AnimatedSensorModule::registerSensor(
jsi::Runtime &rt,
const jsi::Value &sensorType,
const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
const jsi::Value &sensorTypeValue,
const jsi::Value &interval,
const jsi::Value &sensorDataContainer) {
std::shared_ptr<ShareableValue> sensorsData = ShareableValue::adapt(
rt, sensorDataContainer.getObject(rt), runtimeManager_);
auto &mutableObject =
ValueWrapper::asMutableValue(sensorsData->valueContainer);
const jsi::Value &sensorDataHandler) {
SensorType sensorType = static_cast<SensorType>(sensorTypeValue.asNumber());

std::function<void(double[])> setter;
if (sensorType.asNumber() == SensorType::ROTATION_VECTOR) {
setter = [&, mutableObject](double newValues[]) {
jsi::Runtime &runtime = *runtimeManager_->runtime.get();
jsi::Object value(runtime);
value.setProperty(runtime, "qx", newValues[0]);
value.setProperty(runtime, "qy", newValues[1]);
value.setProperty(runtime, "qz", newValues[2]);
value.setProperty(runtime, "qw", newValues[3]);
value.setProperty(runtime, "yaw", newValues[4]);
value.setProperty(runtime, "pitch", newValues[5]);
value.setProperty(runtime, "roll", newValues[6]);
mutableObject->setValue(runtime, std::move(value));
};
} else {
setter = [&, mutableObject](double newValues[]) {
jsi::Runtime &runtime = *runtimeManager_->runtime.get();
jsi::Object value(runtime);
value.setProperty(runtime, "x", newValues[0]);
value.setProperty(runtime, "y", newValues[1]);
value.setProperty(runtime, "z", newValues[2]);
mutableObject->setValue(runtime, std::move(value));
};
}
auto shareableHandler = extractShareableOrThrow(rt, sensorDataHandler);
auto uiRuntime = runtimeHelper->uiRuntime();

int sensorId = platformRegisterSensorFunction_(
sensorType.asNumber(), interval.asNumber(), setter);
sensorType, interval.asNumber(), [=](double newValues[]) {
jsi::Runtime &rt = *uiRuntime;
kmagiera marked this conversation as resolved.
Show resolved Hide resolved
auto handler =
shareableHandler->getJSValue(rt).asObject(rt).asFunction(rt);
if (sensorType == SensorType::ROTATION_VECTOR) {
jsi::Object value(rt);
value.setProperty(rt, "qx", newValues[0]);
value.setProperty(rt, "qy", newValues[1]);
value.setProperty(rt, "qz", newValues[2]);
value.setProperty(rt, "qw", newValues[3]);
value.setProperty(rt, "yaw", newValues[4]);
value.setProperty(rt, "pitch", newValues[5]);
value.setProperty(rt, "roll", newValues[6]);
handler.call(rt, value);
} else {
jsi::Object value(rt);
value.setProperty(rt, "x", newValues[0]);
value.setProperty(rt, "y", newValues[1]);
value.setProperty(rt, "z", newValues[2]);
handler.call(rt, value);
}
});
if (sensorId != -1) {
sensorsIds_.insert(sensorId);
}
Expand Down
6 changes: 3 additions & 3 deletions Common/cpp/AnimatedSensor/AnimatedSensorModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "PlatformDepMethodsHolder.h"
#include "RuntimeManager.h"
#include "Shareables.h"

namespace reanimated {

Expand All @@ -22,16 +23,15 @@ class AnimatedSensorModule {
std::unordered_set<int> sensorsIds_;
RegisterSensorFunction platformRegisterSensorFunction_;
UnregisterSensorFunction platformUnregisterSensorFunction_;
RuntimeManager *runtimeManager_;

public:
AnimatedSensorModule(
const PlatformDepMethodsHolder &platformDepMethodsHolder,
RuntimeManager *runtimeManager);
const PlatformDepMethodsHolder &platformDepMethodsHolder);
~AnimatedSensorModule();

jsi::Value registerSensor(
jsi::Runtime &rt,
const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
const jsi::Value &sensorType,
const jsi::Value &interval,
const jsi::Value &sensorDataContainer);
Expand Down
76 changes: 76 additions & 0 deletions Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include "LayoutAnimationsManager.h"
#include "Shareables.h"

#include <utility>

namespace reanimated {

void LayoutAnimationsManager::configureAnimation(
int tag,
const std::string &type,
std::shared_ptr<Shareable> config) {
auto lock = std::unique_lock<std::mutex>(animationsMutex_);
if (type == "entering") {
enteringAnimations_[tag] = config;
} else if (type == "exiting") {
exitingAnimations_[tag] = config;
} else if (type == "layout") {
layoutAnimations_[tag] = config;
}
}

bool LayoutAnimationsManager::hasLayoutAnimation(
int tag,
const std::string &type) {
auto lock = std::unique_lock<std::mutex>(animationsMutex_);
if (type == "entering") {
return enteringAnimations_.find(tag) != enteringAnimations_.end();
} else if (type == "exiting") {
return exitingAnimations_.find(tag) != exitingAnimations_.end();
} else if (type == "layout") {
return layoutAnimations_.find(tag) != layoutAnimations_.end();
}
return false;
}

void LayoutAnimationsManager::clearLayoutAnimationConfig(int tag) {
auto lock = std::unique_lock<std::mutex>(animationsMutex_);
enteringAnimations_.erase(tag);
exitingAnimations_.erase(tag);
layoutAnimations_.erase(tag);
}

void LayoutAnimationsManager::startLayoutAnimation(
jsi::Runtime &rt,
int tag,
const std::string &type,
const jsi::Object &values) {
std::shared_ptr<Shareable> config, viewShareable;
{
auto lock = std::unique_lock<std::mutex>(animationsMutex_);
if (type == "entering") {
config = enteringAnimations_[tag];
} else if (type == "exiting") {
config = exitingAnimations_[tag];
} else if (type == "layout") {
config = layoutAnimations_[tag];
}
}

// TODO: cache the following!!
jsi::Value layoutAnimationRepositoryAsValue =
rt.global()
.getPropertyAsObject(rt, "global")
.getProperty(rt, "LayoutAnimationsManager");
jsi::Function startAnimationForTag =
layoutAnimationRepositoryAsValue.getObject(rt).getPropertyAsFunction(
rt, "start");
startAnimationForTag.call(
rt,
jsi::Value(tag),
jsi::String::createFromAscii(rt, type),
values,
config->getJSValue(rt));
}

} // namespace reanimated
41 changes: 41 additions & 0 deletions Common/cpp/LayoutAnimations/LayoutAnimationsManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

#include "ErrorHandler.h"
#include "Shareables.h"

#include <jsi/jsi.h>
#include <stdio.h>
#include <functional>
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>

namespace reanimated {

using namespace facebook;

class LayoutAnimationsManager {
public:
void configureAnimation(
int tag,
const std::string &type,
std::shared_ptr<Shareable> config);
bool hasLayoutAnimation(int tag, const std::string &type);
void startLayoutAnimation(
jsi::Runtime &rt,
int tag,
const std::string &type,
const jsi::Object &values);
void clearLayoutAnimationConfig(int tag);

private:
std::unordered_map<int, std::shared_ptr<Shareable>> enteringAnimations_;
std::unordered_map<int, std::shared_ptr<Shareable>> exitingAnimations_;
std::unordered_map<int, std::shared_ptr<Shareable>> layoutAnimations_;
mutable std::mutex
animationsMutex_; // Protects `enteringAnimations_`, `exitingAnimations_`,
// `layoutAnimations_` and `viewSharedValues_`.
};

} // namespace reanimated
127 changes: 0 additions & 127 deletions Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp

This file was deleted.

Loading