Skip to content

Fix Remove mutation parsing in Layout Animations #6286

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

Merged
Merged
Show file tree
Hide file tree
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
69 changes: 69 additions & 0 deletions apps/common-app/src/examples/LayoutAnimations/BottomTabs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React from 'react';

import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { View, StyleSheet, Button } from 'react-native';
import Animated, {
BounceInDown,
FadeIn,
FadeOutDown,
LinearTransition,
RotateOutDownLeft,
} from 'react-native-reanimated';

const BottomBar = createBottomTabNavigator();

const TabA = () => {
const [toggle, setToggle] = React.useState(false);

return (
<View style={styles.container}>
<Animated.View
entering={FadeIn.duration(1000)}
layout={LinearTransition}
exiting={FadeOutDown}
style={[styles.boxA, { width: toggle ? 200 : 100 }]}
/>
<Button title="toggle" onPress={() => setToggle((prev) => !prev)} />
</View>
);
};

const TabB = () => {
return (
<View style={styles.container}>
<Animated.View
entering={BounceInDown.duration(1000)}
exiting={RotateOutDownLeft.duration(1000)}
style={styles.boxB}
/>
</View>
);
};

const BottomTabsExample = () => {
return (
<BottomBar.Navigator>
<BottomBar.Screen name="A" component={TabA} />
<BottomBar.Screen name="B" component={TabB} />
</BottomBar.Navigator>
);
};

const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
},
boxA: {
width: 100,
height: 100,
backgroundColor: 'blue',
},
boxB: {
width: 100,
height: 100,
backgroundColor: 'red',
},
});

export default BottomTabsExample;
5 changes: 5 additions & 0 deletions apps/common-app/src/examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ import BorderRadiiExample from './SharedElementTransitions/BorderRadii';
import FreezingShareablesExample from './ShareableFreezingExample';
import TabNavigatorExample from './SharedElementTransitions/TabNavigatorExample';
import StrictDOMExample from './StrictDOMExample';
import BottomTabsExample from './LayoutAnimations/BottomTabs';
import ListItemLayoutAnimation from './LayoutAnimations/ListItemLayoutAnimation';

interface Example {
Expand Down Expand Up @@ -706,6 +707,10 @@ export const EXAMPLES: Record<string, Example> = {
title: '[LA] Change theme',
screen: ChangeThemeExample,
},
BottomTabs: {
title: '[LA] Bottom Tabs',
screen: BottomTabsExample,
},

// Shared Element Transitions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ void LayoutAnimationsProxy::parseRemoveMutations(
std::unordered_map<Tag, std::vector<std::shared_ptr<MutationNode>>>
childrenForTag, unflattenedChildrenForTag;

std::vector<std::shared_ptr<MutationNode>> mutationNodes;

// iterate from the end, so that parents appear before children
for (auto it = mutations.rbegin(); it != mutations.rend(); it++) {
auto &mutation = *it;
Expand Down Expand Up @@ -190,9 +192,7 @@ void LayoutAnimationsProxy::parseRemoveMutations(
}
}

if (!unflattenedParent->parent) {
roots.push_back(mutationNode);
}
mutationNodes.push_back(mutationNode);

childrenForTag[parentTag].push_back(mutationNode);
unflattenedChildrenForTag[unflattenedParentTag].push_back(mutationNode);
Expand All @@ -209,10 +209,24 @@ void LayoutAnimationsProxy::parseRemoveMutations(
}

for (auto &[parentTag, children] : childrenForTag) {
nodeForTag_[parentTag]->insertChildren(children);
auto &parent = nodeForTag_[parentTag];
parent->insertChildren(children);
for (auto &child : children) {
child->parent = parent;
}
}
for (auto &[unflattenedParentTag, children] : unflattenedChildrenForTag) {
nodeForTag_[unflattenedParentTag]->insertUnflattenedChildren(children);
auto &unflattenedParent = nodeForTag_[unflattenedParentTag];
unflattenedParent->insertUnflattenedChildren(children);
for (auto &child : children) {
child->unflattenedParent = unflattenedParent;
}
}

for (auto &mutationNode : mutationNodes) {
if (!mutationNode->unflattenedParent->isMutationMode()) {
roots.push_back(mutationNode);
}
}
}

Expand Down Expand Up @@ -697,6 +711,7 @@ void LayoutAnimationsProxy::transferConfigFromNativeID(
auto nativeId = stoi(nativeIdString);
layoutAnimationsManager_->transferConfigFromNativeID(nativeId, tag);
} catch (std::invalid_argument) {
} catch (std::out_of_range) {
}
}

Expand Down
Loading