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(FX-4762): Support CTA in Toast #8627

Merged
merged 5 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app/Components/ArtworkLists/useArtworkListsToast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const useArtworkListToast = () => {

toast.show(message, DEFAULT_TOAST_PLACEMENT, {
backgroundColor: "green100",
cta: "View List",
onPress: () => {
navigate(`/artwork-list/${artworkList.internalID}`)
},
Expand All @@ -41,6 +42,7 @@ export const useArtworkListToast = () => {

toast.show(message, DEFAULT_TOAST_PLACEMENT, {
backgroundColor: "green100",
cta: "View Saves",
onPress: () => {
navigate(`/artwork-lists`)
},
Expand Down
22 changes: 15 additions & 7 deletions src/app/Components/Toast/ToastComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Flex, useColor, Text } from "@artsy/palette-mobile"
import { Flex, useColor, Text, Touchable } from "@artsy/palette-mobile"
import { useActionSheet } from "@expo/react-native-action-sheet"
import { GlobalStore } from "app/store/GlobalStore"
import { Touchable } from "@artsy/palette-mobile"
import { useScreenDimensions } from "app/utils/hooks"
import { useEffect, useState } from "react"
import { Animated } from "react-native"
import useTimeoutFn from "react-use/lib/useTimeoutFn"
import { useScreenDimensions } from "app/utils/hooks"
import { ToastDetails, ToastDuration } from "./types"

const AnimatedFlex = Animated.createAnimatedComponent(Flex)
Expand All @@ -30,6 +29,7 @@ export const ToastComponent = ({
Icon,
backgroundColor = "black100",
duration = "short",
cta,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

question: should we support "CTA" for toasts placed in the middle? It seems to me that this is not necessary. what do you think? 🤔

for-question

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure, this kind of middle CTA doesn't even exist in our DS, I'd expect the toasts we have there with the desired position.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, good point!

}: ToastDetails) => {
const toastDuration = TOAST_DURATION_MAP[duration]
const color = useColor()
Expand Down Expand Up @@ -97,9 +97,18 @@ export const ToastComponent = ({
const innerTopBottom = (
<Flex flex={1} flexDirection="row" alignItems="center" mx={2}>
{Icon !== undefined ? <Icon fill="white100" width={25} height={25} mr={1} /> : null}
<Text variant="xs" color="white100">
{message}
</Text>

<Flex flex={1}>
<Text variant="xs" color="white100">
{message}
</Text>
</Flex>

{!!cta && (
<Text variant="xs" color="white100" underline>
{cta}
</Text>
)}
</Flex>
)

Expand Down Expand Up @@ -128,7 +137,6 @@ export const ToastComponent = ({
backgroundColor={color(backgroundColor)}
opacity={opacityAnim.interpolate({ inputRange: [0, 1], outputRange: [0, 1] })}
overflow="hidden"
paddingRight={2}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

paddingRight prop was added in this PR. I checked with @araujobarret, he doesn't mind if we remove it (since there is some UI problem when clicking on toast because of this. See attached video)

Video Screenshots
demo.mp4
demo

zIndex={999}
>
{onPress !== undefined ? (
Expand Down
8 changes: 7 additions & 1 deletion src/app/Components/Toast/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ export interface ToastDetails {
placement: ToastPlacement
message: string

/* Display CTA for toasts with top or bottom placement */
cta?: string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

or is ctaText better?

Copy link
Contributor

Choose a reason for hiding this comment

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

personal opinion: cta of type string it's already self-explanatory to me 👍


onPress?: (helpers: ToastOnPressHelpers) => void
Icon?: React.FC<IconProps>
backgroundColor?: Color
duration?: ToastDuration
}

export type ToastOptions = Pick<ToastDetails, "onPress" | "Icon" | "backgroundColor" | "duration">
export type ToastOptions = Pick<
ToastDetails,
"onPress" | "Icon" | "backgroundColor" | "duration" | "cta"
>