mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
e24ce708ab
Summary: Fixes https://github.com/facebook/react-native/issues/34120 The new React Native architecture doesn't check `needsCustomLayoutForChildren` so it wrongly positions native views on Android. In https://github.com/facebook/react-native/issues/34120 there are videos comparing the positioning of a native action view in the old and the new architecture. This PR passes the parent tag to the `updateLayout` method of the `SurfaceMountingManager`. The `SurfaceMountingManager` calls `needsCustomLayoutForChildren` on the parent view manager (copied the code from the `NativeViewHierarchyManager` in the old architecture). **NOTE** - I wasn't sure where to get the parent shadow view from so I've put in my best guesses where I could and left it as `{}` otherwise. ## Changelog [Android] [Fixed] - Migrate `needsCustomLayoutForChildren` check to the new architecture Pull Request resolved: https://github.com/facebook/react-native/pull/34254 Test Plan: I checked the fix in the repro from https://github.com/facebook/react-native/issues/34165. Here is a video of the action view closing using the native button that is now visible in the new architecture. https://user-images.githubusercontent.com/1761227/180607896-35bf477f-4552-4b8a-8e09-9e8c49122c0c.mov Reviewed By: cipolleschi Differential Revision: D38153924 Pulled By: javache fbshipit-source-id: e2c77fa70d725a33ce73fe4a615f6d884312580c
181 lines
5.7 KiB
C++
181 lines
5.7 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include "ShadowViewMutation.h"
|
|
|
|
#include <utility>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
/**
|
|
* Initialize static feature flags for this module.
|
|
* These flags should be treated as temporary.
|
|
*/
|
|
bool ShadowViewMutation::PlatformSupportsRemoveDeleteTreeInstruction = false;
|
|
|
|
ShadowViewMutation ShadowViewMutation::CreateMutation(ShadowView shadowView) {
|
|
return {
|
|
/* .type = */ Create,
|
|
/* .parentShadowView = */ {},
|
|
/* .oldChildShadowView = */ {},
|
|
/* .newChildShadowView = */ std::move(shadowView),
|
|
/* .index = */ -1,
|
|
};
|
|
}
|
|
|
|
ShadowViewMutation ShadowViewMutation::DeleteMutation(
|
|
ShadowView shadowView,
|
|
bool isRedundantOperation) {
|
|
return {
|
|
/* .type = */ Delete,
|
|
/* .parentShadowView = */ {},
|
|
/* .oldChildShadowView = */ std::move(shadowView),
|
|
/* .newChildShadowView = */ {},
|
|
/* .index = */ -1,
|
|
/* .isRedundantOperation */ isRedundantOperation,
|
|
};
|
|
}
|
|
|
|
ShadowViewMutation ShadowViewMutation::InsertMutation(
|
|
ShadowView parentShadowView,
|
|
ShadowView childShadowView,
|
|
int index) {
|
|
return {
|
|
/* .type = */ Insert,
|
|
/* .parentShadowView = */ std::move(parentShadowView),
|
|
/* .oldChildShadowView = */ {},
|
|
/* .newChildShadowView = */ std::move(childShadowView),
|
|
/* .index = */ index,
|
|
};
|
|
}
|
|
|
|
ShadowViewMutation ShadowViewMutation::RemoveMutation(
|
|
ShadowView parentShadowView,
|
|
ShadowView childShadowView,
|
|
int index,
|
|
bool isRedundantOperation) {
|
|
return {
|
|
/* .type = */ Remove,
|
|
/* .parentShadowView = */ std::move(parentShadowView),
|
|
/* .oldChildShadowView = */ std::move(childShadowView),
|
|
/* .newChildShadowView = */ {},
|
|
/* .index = */ index,
|
|
/* .isRedundantOperation */ isRedundantOperation,
|
|
};
|
|
}
|
|
|
|
ShadowViewMutation ShadowViewMutation::RemoveDeleteTreeMutation(
|
|
ShadowView parentShadowView,
|
|
ShadowView childShadowView,
|
|
int index) {
|
|
return {
|
|
/* .type = */ RemoveDeleteTree,
|
|
/* .parentShadowView = */ std::move(parentShadowView),
|
|
/* .oldChildShadowView = */ std::move(childShadowView),
|
|
/* .newChildShadowView = */ {},
|
|
/* .index = */ index,
|
|
};
|
|
}
|
|
|
|
ShadowViewMutation ShadowViewMutation::UpdateMutation(
|
|
ShadowView oldChildShadowView,
|
|
ShadowView newChildShadowView,
|
|
ShadowView parentShadowView) {
|
|
return {
|
|
/* .type = */ Update,
|
|
/* .parentShadowView = */ std::move(parentShadowView),
|
|
/* .oldChildShadowView = */ std::move(oldChildShadowView),
|
|
/* .newChildShadowView = */ std::move(newChildShadowView),
|
|
/* .index = */ -1,
|
|
};
|
|
}
|
|
|
|
bool ShadowViewMutation::mutatedViewIsVirtual() const {
|
|
bool viewIsVirtual = false;
|
|
|
|
#ifdef ANDROID
|
|
// Explanation: Even for non-virtual views,
|
|
// for "Insert" mutations, oldChildShadowView is always empty.
|
|
// for "Remove" mutations, newChildShadowView is always empty.
|
|
// Thus, to see if a view is virtual, we need to always check both the old and
|
|
// new View.
|
|
viewIsVirtual = newChildShadowView.layoutMetrics == EmptyLayoutMetrics &&
|
|
oldChildShadowView.layoutMetrics == EmptyLayoutMetrics;
|
|
#endif
|
|
|
|
return viewIsVirtual;
|
|
}
|
|
|
|
ShadowViewMutation::ShadowViewMutation(
|
|
Type type,
|
|
ShadowView parentShadowView,
|
|
ShadowView oldChildShadowView,
|
|
ShadowView newChildShadowView,
|
|
int index,
|
|
bool isRedundantOperation)
|
|
: type(type),
|
|
parentShadowView(std::move(parentShadowView)),
|
|
oldChildShadowView(std::move(oldChildShadowView)),
|
|
newChildShadowView(std::move(newChildShadowView)),
|
|
index(index),
|
|
isRedundantOperation(isRedundantOperation) {}
|
|
|
|
#if RN_DEBUG_STRING_CONVERTIBLE
|
|
|
|
std::string getDebugName(ShadowViewMutation const &mutation) {
|
|
switch (mutation.type) {
|
|
case ShadowViewMutation::Create:
|
|
return "Create";
|
|
case ShadowViewMutation::Delete:
|
|
return "Delete";
|
|
case ShadowViewMutation::Insert:
|
|
return "Insert";
|
|
case ShadowViewMutation::Remove:
|
|
return "Remove";
|
|
case ShadowViewMutation::Update:
|
|
return "Update";
|
|
case ShadowViewMutation::RemoveDeleteTree:
|
|
return "RemoveDeleteTree";
|
|
}
|
|
}
|
|
|
|
std::vector<DebugStringConvertibleObject> getDebugProps(
|
|
ShadowViewMutation const &mutation,
|
|
DebugStringConvertibleOptions options) {
|
|
return {
|
|
mutation.oldChildShadowView.componentHandle
|
|
? DebugStringConvertibleObject{"oldChild",
|
|
getDebugDescription(
|
|
mutation.oldChildShadowView,
|
|
options)}
|
|
: DebugStringConvertibleObject{},
|
|
mutation.newChildShadowView.componentHandle
|
|
? DebugStringConvertibleObject{"newChild",
|
|
getDebugDescription(
|
|
mutation.newChildShadowView,
|
|
options)}
|
|
: DebugStringConvertibleObject{},
|
|
mutation.parentShadowView.componentHandle
|
|
? DebugStringConvertibleObject{"parent",
|
|
getDebugDescription(
|
|
mutation.parentShadowView,
|
|
options)}
|
|
: DebugStringConvertibleObject{},
|
|
mutation.index != -1
|
|
? DebugStringConvertibleObject{"index",
|
|
getDebugDescription(
|
|
mutation.index, options)}
|
|
: DebugStringConvertibleObject{},
|
|
};
|
|
}
|
|
|
|
#endif
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|