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

feat: add headers to modal #821

Merged
merged 12 commits into from
May 7, 2021
Merged

Conversation

WoLewicki
Copy link
Member

@WoLewicki WoLewicki commented Feb 18, 2021

Description

Added option for achieving headers in modal on iOS. The change is based on adding additional ScreenStack to every modal Screen component and adding the HeaderConfig component to upper or lower Screen based on the stackPresentation to ensure proper header transitions. Modal headers will not have the back button on iOS, since the header comes from the nested stack there and has no previous screen. Requested in #800.

Changes

Changed NativeStackView.tsx to contain nested ScreenStack with proper HeaderConfig component manipulation. Same with v4 native-stack.

Test code and steps to reproduce

Test800.tsx in TestsExample. It will require to test many scenarios in order to make sure it doesn't break anything.

Checklist

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

Copy link
Member

@kacperkapusciak kacperkapusciak left a comment

Choose a reason for hiding this comment

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

I've found out that the header background color behaves unpredictably. It seems like it sometimes makes itself transparent:

Modal.header.color.cyan.mov
Modal.header.color.mov

image

TestsExample/src/Test800.tsx Outdated Show resolved Hide resolved
Copy link
Member

@kacperkapusciak kacperkapusciak left a comment

Choose a reason for hiding this comment

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

Left some comments but looks good overall 🙌 Good job! 🎉

src/native-stack/views/NativeStackView.tsx Outdated Show resolved Hide resolved
src/native-stack/views/NativeStackView.tsx Show resolved Hide resolved
src/createNativeStackNavigator.js Outdated Show resolved Hide resolved
index: number,
descriptor: NativeStackDescriptor
) => {
if (isHeaderInModal) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This may be problematic if this option changes dynamically as it'll unmount the previous component and render new one, and all state will be destroyed.

@niklasgrewe
Copy link

any news on this pr? I am looking also for this feature 👍

@WoLewicki
Copy link
Member Author

Hopefully this will be merged soon. You can always patch-package these changes into your project to see how it works and give us feedback.

@AzzouQ
Copy link
Contributor

AzzouQ commented Apr 13, 2021

I've found out that the header background color behaves unpredictably. It seems like it sometimes makes itself transparent:

Modal.header.color.cyan.mov
Modal.header.color.mov
image

Same here, otherwise it's very nice to finally see that implemented 🥳

@KingAmo
Copy link

KingAmo commented Apr 20, 2021

any update?

@WoLewicki WoLewicki linked an issue May 7, 2021 that may be closed by this pull request
@WoLewicki WoLewicki merged commit 3078dc7 into master May 7, 2021
@WoLewicki WoLewicki deleted the @wolewicki/add-header-in-modal branch May 7, 2021 10:21
Comment on lines +133 to +142
if (
!didWarn &&
stackPresentation !== 'push' &&
headerShown !== undefined
) {
didWarn = true;
console.warn(
'Be aware that changing the visibility of header in modal on iOS will result in resetting the state of the screen.'
);
}

Choose a reason for hiding this comment

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

@WoLewicki Would it not make more sense to warn about this whenever a visibility change actually happens?

Now I get a warning every time I run the app and open a modal despite having a static headerShown: false that will never cause this issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

We would need to keep track of the previous value of this prop in order to do that, and I am not sure if it is a good idea. Also, if you do not want the header to be shown, you can just not change the prop in modal screens at all. You can easily remove the warning by using LogBox.ignoreLogs.

Choose a reason for hiding this comment

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

Yeah, good point.

I see it's triggered due to screenOptions={{ headerShown: false }} on the navigator. I know you suggest setting headerShown on each screen instead, but why is that suggested exactly?

You can easily remove the warning by using LogBox.ignoreLogs.

headerShown: undefined on the modal screen works as well, as it seems to override the navigator's headerShown.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, setting props on individual screens override the options set in navigator's screenOptions.

Copy link

Choose a reason for hiding this comment

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

I understand, then basically I can ignore the warning if I did not intentionally change headerShown prop. Just to make sure I am not doing anything wrong by paying attention to all warnings. :)

WoLewicki added a commit that referenced this pull request May 20, 2021
Added option for achieving headers in modal on iOS. The change is based on adding additional ScreenStack to every modal Screen component and adding the HeaderConfig component to upper or lower Screen based on the stackPresentation to ensure proper header transitions. Modal headers will not have the back button on iOS, since the header comes from the nested stack there and has no previous screen.
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.

Allow headers when stack presentation = "modal"
8 participants