Skip to content

Commit

Permalink
Refactor the fix completely: use ShadowNoteTraits::RootNodeKind to ha…
Browse files Browse the repository at this point in the history
…ndle the situation
  • Loading branch information
kkafar committed Jan 23, 2025
1 parent dca778f commit 45e643f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,4 @@ namespace facebook::react {

extern const char RNSFullWindowOverlayComponentName[] = "RNSFullWindowOverlay";

#if !defined(ANDROID)
void RNSFullWindowOverlayShadowNode::layout(LayoutContext layoutContext) {
YogaLayoutableShadowNode::layout(layoutContext);

applyFrameCorrections();
}

void RNSFullWindowOverlayShadowNode::applyFrameCorrections() {
ensureUnsealed();

const auto &stateData = getStateData();

// During mounting phase due to view flattening the frame origin can be
// offsetted by non-zero point value, while we require FullWindowOverlay view
// to be always positioned at (0, 0). By adding this correction, the view will
// be positioned at (0, 0) after mounting stage finishes. See:
// https://github.com/software-mansion/react-native-screens/pull/2641
layoutMetrics_.frame.origin -= stateData.contentOffset;
}
#endif // !ANDROID

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,24 @@ namespace facebook::react {

JSI_EXPORT extern const char RNSFullWindowOverlayComponentName[];

using ConcreteViewShadowNodeSuperType = ConcreteViewShadowNode<
RNSFullWindowOverlayComponentName,
RNSFullWindowOverlayProps,
RNSFullWindowOverlayEventEmitter,
RNSFullWindowOverlayState>;

class JSI_EXPORT RNSFullWindowOverlayShadowNode final
: public ConcreteViewShadowNode<
RNSFullWindowOverlayComponentName,
RNSFullWindowOverlayProps,
RNSFullWindowOverlayEventEmitter,
RNSFullWindowOverlayState> {
: public ConcreteViewShadowNodeSuperType {
public:
using ConcreteViewShadowNode::ConcreteViewShadowNode;
using StateData = ConcreteViewShadowNode::ConcreteStateData;

#if !defined(ANDROID)
void layout(LayoutContext layoutContext) override;

void applyFrameCorrections();
static ShadowNodeTraits BaseTraits() {
auto traits = ConcreteViewShadowNodeSuperType::BaseTraits();
traits.set(ShadowNodeTraits::Trait::RootNodeKind);
return traits;
}
#endif
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ class JSI_EXPORT RNSFullWindowOverlayState final {
return {};
}
#endif

#if !defined(ANDROID)
RNSFullWindowOverlayState(Point contentOffset_)
: contentOffset{contentOffset_} {}
#endif

#if !defined(ANDROID)
/// Content offset caused by view flattening. iOS only.
Point contentOffset{};
#endif
};

} // namespace facebook::react
16 changes: 3 additions & 13 deletions ios/RNSFullWindowOverlay.mm
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ @implementation RNSFullWindowOverlay {
CGRect _reactFrame;
#ifdef RCT_NEW_ARCH_ENABLED
RCTSurfaceTouchHandler *_touchHandler;
react::Point _lastContentOffset;
react::RNSFullWindowOverlayShadowNode::ConcreteState::Shared _state;
#else
RCTTouchHandler *_touchHandler;
#endif // RCT_NEW_ARCH_ENABLED
Expand All @@ -94,7 +92,6 @@ - (instancetype)init
if (self = [super init]) {
static const auto defaultProps = std::make_shared<const react::RNSFullWindowOverlayProps>();
_props = defaultProps;
_lastContentOffset = {0.f, 0.f};
[self _initCommon];
}
return self;
Expand Down Expand Up @@ -212,22 +209,15 @@ - (void)updateLayoutMetrics:(react::LayoutMetrics const &)layoutMetrics

// Due to view flattening on new architecture there are situations
// when we receive frames with origin different from (0, 0).
// We account for this frame manipulation in shadow node by setting
// RootNodeKind trait for the shadow node making state consistent
// between Host & Shadow Tree
frame.origin = CGPointZero;

_reactFrame = frame;
[_container setFrame:frame];

if (_lastContentOffset != layoutMetrics.frame.origin && _state) {
_lastContentOffset = layoutMetrics.frame.origin;
_state->updateState(react::RNSFullWindowOverlayState(_lastContentOffset));
}
}

- (void)updateState:(const facebook::react::State::Shared &)state
oldState:(const facebook::react::State::Shared &)oldState
{
_state = std::static_pointer_cast<const react::RNSFullWindowOverlayShadowNode::ConcreteState>(state);
}
RNS_IGNORE_SUPER_CALL_END

#else
Expand Down

0 comments on commit 45e643f

Please sign in to comment.