Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -708,9 +708,9 @@ static void calculateShadowViewMutationsFlattener(
auto unvisitedOtherNodesIt =
unvisitedOtherNodes.find(newChild.shadowView.tag);
if (unvisitedOtherNodesIt != unvisitedOtherNodes.end()) {
auto unvisitedItPair = *unvisitedOtherNodesIt->second;
auto* unvisitedItPair = unvisitedOtherNodesIt->second;
unvisitedRecursiveChildPairs.insert(
{unvisitedItPair.shadowView.tag, &unvisitedItPair});
{unvisitedItPair->shadowView.tag, unvisitedItPair});
} else {
unvisitedRecursiveChildPairs.insert(
{newChild.shadowView.tag, &newChild});
Expand Down Expand Up @@ -820,6 +820,9 @@ static void calculateShadowViewMutationsFlattener(
// Final step: go through creation/deletion candidates and delete/create
// subtrees if they were never visited during the execution of the above
// loop and recursions.
const auto& subVisitedMap = reparentMode == ReparentMode::Flatten
? *subVisitedOldMap
: *subVisitedNewMap;
for (auto& deletionCreationCandidatePair : deletionCreationCandidatePairs) {
auto& treeChildPair = *deletionCreationCandidatePair.second;

Expand All @@ -828,7 +831,10 @@ static void calculateShadowViewMutationsFlattener(
// already created/deleted and we don't need to do that here.
// It is always the responsibility of the matcher to update subtrees when
// nodes are matched.
if (treeChildPair.inOtherTree()) {
// The recursion can match the node through a different pair instance
// (e.g. when zIndex orders it before its parent), so check its tag too.
if (treeChildPair.inOtherTree() ||
subVisitedMap.contains(treeChildPair.shadowView.tag)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,73 @@ describe('ViewFlattening', () => {
/>,
);
});

test('#58647: child with negative zIndex is kept when its parent flattens and its grandparent unflattens', () => {
const root = Fantom.createRoot();

function render(opacityOnGrandparent: boolean) {
Fantom.runTask(() => {
root.render(
<View nativeID="Q" style={{opacity: 0.5}}>
<View style={opacityOnGrandparent ? {opacity: 0.5} : null}>
<View style={opacityOnGrandparent ? null : {opacity: 0.5}}>
<View nativeID="A" />
<View nativeID="K" style={{zIndex: -1}} />
<View nativeID="B" />
</View>
</View>
</View>,
);
});
}

const expectedOutput = (
<rn-view nativeID="Q">
<rn-view>
<rn-view key="0" nativeID="K" />
<rn-view key="1" nativeID="A" />
<rn-view key="2" nativeID="B" />
</rn-view>
</rn-view>
);

render(false);
root.takeMountingManagerLogs();

render(true);
expect(root.takeMountingManagerLogs()).toEqual([
'Remove {type: "View", parentNativeID: "Q", index: 0, nativeID: (N/A)}',
'Remove {type: "View", parentNativeID: (N/A), index: 2, nativeID: "B"}',
'Remove {type: "View", parentNativeID: (N/A), index: 1, nativeID: "A"}',
'Remove {type: "View", parentNativeID: (N/A), index: 0, nativeID: "K"}',
'Delete {type: "View", nativeID: (N/A)}',
'Create {type: "View", nativeID: (N/A)}',
'Insert {type: "View", parentNativeID: "Q", index: 0, nativeID: (N/A)}',
'Insert {type: "View", parentNativeID: (N/A), index: 0, nativeID: "K"}',
'Insert {type: "View", parentNativeID: (N/A), index: 1, nativeID: "A"}',
'Insert {type: "View", parentNativeID: (N/A), index: 2, nativeID: "B"}',
]);
expect(root.getRenderedOutput({props: ['nativeID']}).toJSX()).toEqual(
expectedOutput,
);

render(false);
expect(root.takeMountingManagerLogs()).toEqual([
'Remove {type: "View", parentNativeID: (N/A), index: 2, nativeID: "B"}',
'Remove {type: "View", parentNativeID: (N/A), index: 1, nativeID: "A"}',
'Remove {type: "View", parentNativeID: (N/A), index: 0, nativeID: "K"}',
'Remove {type: "View", parentNativeID: "Q", index: 0, nativeID: (N/A)}',
'Delete {type: "View", nativeID: (N/A)}',
'Create {type: "View", nativeID: (N/A)}',
'Insert {type: "View", parentNativeID: (N/A), index: 0, nativeID: "K"}',
'Insert {type: "View", parentNativeID: (N/A), index: 1, nativeID: "A"}',
'Insert {type: "View", parentNativeID: (N/A), index: 2, nativeID: "B"}',
'Insert {type: "View", parentNativeID: "Q", index: 0, nativeID: (N/A)}',
]);
expect(root.getRenderedOutput({props: ['nativeID']}).toJSX()).toEqual(
expectedOutput,
);
});
});

describe('reconciliation of setNativeProps and React commit', () => {
Expand Down
Loading