Skip to content

Commit

Permalink
Add back missing key prop for SceneWrapperFooter to fix rendering
Browse files Browse the repository at this point in the history
A change to fix a react warning (yellow box) removed the `key` prop
from SceneFooterWrapper which is required in order for the `onLayout`
handler to be invoked when transitioning between scenes causing a new
SceneFooterWrapper instance to be created in the `MenuTabs` component.
Without a key, the instance is considered a "re-render" of the same
React node and this will potentially omit a layout event from emitting
if the React node is the same layout dimensions. In order to force
React to treat these instances as indeed separate we leverage the `key`
prop. Luckily, it's only necessary to define a key at the top-most
component from `renderFooter`, so we don't need to use the `key` prop
within `SceneFooterWrapper`, so this is the correct way to resolve the
react warning.
  • Loading branch information
samholmes committed May 28, 2024
1 parent fddd10d commit ad0f8b3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/scenes/WalletListScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function WalletListScene(props: Props) {
sceneWrapperInfo => {
const key = 'WalletListScene-SearchFooter'
return sorting ? (
<SceneFooterWrapper sceneFooterKey={key} noBackgroundBlur sceneWrapperInfo={sceneWrapperInfo} onLayoutHeight={handleFooterLayoutHeight}>
<SceneFooterWrapper key={key} noBackgroundBlur sceneWrapperInfo={sceneWrapperInfo} onLayoutHeight={handleFooterLayoutHeight}>
<View style={styles.sortFooterContainer}>
<ButtonUi4 key="doneButton" mini type="primary" label={lstrings.string_done_cap} onPress={handlePressDone} />
</View>
Expand Down
9 changes: 5 additions & 4 deletions src/components/themed/SceneFooterWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import { styled } from '../hoc/styled'
import { BlurBackground } from '../ui4/BlurBackground'

export interface SceneFooterProps {
// This component requires a key for the onLayoutHeight prop
sceneFooterKey: string
// This component requires a key prop so that way the onLayoutHeight prop
// will work correctly.
// eslint-disable-next-line react/no-unused-prop-types
key: string

children: React.ReactNode
sceneWrapperInfo?: SceneWrapperInfo
Expand All @@ -22,7 +24,7 @@ export interface SceneFooterProps {
}

export const SceneFooterWrapper = (props: SceneFooterProps) => {
const { sceneFooterKey: key, children, noBackgroundBlur = false, sceneWrapperInfo, onLayoutHeight } = props
const { children, noBackgroundBlur = false, sceneWrapperInfo, onLayoutHeight } = props
const { hasTabs = true, isKeyboardOpen = false } = sceneWrapperInfo ?? {}
const footerOpenRatio = useSceneFooterState(state => state.footerOpenRatio)

Expand Down Expand Up @@ -52,7 +54,6 @@ export const SceneFooterWrapper = (props: SceneFooterProps) => {

return (
<ContainerAnimatedView
key={`${key}-ContainerAnimatedView`}
containerHeight={layout?.height}
footerOpenRatio={footerOpenRatio}
isKeyboardOpen={isKeyboardOpen}
Expand Down
2 changes: 1 addition & 1 deletion src/components/themed/SearchFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const SearchFooter = (props: SearchFooterProps) => {

return (
<SceneFooterWrapper
sceneFooterKey={`${name}-SceneFooterWrapper`}
key={`${name}-SceneFooterWrapper`}
noBackgroundBlur={noBackground}
sceneWrapperInfo={sceneWrapperInfo}
onLayoutHeight={handleFooterLayoutHeight}
Expand Down

0 comments on commit ad0f8b3

Please sign in to comment.