Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(iOS): change implementation of calculating status bar, refactor methods used on header height change #1917

Merged
merged 17 commits into from
Oct 17, 2023

Conversation

tboba
Copy link
Member

@tboba tboba commented Oct 11, 2023

Description

It looks that sometimes when you're most likely on the first screen the initial header height (taken from the getDefaultHeaderHeight method) stays and is not being updated from the onHeaderHeightChange event. Also, when user hides the status bar it wasn't counted to the final value of header height. This PR fixes those problems and also other minor issues, related to the calculating header height.

Changes

  • Added calls for calculating header height on setting animated config and changing statusBarHidden prop.
  • Changed implementation of getCalculatedStatusBarHeightIsModal method.
  • Refactorized naming of the methods, related to the header height.
  • Added asserting modal hierarchy.

Test code and steps to reproduce

You can change Modals.tsx file by adding this snippet:

    const headerHeight = useAnimatedHeaderHeight();
    headerHeight.addListener((height) => console.log(height.value))

to the components and listen to the changes in Modals example. Then try to hide header in modals - there should be 0 value as a header height.

Checklist

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

@tboba tboba requested a review from kkafar October 11, 2023 08:11
@tboba tboba self-assigned this Oct 11, 2023
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.

I have left a question below

ios/RNSScreen.mm Outdated Show resolved Hide resolved
ios/RNSScreen.mm Outdated
Comment on lines 1082 to 1089
- (CGFloat)calculateHeaderHeightIsModal:(BOOL)isModal
{
CGFloat navbarHeight = [self getCalculatedHeaderHeightIsModal:isModal];
CGSize statusBarSize = [self getCalculatedStatusBarHeightIsModal:isModal];

// Unfortunately, UIKit doesn't care about switching width and height options on screen rotation.
// We should check if user has rotated its screen, so we're choosing the minimum value between the
// width and height.
CGFloat statusBarHeight = MIN(statusBarSize.width, statusBarSize.height);
return navbarHeight + statusBarHeight;
CGFloat navbarHeight = [self getNavigationBarHeightIsModal:isModal];
CGFloat navbarInset = [self getNavigationBarInsetIsModal:isModal];
return navbarHeight + navbarInset;
}

- (void)calculateAndNotifyHeaderHeightChangeIsModal:(BOOL)isModal
Copy link
Member Author

@tboba tboba Oct 11, 2023

Choose a reason for hiding this comment

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

Just one comment from me - leaving the name calculateHeaderHeightIsModal is made on purpose here. I did not change it to calculateNavigationBarHeightIsModal because for me header is the navigationBar + an inset of it - that's why I'm leaving it here.

@tboba tboba requested a review from kkafar October 11, 2023 09:46
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.

Few more remarks.

Also please update PR title before merging (as events are no longer sent on status bar visibility change)

ios/RNSScreenStackHeaderConfig.mm Outdated Show resolved Hide resolved
ios/RNSScreenStackHeaderConfig.mm Outdated Show resolved Hide resolved
Comment on lines +361 to +365
// As the header might have change in `updateViewController` we need to ensure that header height
// returned by the `onHeaderHeightChange` event is correct.
if ([vc isKindOfClass:[RNSScreen class]]) {
[(RNSScreen *)vc calculateAndNotifyHeaderHeightChangeIsModal:NO];
}
Copy link
Member

Choose a reason for hiding this comment

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

In this case I'm not sure, so we can leave it, but I have a feeling that it is also always RNSScreen.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's keep it for now - I'm afraid if there will be some cases that vc won't be actually RNSScreen (RNSScreenStack?) and that may cause some crashes on iOS.

ios/RNSScreen.mm Outdated Show resolved Hide resolved
@tboba tboba changed the title fix(iOS): Send events on setting animated config and changing status bar visibility fix(iOS): change implementation of calculating status bar, refactor naming Oct 11, 2023
@tboba tboba changed the title fix(iOS): change implementation of calculating status bar, refactor naming fix(iOS): change implementation of calculating status bar, refactor methods used on header height change Oct 11, 2023
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.

Looks good beside one thing I mention below

ios/RNSScreenStackHeaderConfig.mm Outdated Show resolved Hide resolved
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.

LGTM 🎉

@tboba
Copy link
Member Author

tboba commented Oct 11, 2023

Hey @kkafar, as I've made some changes (as I discovered a bug while testing modals 😅) and also refactorized even more some places, can you take a final look on the changes? 🙏

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.

Hey, I've found the use case I told you about yesterday: if headerShown: false is set on modal it won't have RNSNavigationController in its hierarchy.

image

Does the code cover this case?
I believe 0 should be returned.

@kkafar
Copy link
Member

kkafar commented Oct 13, 2023

Also after this PR is approved, please update PR description so that it reflects what actually this PR does.

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.

