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: Elevation context wrapping #14593

Merged
merged 1 commit into from
Sep 27, 2024
Merged

Conversation

peter-sanderson
Copy link
Contributor

Fixes the incorrect use of React Context so the elevation value is passed down correctly.

This also fixes the base elevation of modal, as elevation context sets the elevation of the plane the NewModal is onto.

image

);
};

const NewModalBase = (props: NewModalProps) => (
<ElevationContext baseElevation={prevElevation[MODAL_ELEVATION]}>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here the prevElevation must be used, as ElevationContext sets the level of the plane, on which NewModal sits on.

If we want NewModal to be 0 it must sit on plane of elevation -1

@peter-sanderson peter-sanderson force-pushed the fix_elevation_for_new_modal branch from f133c61 to aad54be Compare September 27, 2024 17:26
)}
</Header>
<Container
$elevation={elevation}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

MODAL_ELEVATION no longer needs to be hard-coded as we can use value from useElevation now, because we are in nested component and the Context (ElevationContext) of this component is correctly set by React.

@@ -131,7 +131,7 @@ type NewModalProps = AllowedFrameProps & {
'data-testid'?: string;
};

const NewModalBase = ({
const _NewModalBase = ({
Copy link
Contributor

Choose a reason for hiding this comment

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

I really don't like this naming:D There must be something better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Feel free to come up with better name / rename it later ;)

{children}
</Body>
</ScrollContainer>
<ShadowBottom backgroundColor={modalBackgroundColor} />
Copy link
Contributor Author

@peter-sanderson peter-sanderson Sep 27, 2024

Choose a reason for hiding this comment

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

Problem here is, that ShadowBottom component is placed in JSX in the context of NewModalBase parent component.

The fact its wrapped in <ElevationContext ... does not set its context to it, but keeps the context of the NewModalBase.

We have to create new component function, so the new context is created and the correct elevation value is retrieved from it (in this case the value -1 + 1 = 0 <-- correct.

The reason why it "worked" (kinda), is because useElevation has a default behavior and fallbacks to 0 (which resulted in this case in 0 + 1 = 1 <-- incorrect.

In the light of this issue, I kinda think we should remove default behavior and throw error if useElevation is used without context being set.

Defaults are evil.

cc @jvaclavik ☝️

image

@peter-sanderson peter-sanderson merged commit 03347b5 into develop Sep 27, 2024
22 checks passed
@peter-sanderson peter-sanderson deleted the fix_elevation_for_new_modal branch September 27, 2024 17:51
@bosomt
Copy link
Contributor

bosomt commented Oct 1, 2024

QA OK

Info:

  • Suite version: desktop 24.10.0 (2187dc0)
  • Browser: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) TrezorSuiteDev/24.10.0 Chrome/126.0.6478.234 Electron/31.6.0 Safari/537.36
  • OS: MacIntel
  • Screen: 1512x982
  • Device: Trezor T2T1 2.8.1 regular (revision 632b9561559b7ab6824bb7eeac072874e07b7b82)
  • Transport: BridgeTransport 3.0.0-bundled.24.10.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants