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

draft: testing screen transitions and SETs #5655

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
ef35469
Copy changes from rn-screens
piaskowyk Oct 19, 2023
0329270
Call configure props
piaskowyk Oct 19, 2023
97ec16b
Add example
piaskowyk Oct 19, 2023
a5fc158
Export types
piaskowyk Oct 19, 2023
803c380
Use Screen's methods on UI
piaskowyk Oct 20, 2023
c74789d
Update package.json
piaskowyk Oct 20, 2023
a0cd9e1
Run Android on UI
piaskowyk Oct 25, 2023
5b372dc
Added easing
piaskowyk Oct 26, 2023
d9636ac
Update screens version
piaskowyk Oct 26, 2023
68c6493
Plit update
piaskowyk Oct 26, 2023
b2ff069
Merge branch 'main' into @piaskowyk/screen-animations-swipe-back
piaskowyk Nov 2, 2023
f975ef0
Run format
piaskowyk Nov 2, 2023
4ed7262
Use screens as local tarball
piaskowyk Nov 3, 2023
1732b3d
Compatibility without screens
piaskowyk Nov 6, 2023
a6c90ae
Update example
piaskowyk Nov 6, 2023
8c71ce3
Update hash
piaskowyk Nov 6, 2023
7a0f14c
Web mock
piaskowyk Nov 6, 2023
984afad
Web mock
piaskowyk Nov 6, 2023
e3f60c8
Force common interface
piaskowyk Nov 6, 2023
115f4e6
Update hash
piaskowyk Nov 6, 2023
3fd934a
Update hash again
piaskowyk Nov 6, 2023
de25c01
Update gradle properties
piaskowyk Nov 6, 2023
45f86f7
Update globals
piaskowyk Nov 6, 2023
9395a59
Update layout animations
bartlomiejbloniarz Nov 13, 2023
272399c
Add example
bartlomiejbloniarz Nov 13, 2023
0858237
Update gesture simulator
piaskowyk Nov 13, 2023
34385be
Update dependencies
piaskowyk Nov 13, 2023
0880b7d
Update screens
piaskowyk Nov 14, 2023
7f6fd8e
Add use strict
piaskowyk Nov 14, 2023
5874b31
update example
piaskowyk Nov 14, 2023
fd7aaea
batchinator
bartlomiejbloniarz Nov 17, 2023
de8c246
`'use strict'` 😭
bartlomiejbloniarz Nov 17, 2023
2ee764d
Mock web
bartlomiejbloniarz Nov 17, 2023
ee5eae0
Fix `enableLayoutAnimations` call
bartlomiejbloniarz Nov 20, 2023
9d480e9
Fix overlapping layout animations
bartlomiejbloniarz Nov 20, 2023
73603db
Fix `MethodMetadata`
bartlomiejbloniarz Nov 20, 2023
722ec07
Update docs
bartlomiejbloniarz Nov 21, 2023
056deb8
Merge branch 'main' into @bartlomiejbloniarz/modify-layout-animations
bartlomiejbloniarz Nov 21, 2023
9c77015
Merge branch 'main' into @bartlomiejbloniarz/modify-layout-animations
bartlomiejbloniarz Nov 22, 2023
cc02106
Merge branch 'main' into @bartlomiejbloniarz/modify-layout-animations
bartlomiejbloniarz Nov 22, 2023
6dc6d95
Merge branch 'main' into @piaskowyk/screen-animations-swipe-back
piaskowyk Dec 1, 2023
20685b8
Improvements after review
piaskowyk Dec 5, 2023
7513d1e
Java lint
piaskowyk Dec 5, 2023
5c6ca32
Align to the new screens interface
piaskowyk Dec 5, 2023
4031de8
Remove dependency for RNScreensModule
piaskowyk Dec 12, 2023
39d52d1
Add worklet directive
piaskowyk Dec 12, 2023
5282eb9
Lint Java
piaskowyk Dec 12, 2023
9aa642b
Clean up
piaskowyk Dec 12, 2023
efbd197
Big commit
bartlomiejbloniarz Dec 13, 2023
1e0c321
Update types
piaskowyk Dec 13, 2023
2711ed4
Update example app
piaskowyk Dec 13, 2023
a68c1fc
Remove screes .tgz
piaskowyk Dec 13, 2023
f3136f8
Update example
piaskowyk Dec 13, 2023
f3b1619
Merge branch 'main' into @piaskowyk/screen-animations-swipe-back
piaskowyk Dec 13, 2023
7c7bb5a
Merge branch 'main' into @piaskowyk/screen-animations-swipe-back
piaskowyk Dec 28, 2023
5a7d165
Review
piaskowyk Dec 28, 2023
a8fac50
Restore file name
piaskowyk Dec 28, 2023
1a5c16f
ScreensTurboModule mock
piaskowyk Dec 28, 2023
cac050d
Small refactor
piaskowyk Dec 28, 2023
778fa63
change Android implementation
bartlomiejbloniarz Dec 29, 2023
a30284a
Remove unnecessary configuration calls
bartlomiejbloniarz Jan 8, 2024
aaf7149
Move animation start to `willAppear`
bartlomiejbloniarz Jan 8, 2024
9e2c337
Merge branch 'main' into @piaskowyk/screen-animations-swipe-back
piaskowyk Jan 9, 2024
f3debe0
Fix interactivity
bartlomiejbloniarz Jan 12, 2024
05bac12
merg
bartlomiejbloniarz Jan 15, 2024
577feea
fix java lint
bartlomiejbloniarz Jan 15, 2024
15974e1
Merge branch 'main' into @bartlomiejbloniarz/modify-sets
bartlomiejbloniarz Jan 17, 2024
1771706
Add tsdoc
bartlomiejbloniarz Jan 17, 2024
6adce90
Fix transforms on iOS
bartlomiejbloniarz Jan 24, 2024
6de03aa
Simplify configuration
bartlomiejbloniarz Jan 24, 2024
a9a5461
Remove old api
bartlomiejbloniarz Jan 26, 2024
7b3d4dc
Add comment
bartlomiejbloniarz Jan 26, 2024
0b0fcdc
Fix [SET] Modals example
bartlomiejbloniarz Jan 26, 2024
5748249
Change config cleanup
bartlomiejbloniarz Jan 26, 2024
c5ae961
Rename listener
bartlomiejbloniarz Jan 26, 2024
2ccf49e
merg
bartlomiejbloniarz Jan 26, 2024
05c25a5
Merge remote-tracking branch 'origin/@bartlomiejbloniarz/modify-sets'…
kacperkapusciak Feb 8, 2024
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
62 changes: 35 additions & 27 deletions Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,35 @@

