Skip to content

fix(iOS): header snapshots not working - #2393

Merged
kkafar merged 13 commits into
mainfrom
@alduzy/ios-header-snapshots-fix
Oct 15, 2024
Merged

kkafar merged 13 commits into
mainfrom
@alduzy/ios-header-snapshots-fix

Conversation

@alduzy

@alduzy alduzy commented Oct 7, 2024 •

Copy link
Copy Markdown
Contributor

Description

The updateViewControllerIfNeeded call introduced by #2230 forces the view controller to rebuild the subviews with the recent config.
When the screen is being unmounted it replaces the subviews with nil values as the reactSubviews are removed from the config one by one. Snapshots made earlier get discarded in the process.

This PR adds a condition that prevents updating the view controller when the screen is being changed + stops unnecessary snapshots when the screen is not changed.

Changes

  • updated Test556.tsx repro
  • added isGoingToBeRemoved property to RNSScreenView
  • making snapshots / updating the view controller conditionally

Test code and steps to reproduce

  • Use Test556.tsx repro

Checklist

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

@alduzy
alduzy requested review from kkafar and maciekstosio October 7, 2024 20:20

@kkafar kkafar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey, I need you to confirm that this PR does not introduce regression on #2230.
You can test specifically on @tboba's reproduction: #2230 (comment)

If we don't have a regression I need you to explain what other change fixed the issue mentioned in #2230. Otherwise I'm a bit reluctant, cause it might be working only by accident.

@alduzy

alduzy commented Oct 8, 2024

Copy link
Copy Markdown
Contributor Author

@kkafar Ok, I see. Thanks to @tboba's reproduction I was able to test it and it does in fact introduce regression. I'm going to keep working on it

@alduzy
alduzy marked this pull request as draft October 8, 2024 13:06
@alduzy
alduzy marked this pull request as ready for review October 14, 2024 07:42
@alduzy
alduzy requested a review from kkafar October 14, 2024 14:21

@kkafar kkafar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Few remarks. The logic looks good, I would only want you to change the naming.

Comment thread ios/RNSScreen.h Outdated
@property (nonatomic) react::LayoutMetrics newLayoutMetrics;
@property (weak, nonatomic) RNSScreenStackHeaderConfig *config;
@property (nonatomic, readonly) BOOL hasHeaderConfig;
@property (nonatomic) BOOL isGoingToBeRemoved;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don't need this in public API of Screen component

Suggested change
@property (nonatomic) BOOL isGoingToBeRemoved;

Comment thread ios/RNSScreen.h Resolved
Comment thread ios/RNSScreen.mm Resolved
alduzy and others added 3 commits October 15, 2024 10:16
Co-authored-by: Kacper Kafara <kacper.kafara@swmansion.com>
@kkafar
kkafar merged commit e4333a1 into main Oct 15, 2024
@kkafar
kkafar deleted the @alduzy/ios-header-snapshots-fix branch October 15, 2024 09:05
kkafar added a commit that referenced this pull request Oct 25, 2024
The `updateViewControllerIfNeeded` call introduced by
#2230
forces the view controller to rebuild the subviews with the recent
config.
When the screen is being unmounted it replaces the subviews with nil
values as the `reactSubviews` are removed from the config one by one.
Snapshots made earlier get discarded in the process.

This PR adds a condition that prevents updating the view controller when
the screen is being changed + stops unnecessary snapshots when the
screen is not changed.

- updated `Test556.tsx` repro
- added `isGoingToBeRemoved` property to `RNSScreenView`
- making snapshots / updating the view controller conditionally

 <!--
-->

- Use `Test556.tsx` repro

- [x] Included code example that can be used to test this change
- [x] Ensured that CI passes

---------

Co-authored-by: Kacper Kafara <kacper.kafara@swmansion.com>
Co-authored-by: Kacper Kafara <kacperkafara@gmail.com>
(cherry picked from commit e4333a1)
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