Few more remarks. Getting close

ios/RNSScreen.mm Outdated Show resolved Hide resolved
ios/RNSScreen.mm Outdated Show resolved Hide resolved
ios/RNSScreen.mm Outdated Show resolved Hide resolved
ios/RNSScreen.mm Show resolved Hide resolved
…chy to isModalWithHeader, move statusBarSize var
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.

🟢

@tboba tboba merged commit dbb7430 into main Oct 17, 2023
6 checks passed
@tboba tboba deleted the @tboba/header-height-improvements branch October 17, 2023 15:48
renovate bot referenced this pull request in valora-inc/wallet Nov 2, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[react-native-screens](https://togithub.com/software-mansion/react-native-screens)
| [`^3.25.0` ->
`^3.26.0`](https://renovatebot.com/diffs/npm/react-native-screens/3.25.0/3.26.0)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/react-native-screens/3.26.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/react-native-screens/3.26.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/react-native-screens/3.25.0/3.26.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/react-native-screens/3.25.0/3.26.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>software-mansion/react-native-screens
(react-native-screens)</summary>

###
[`v3.26.0`](https://togithub.com/software-mansion/react-native-screens/releases/tag/3.26.0)

[Compare
Source](https://togithub.com/software-mansion/react-native-screens/compare/3.25.0...3.26.0)

Minor release adding new useAnimatedHeaderHeight and
useReanimatedHeaderHeight hooks, providing fixes for search bar and
introducing internal changes. *Please note that new hooks introduced in
this release are fully functional on Paper, on Fabric there are few edge
cases we are still working on*.

#### What's Changed

#### 🐛 Bug fixes

- Change implementation of `headerConfig` prop on Android by
[@&#8203;tboba](https://togithub.com/tboba) in
[https://github.com/software-mansion/react-native-screens/pull/1883](https://togithub.com/software-mansion/react-native-screens/pull/1883)
- Change elements visibility on search bar open by
[@&#8203;tboba](https://togithub.com/tboba) in
[https://github.com/software-mansion/react-native-screens/pull/1903](https://togithub.com/software-mansion/react-native-screens/pull/1903)
- Fix positioning of large header and search bar by
[@&#8203;tboba](https://togithub.com/tboba) in
[https://github.com/software-mansion/react-native-screens/pull/1895](https://togithub.com/software-mansion/react-native-screens/pull/1895)
- Change implementation of calculating status bar, refactor methods used
on header height change by [@&#8203;tboba](https://togithub.com/tboba)
in
[https://github.com/software-mansion/react-native-screens/pull/1917](https://togithub.com/software-mansion/react-native-screens/pull/1917)
- Fix calculating header height when changing status/action bar
visibility by [@&#8203;tboba](https://togithub.com/tboba) in
[https://github.com/software-mansion/react-native-screens/pull/1922](https://togithub.com/software-mansion/react-native-screens/pull/1922)
- Allow Reanimated Screen to check large header by
[@&#8203;tboba](https://togithub.com/tboba) in
[https://github.com/software-mansion/react-native-screens/pull/1915](https://togithub.com/software-mansion/react-native-screens/pull/1915)
- Fix issue when emptying nav stack on Windows by
[@&#8203;chrisglein](https://togithub.com/chrisglein) in
[https://github.com/software-mansion/react-native-screens/pull/1890](https://togithub.com/software-mansion/react-native-screens/pull/1890)
- Update podspec to use install_modules_dependencies by
[@&#8203;cipolleschi](https://togithub.com/cipolleschi) in
[https://github.com/software-mansion/react-native-screens/pull/1920](https://togithub.com/software-mansion/react-native-screens/pull/1920)
- Remove MaxPerm args from JVM invocation by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[https://github.com/software-mansion/react-native-screens/pull/1888](https://togithub.com/software-mansion/react-native-screens/pull/1888)

#### 👍 Improvements

- Calculate values of useHeaderHeight natively by
[@&#8203;tboba](https://togithub.com/tboba) in
[https://github.com/software-mansion/react-native-screens/pull/1802](https://togithub.com/software-mansion/react-native-screens/pull/1802)
- Allow for different fragment types inside ScreenContainer by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[https://github.com/software-mansion/react-native-screens/pull/1887](https://togithub.com/software-mansion/react-native-screens/pull/1887)
- Add focused states on page transitions by
[@&#8203;tboba](https://togithub.com/tboba) in
[https://github.com/software-mansion/react-native-screens/pull/1894](https://togithub.com/software-mansion/react-native-screens/pull/1894)

#### 🔢 Miscellaneous

- **Create FUNDING.yml by
[@&#8203;aleqsio](https://togithub.com/aleqsio) in
[https://github.com/software-mansion/react-native-screens/pull/1886](https://togithub.com/software-mansion/react-native-screens/pull/1886)**
- Migrate from deprecated `RCTEventEmitter` by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[https://github.com/software-mansion/react-native-screens/pull/1867](https://togithub.com/software-mansion/react-native-screens/pull/1867)
- Use `require` syntax for resolution of all native components by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[https://github.com/software-mansion/react-native-screens/pull/1909](https://togithub.com/software-mansion/react-native-screens/pull/1909)
- Run Android e2e with JDK 17 by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[https://github.com/software-mansion/react-native-screens/pull/1892](https://togithub.com/software-mansion/react-native-screens/pull/1892)
- Put timelimit on execution of each workflow by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[https://github.com/software-mansion/react-native-screens/pull/1893](https://togithub.com/software-mansion/react-native-screens/pull/1893)
- Trigger e2e tests on JS-only changes by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[https://github.com/software-mansion/react-native-screens/pull/1910](https://togithub.com/software-mansion/react-native-screens/pull/1910)
- Update deprecated expo install instructions to `npx expo install` by
[@&#8203;GabrieldosSantosOliveira](https://togithub.com/GabrieldosSantosOliveira)
in
[https://github.com/software-mansion/react-native-screens/pull/1899](https://togithub.com/software-mansion/react-native-screens/pull/1899)
- Bump activesupport from 6.1.7.3 to 7.0.7.2 in /TestsExample by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/software-mansion/react-native-screens/pull/1877](https://togithub.com/software-mansion/react-native-screens/pull/1877)
- Update deps & RN in example apps after release by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[https://github.com/software-mansion/react-native-screens/pull/1878](https://togithub.com/software-mansion/react-native-screens/pull/1878)
- Migrate `Example` app & e2e tests to RN 0.72.4 by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[https://github.com/software-mansion/react-native-screens/pull/1880](https://togithub.com/software-mansion/react-native-screens/pull/1880)
- Bump library deps to recent versions (including RN) by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[https://github.com/software-mansion/react-native-screens/pull/1881](https://togithub.com/software-mansion/react-native-screens/pull/1881)
- Bump library native Android deps & config by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[https://github.com/software-mansion/react-native-screens/pull/1891](https://togithub.com/software-mansion/react-native-screens/pull/1891)

#### New Contributors

- [@&#8203;chrisglein](https://togithub.com/chrisglein) made their first
contribution in
[https://github.com/software-mansion/react-native-screens/pull/1890](https://togithub.com/software-mansion/react-native-screens/pull/1890)
-
[@&#8203;GabrieldosSantosOliveira](https://togithub.com/GabrieldosSantosOliveira)
made their first contribution in
[https://github.com/software-mansion/react-native-screens/pull/1899](https://togithub.com/software-mansion/react-native-screens/pull/1899)
- [@&#8203;cipolleschi](https://togithub.com/cipolleschi) made their
first contribution in
[https://github.com/software-mansion/react-native-screens/pull/1920](https://togithub.com/software-mansion/react-native-screens/pull/1920)

**Full Changelog**:
software-mansion/react-native-screens@3.25.0...3.26.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 5pm,every weekend" in timezone
America/Los_Angeles, Automerge - "after 5pm,every weekend" in timezone
America/Los_Angeles.

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/valora-inc/wallet).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xOS4yIiwidXBkYXRlZEluVmVyIjoiMzcuMTkuMiIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: valora-bot <[email protected]>
Co-authored-by: Silas Boyd-Wickizer <[email protected]>
Co-authored-by: Silas Boyd-Wickizer <[email protected]>
ja1ns pushed a commit to WiseOwlTech/react-native-screens that referenced this pull request Oct 9, 2024
…ethods used on header height change (software-mansion#1917)

## Description

It looks that sometimes when you're most likely on the first screen the
initial header height (taken from the `getDefaultHeaderHeight` method)
stays and is not being updated from the `onHeaderHeightChange` event.
Also, when user hides the status bar it wasn't counted to the final
value of header height. This PR fixes those problems and also other
minor issues, related to the calculating header height.

## Changes

- Added calls for calculating header height on setting animated config
and changing `statusBarHidden` prop.
- Changed implementation of `getCalculatedStatusBarHeightIsModal`
method.
- Refactorized naming of the methods, related to the header height.
- Added asserting modal hierarchy.

## Test code and steps to reproduce

You can change `Modals.tsx` file by adding this snippet:

```js
    const headerHeight = useAnimatedHeaderHeight();
    headerHeight.addListener((height) => console.log(height.value))
```

to the components and listen to the changes in `Modals` example. Then
try to hide header in modals - there should be `0` value as a header
height.

## Checklist

- [X] Included code example that can be used to test this change
- [ ] Ensured that CI passes
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