namespace reanimated {

void LayoutAnimationsManager::configureAnimation(
const int tag,
const LayoutAnimationType type,
const std::string &sharedTransitionTag,
const std::shared_ptr<Shareable> &config) {
void LayoutAnimationsManager::configureAnimationBatch(
const std::vector<LayoutAnimationConfig> &layoutAnimationsBatch) {
auto lock = std::unique_lock<std::mutex>(animationsMutex_);
if (type == SHARED_ELEMENT_TRANSITION ||
type == SHARED_ELEMENT_TRANSITION_PROGRESS) {
std::vector<LayoutAnimationConfig> sharedTransitionConfigs;
for (auto layoutAnimationConfig : layoutAnimationsBatch) {
auto [tag, type, config, sharedTransitionTag] = layoutAnimationConfig;
if (type == SHARED_ELEMENT_TRANSITION ||
type == SHARED_ELEMENT_TRANSITION_PROGRESS) {
clearSharedTransitionConfig(tag);
sharedTransitionConfigs.push_back(std::move(layoutAnimationConfig));
} else {
if (config == nullptr) {
getConfigsForType(type).erase(tag);
} else {
getConfigsForType(type)[tag] = config;
}
}
}
for (auto [tag, type, config, sharedTransitionTag] :
sharedTransitionConfigs) {
if (config == nullptr) {
continue;
}
sharedTransitionGroups_[sharedTransitionTag].push_back(tag);
viewTagToSharedTag_[tag] = sharedTransitionTag;
getConfigsForType(SHARED_ELEMENT_TRANSITION)[tag] = config;
if (type == SHARED_ELEMENT_TRANSITION) {
ignoreProgressAnimationForTag_.insert(tag);
}
} else {
getConfigsForType(type)[tag] = config;
}
}

void LayoutAnimationsManager::configureAnimationBatch(
const std::vector<LayoutAnimationConfig> &layoutAnimationsBatch) {
auto lock = std::unique_lock<std::mutex>(animationsMutex_);
for (auto [tag, type, config] : layoutAnimationsBatch) {
if (config == nullptr) {
getConfigsForType(type).erase(tag);
} else {
getConfigsForType(type)[tag] = config;
}
}
}

Expand Down Expand Up @@ -66,12 +67,9 @@ bool LayoutAnimationsManager::hasLayoutAnimation(
return collection::contains(getConfigsForType(type), tag);
}

void LayoutAnimationsManager::clearLayoutAnimationConfig(const int tag) {
auto lock = std::unique_lock<std::mutex>(animationsMutex_);
enteringAnimations_.erase(tag);
exitingAnimations_.erase(tag);
layoutAnimations_.erase(tag);
shouldAnimateExitingForTag_.erase(tag);
void LayoutAnimationsManager::clearSharedTransitionConfig(const int tag) {
// here we don't lock the mutex, since this function is only supposed to be
// used as a helper
#ifndef NDEBUG
const auto &pair = viewsScreenSharedTagMap_[tag];
screenSharedTagSet_.erase(pair);
Expand All @@ -81,6 +79,7 @@ void LayoutAnimationsManager::clearLayoutAnimationConfig(const int tag) {
sharedTransitionAnimations_.erase(tag);
auto const &groupName = viewTagToSharedTag_[tag];
if (groupName.empty()) {
viewTagToSharedTag_.erase(tag);
return;
}
auto &group = sharedTransitionGroups_[groupName];
Expand All @@ -95,6 +94,15 @@ void LayoutAnimationsManager::clearLayoutAnimationConfig(const int tag) {
ignoreProgressAnimationForTag_.erase(tag);
}

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

void LayoutAnimationsManager::startLayoutAnimation(
jsi::Runtime &rt,
const int tag,
Expand Down
7 changes: 2 additions & 5 deletions Common/cpp/LayoutAnimations/LayoutAnimationsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@ struct LayoutAnimationConfig {
int tag;
LayoutAnimationType type;
std::shared_ptr<Shareable> config;
std::string sharedTransitionTag;
};

class LayoutAnimationsManager {
public:
explicit LayoutAnimationsManager(const std::shared_ptr<JSLogger> &jsLogger)
: jsLogger_(jsLogger) {}
void configureAnimation(
const int tag,
const LayoutAnimationType type,
const std::string &sharedTransitionTag,
const std::shared_ptr<Shareable> &config);
void configureAnimationBatch(
const std::vector<LayoutAnimationConfig> &layoutAnimationsBatch);
void setShouldAnimateExiting(const int tag, const bool value);
Expand All @@ -54,6 +50,7 @@ class LayoutAnimationsManager {
#endif

private:
void clearSharedTransitionConfig(const int tag);
std::unordered_map<int, std::shared_ptr<Shareable>> &getConfigsForType(
const LayoutAnimationType type);

Expand Down
27 changes: 10 additions & 17 deletions Common/cpp/NativeModules/NativeReanimatedModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,23 +293,6 @@ jsi::Value NativeReanimatedModule::configureProps(
return jsi::Value::undefined();
}

jsi::Value NativeReanimatedModule::configureLayoutAnimation(
jsi::Runtime &rt,
const jsi::Value &viewTag,
const jsi::Value &type,
const jsi::Value &sharedTransitionTag,
const jsi::Value &config) {
layoutAnimationsManager_.configureAnimation(
viewTag.asNumber(),
static_cast<LayoutAnimationType>(type.asNumber()),
sharedTransitionTag.asString(rt).utf8(rt),
extractShareableOrThrow<ShareableObject>(
rt,
config,
"[Reanimated] Layout animation config must be an object."));
return jsi::Value::undefined();
}

jsi::Value NativeReanimatedModule::configureLayoutAnimationBatch(
jsi::Runtime &rt,
const jsi::Value &layoutAnimationsBatch) {
Expand All @@ -331,6 +314,16 @@ jsi::Value NativeReanimatedModule::configureLayoutAnimationBatch(
config,
"[Reanimated] Layout animation config must be an object.");
}
if (batch[i].type != SHARED_ELEMENT_TRANSITION &&
batch[i].type != SHARED_ELEMENT_TRANSITION_PROGRESS) {
continue;
}
auto sharedTransitionTag = item.getProperty(rt, "sharedTransitionTag");
if (sharedTransitionTag.isUndefined()) {
batch[i].config = nullptr;
} else {
batch[i].sharedTransitionTag = sharedTransitionTag.asString(rt).utf8(rt);
}
}
layoutAnimationsManager_.configureAnimationBatch(batch);
return jsi::Value::undefined();
Expand Down
6 changes: 0 additions & 6 deletions Common/cpp/NativeModules/NativeReanimatedModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec {
jsi::Runtime &rt,
const jsi::Value &uiProps,
const jsi::Value &nativeProps) override;
jsi::Value configureLayoutAnimation(
jsi::Runtime &rt,
const jsi::Value &viewTag,
const jsi::Value &type,
const jsi::Value &sharedTransitionTag,
const jsi::Value &config) override;
jsi::Value configureLayoutAnimationBatch(
jsi::Runtime &rt,
const jsi::Value &layoutAnimationsBatch) override;
Expand Down
16 changes: 0 additions & 16 deletions Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,6 @@ static jsi::Value SPEC_PREFIX(unsubscribeFromKeyboardEvents)(
return jsi::Value::undefined();
}

static jsi::Value SPEC_PREFIX(configureLayoutAnimation)(
jsi::Runtime &rt,
TurboModule &turboModule,
const jsi::Value *args,
size_t) {
return static_cast<NativeReanimatedModuleSpec *>(&turboModule)
->configureLayoutAnimation(
rt,
std::move(args[0]),
std::move(args[1]),
std::move(args[2]),
std::move(args[3]));
}

static jsi::Value SPEC_PREFIX(configureLayoutAnimationBatch)(
jsi::Runtime &rt,
TurboModule &turboModule,
Expand Down Expand Up @@ -214,8 +200,6 @@ NativeReanimatedModuleSpec::NativeReanimatedModuleSpec(
methodMap_["unsubscribeFromKeyboardEvents"] =
MethodMetadata{1, SPEC_PREFIX(unsubscribeFromKeyboardEvents)};

methodMap_["configureLayoutAnimation"] =
MethodMetadata{4, SPEC_PREFIX(configureLayoutAnimation)};
methodMap_["configureLayoutAnimationBatch"] =
MethodMetadata{1, SPEC_PREFIX(configureLayoutAnimationBatch)};
methodMap_["setShouldAnimateExitingForTag"] =
Expand Down
7 changes: 0 additions & 7 deletions Common/cpp/NativeModules/NativeReanimatedModuleSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@ class JSI_EXPORT NativeReanimatedModuleSpec : public TurboModule {
const jsi::Value &nativeProps) = 0;

// layout animations
virtual jsi::Value configureLayoutAnimation(
jsi::Runtime &rt,
const jsi::Value &viewTag,
const jsi::Value &type,
const jsi::Value &sharedTransitionTag,
const jsi::Value &config) = 0;

virtual jsi::Value configureLayoutAnimationBatch(
jsi::Runtime &rt,
const jsi::Value &layoutAnimationsBatch) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,8 @@ private static Point convertScreenLocationToViewCoordinates(Point fromPoint, Vie
return new Point(fromPoint.x - toPoint[0], fromPoint.y - toPoint[1]);
}

public void screenDidLayout() {
mSharedTransitionManager.screenDidLayout();
public void screenDidLayout(View view) {
mSharedTransitionManager.screenDidLayout(view);
}

public void viewDidLayout(View view) {
Expand All @@ -724,6 +724,10 @@ public void notifyAboutViewsRemoval(int[] tagsToDelete) {
mSharedTransitionManager.onViewsRemoval(tagsToDelete);
}

public void notifyAboutScreenWillDisappear() {
mSharedTransitionManager.onScreenWillDisappear();
}

public void makeSnapshotOfTopScreenViews(ViewGroup stack) {
mSharedTransitionManager.doSnapshotForTopScreenViews(stack);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.uimanager.IllegalViewOperationException;
import com.facebook.react.uimanager.NativeViewHierarchyManager;
import com.facebook.react.uimanager.UIManagerHelper;
import com.facebook.react.uimanager.ViewAtIndex;
import com.facebook.react.uimanager.ViewGroupManager;
import com.facebook.react.uimanager.ViewManager;
Expand Down Expand Up @@ -164,6 +166,20 @@ public void deleteView(final View view, final LayoutAnimationListener listener)
if (parentName.equals("RNSScreenStack")) {
mAnimationsManager.cancelAnimationsInSubviews(view);
super.deleteView(view, listener);
var eventDispatcher =
UIManagerHelper.getEventDispatcherForReactTag(
(ReactContext) view.getContext(), view.getId());
if (eventDispatcher != null) {
eventDispatcher.addListener(
event -> {
// we schedule the start of transition for the ScreenWilDisappear event, so that the
// layout of the target screen is already calculated
// this allows us to make snapshots on the go, so that they are always up-to-date
if (event.getEventName().equals("topWillDisappear")) {
getAnimationsManager().notifyAboutScreenWillDisappear();
}
});
}
return;
}
}
Expand Down Expand Up @@ -264,7 +280,7 @@ public synchronized void updateLayout(
if (container != null && viewManagerName.equals("RNSScreen") && mReaLayoutAnimator != null) {
boolean hasHeader = checkIfTopScreenHasHeader((ViewGroup) container);
if (!hasHeader || !container.isLayoutRequested()) {
mReaLayoutAnimator.getAnimationsManager().screenDidLayout();
mReaLayoutAnimator.getAnimationsManager().screenDidLayout(container);
}
}
View view = resolveView(tag);
Expand Down
Loading