Skip to content

Commit 2eed7d3

Browse files
authored
feat(Android): Make commit hook condition for resetting screen size more general (#3508)
Closes software-mansion/react-native-screens-labs#598 ## Description This PR aims to generalize the condition in RNSScreenShadowNodeCommitHook to also include the screen resize, without orientation change. Let's discuss the change & decide how "general" should it be. Even when triggering the mechanism on every screen resize, this shouldn't be a problem, since the change is still rare. ## Changes Modified the screen size reset condition in RNSScreenShadowNodeCommitHook ## Before & After | Before | After | | --- | --- | | <video src="https://github.com/user-attachments/assets/4f4f562c-dafb-4881-9d27-9439d1375d34" /> | <video src="https://github.com/user-attachments/assets/d136bf0b-b87f-4ff9-866d-e5a4199be39c" /> | ## Test code and steps to reproduce Use Test2933 & try split screen, floating window.
1 parent 24af933 commit 2eed7d3

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

common/cpp/react/renderer/components/rnscreens/RNSScreenShadowNodeCommitHook.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ RootShadowNode::Unshared RNSScreenShadowNodeCommitHook::shadowTreeWillCommit(
3232
auto newRootProps =
3333
std::static_pointer_cast<const RootProps>(newRootShadowNode->getProps());
3434

35-
const bool wasHorizontal = isHorizontal_(*oldRootProps);
36-
const bool willBeHorizontal = isHorizontal_(*newRootProps);
37-
38-
if (wasHorizontal != willBeHorizontal) {
35+
// Check if screen area has changed size (either because of orientation
36+
// change, or application resize with floating window / split screen)
37+
if (_screenSizeChanged(*oldRootProps, *newRootProps)) {
3938
return newRootShadowNodeWithScreenFrameSizesReset(newRootShadowNode);
4039
}
4140

common/cpp/react/renderer/components/rnscreens/RNSScreenShadowNodeCommitHook.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,18 @@ class RNSScreenShadowNodeCommitHook : public UIManagerCommitHook {
2929
const ShadowTreeCommitOptions & /*commitOptions*/) noexcept override;
3030

3131
private:
32-
static inline bool isHorizontal_(const RootProps &props) {
33-
const auto &layoutConstraints = props.layoutConstraints;
34-
const float width = layoutConstraints.maximumSize.width;
35-
const float height = layoutConstraints.maximumSize.height;
36-
37-
return width > height;
38-
};
32+
static inline bool _screenSizeChanged(
33+
const RootProps &oldProps,
34+
const RootProps &newProps) {
35+
const auto &newLayoutConstraints = newProps.layoutConstraints;
36+
const auto &oldLayoutConstraints = oldProps.layoutConstraints;
37+
38+
return (
39+
newLayoutConstraints.maximumSize.width !=
40+
oldLayoutConstraints.maximumSize.width ||
41+
newLayoutConstraints.maximumSize.height !=
42+
oldLayoutConstraints.maximumSize.width);
43+
}
3944

4045
static RootShadowNode::Unshared newRootShadowNodeWithScreenFrameSizesReset(
4146
RootShadowNode::Unshared rootShadowNode);

0 commit comments

Comments
 (0)