-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Wallet] Fix last alert banner redisplayed on re-render (#6325)
### Description This fixes the regression described in #6314. The change in #6230 made the underlying problem in `AlertBanner` more prominent as it caused the top level navigator to re-render on app state change (background/foreground/inactive) and hence the `AlertBanner`. ### Other changes Globally mock `Animated.View` and `Animated.ScrollView` to prevent out of memory error when a ref is set. See callstack/react-native-testing-library#539 Note: This change caused the Snapshot updates, because the styles are not flattened anymore for the mocked `Animated.View`. ### Tested - Last alert is not redisplayed when navigating to different screens. - New alert banner with same content can still be redisplayed when dispatched (causing a state change). ### Related issues - Fixes #6314 ### Backwards compatibility Yes
- Loading branch information
1 parent
51f643d
commit d8bee97
Showing
21 changed files
with
1,100 additions
and
965 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,37 @@ | ||
import SmartTopAlert, { AlertTypes } from '@celo/react-components/components/SmartTopAlert' | ||
import * as React from 'react' | ||
import SmartTopAlert from '@celo/react-components/components/SmartTopAlert' | ||
import React, { memo, useMemo } from 'react' | ||
import { useDispatch } from 'react-redux' | ||
import { hideAlert } from 'src/alert/actions' | ||
import { ErrorDisplayType } from 'src/alert/reducer' | ||
import useSelector from 'src/redux/useSelector' | ||
|
||
export default function AlertBanner() { | ||
function AlertBanner() { | ||
const alert = useSelector((state) => state.alert) | ||
const dispatch = useDispatch() | ||
|
||
const onPress = () => { | ||
const action = alert?.action ?? hideAlert() | ||
dispatch(action) | ||
} | ||
const displayAlert = useMemo(() => { | ||
if (alert?.displayMethod === ErrorDisplayType.BANNER && (alert.title || alert.message)) { | ||
const onPress = () => { | ||
const action = alert?.action ?? hideAlert() | ||
dispatch(action) | ||
} | ||
|
||
return ( | ||
<SmartTopAlert | ||
isVisible={!!alert && alert.displayMethod === ErrorDisplayType.BANNER} | ||
// TODO: this looks like a hack to re-render, refactor! | ||
timestamp={Date.now()} | ||
text={alert && alert.message} | ||
onPress={onPress} | ||
type={alert && alert.type === 'error' ? AlertTypes.ERROR : AlertTypes.MESSAGE} | ||
dismissAfter={alert && alert.dismissAfter} | ||
buttonMessage={alert && alert.buttonMessage} | ||
title={alert && alert.title} | ||
/> | ||
) | ||
const { type, title, message, buttonMessage, dismissAfter } = alert | ||
|
||
return { | ||
type, | ||
title, | ||
message, | ||
buttonMessage, | ||
dismissAfter, | ||
onPress, | ||
} | ||
} else { | ||
return null | ||
} | ||
}, [alert]) | ||
|
||
return <SmartTopAlert alert={displayAlert} /> | ||
} | ||
|
||
export default memo(AlertBanner) |
Oops, something went wrong.