Skip to content

Conversation

t0maboro
Copy link
Contributor

@t0maboro t0maboro commented Jul 30, 2025

Description

Closes:
https://github.com/software-mansion/react-native-screens-labs/issues/156

Problem:

  • Controller has a strong reference to an associated component via .view property.
  • In our case, Component keeps a strong reference to the controller.
  • This creates a retain cycle, which we're not breaking anywhere at the moment.

Solution:
SplitViewHost keeps references to all subviews of type SplitViewScreen all the time (columns might be hidden, but they won't disappear). It means that we can consider Host as an owner of the SplitViewScreens' lifecycles. If the host is about to be unmounted from the view hierarchy, we can perform some additional cleanup in child components to detach the reference to theirs controllers.

Changes

  • Added a method for invalidating a screen component that removes a reference to the controller.

Test code and steps to reproduce

Create an example that includes a SplitView, which may be removed from the hierarchy, add log and observe.

Checklist

  • Included code example that can be used to test this change
  • Ensured that CI passes

Copy link
Member

@kkafar kkafar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added clarification comments. I'd also move the for loop that invalidates the children into separate method, e.g. invalidate :D

@t0maboro t0maboro requested a review from kkafar July 30, 2025 09:32
Copy link
Member

@kkafar kkafar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Let's do something similar for bottom tabs implementation (in separate PR obviously)

@t0maboro
Copy link
Contributor Author

Thanks!

Let's do something similar for bottom tabs implementation (in separate PR obviously)

#3085 - created a followup for bottom tabs

@t0maboro t0maboro merged commit 1f6b3cb into main Jul 30, 2025
4 of 5 checks passed
@t0maboro t0maboro deleted the @t0maboro/break-retain-cycle-split-screen branch July 30, 2025 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants