Repository navigation
Add profile QR code for sharing and inviting friends #10659
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
Changes from 13 commits
42732c8
11ff9fa
5b4d7fa
7e6198e
ac83105
1c68046
a202fd4
bb9f0b9
218c997
114bf0d
b9c5ef1
2e48d5c
27ab4af
19f0477
dad13d3
164584b
7b24015
4b9fa8e
24cfc39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| import {useCallback, useEffect} from 'react' | ||
| import {View} from 'react-native' | ||
| import {Image} from 'expo-image' | ||
| import {Trans, useLingui} from '@lingui/react/macro' | ||
|
|
||
| import {useCallOnce} from '#/lib/once' | ||
| import {atoms as a, useTheme, web} from '#/alf' | ||
| import {themes} from '#/alf/themes' | ||
| import {Button, ButtonText} from '#/components/Button' | ||
| import * as Dialog from '#/components/Dialog' | ||
| import {useNuxDialogContext} from '#/components/dialogs/nuxs' | ||
| import {Sparkle_Stroke2_Corner0_Rounded as SparkleIcon} from '#/components/icons/Sparkle' | ||
| import {Text} from '#/components/Typography' | ||
| import {useAnalytics} from '#/analytics' | ||
| import {IS_E2E, IS_NATIVE, IS_WEB} from '#/env' | ||
| import {createIsEnabledCheck} from './utils' | ||
|
|
||
| export const enabled = createIsEnabledCheck(() => { | ||
| // Native-only feature (matches the rest of the invite-friends scope). | ||
| // Skipped in E2E to keep tests deterministic. | ||
| return !IS_E2E && IS_NATIVE | ||
| }) | ||
|
|
||
| export function InviteFriendsAnnouncement() { | ||
| const t = useTheme() | ||
| const {t: l} = useLingui() | ||
| const ax = useAnalytics() | ||
| const nuxDialogs = useNuxDialogContext() | ||
| const control = Dialog.useDialogControl() | ||
|
|
||
| Dialog.useAutoOpen(control) | ||
|
|
||
| const firePresented = useCallOnce(() => { | ||
| ax.metric('invite:nux:presented', {}) | ||
| }) | ||
| useEffect(() => { | ||
| firePresented() | ||
| }, [firePresented]) | ||
|
|
||
| const onClose = useCallback(() => { | ||
| nuxDialogs.dismissActiveNux() | ||
| }, [nuxDialogs]) | ||
|
|
||
| const onPressTryIt = useCallback(() => { | ||
| ax.metric('invite:nux:tryItPressed', {}) | ||
| // Close this announcement (which dismisses + unmounts the NUX), then open | ||
| // the invite dialog. The invite dialog is mounted persistently by NuxDialogs | ||
| // (not here) so it survives the dismissal - the native bottom sheet cannot | ||
| // hand off to a second sheet mounted in this same subtree. Defer the open to | ||
| // the next frame so the announcement's teardown completes first. | ||
| control.close(() => { | ||
| requestAnimationFrame(() => nuxDialogs.openInviteFriends()) | ||
| }) | ||
| }, [ax, control, nuxDialogs]) | ||
|
|
||
| return ( | ||
| <> | ||
| <Dialog.Outer | ||
| control={control} | ||
| onClose={onClose} | ||
| nativeOptions={{preventExpansion: true}}> | ||
| <Dialog.Handle fill={t.palette.primary_400} /> | ||
|
|
||
| <Dialog.ScrollableInner | ||
| label={l`Invite your friends`} | ||
| style={[web({maxWidth: 440})]} | ||
| contentContainerStyle={[ | ||
| {paddingTop: 0, paddingLeft: 0, paddingRight: 0}, | ||
| ]}> | ||
| <View | ||
| style={[ | ||
| a.w_full, | ||
| a.relative, | ||
| a.overflow_hidden, | ||
| { | ||
| borderTopLeftRadius: a.rounded_md.borderRadius, | ||
| borderTopRightRadius: a.rounded_md.borderRadius, | ||
| }, | ||
| ]}> | ||
| {/* The image is the full header background; the tag sits on top of it. */} | ||
| <Image | ||
| accessibilityIgnoresInvertColors | ||
| source={require('../../../../assets/images/invite_friends_announcement_nux.webp')} | ||
| style={[a.w_full, {aspectRatio: 754 / 440}]} | ||
| alt={l`An illustration of the Bluesky app with a paper airplane flying out of it, representing inviting friends`} | ||
| /> | ||
| <View | ||
| style={[ | ||
| a.absolute, | ||
| a.align_center, | ||
| {top: 0, left: 0, right: 0, paddingTop: IS_WEB ? 24 : 20}, | ||
| ]}> | ||
| {/* Pinned to the light palette: the header illustration has a | ||
| fixed light background, so the tag must stay dark in any | ||
| theme to remain legible. */} | ||
| <View style={[a.flex_row, a.align_center, a.gap_xs]}> | ||
| <SparkleIcon fill={themes.lightPalette.primary_800} size="sm" /> | ||
| <Text | ||
| style={[ | ||
| a.font_semi_bold, | ||
| {color: themes.lightPalette.primary_800}, | ||
| ]}> | ||
| <Trans>New Feature</Trans> | ||
| </Text> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| <View style={[a.align_center, a.px_xl, a.pt_xl, a.gap_2xl, a.pb_sm]}> | ||
| <View style={[a.gap_sm, a.align_center]}> | ||
| <Text | ||
| style={[ | ||
| a.text_3xl, | ||
| a.leading_tight, | ||
| a.font_bold, | ||
| a.text_center, | ||
| {fontSize: IS_WEB ? 28 : 32, maxWidth: 300}, | ||
| ]}> | ||
| <Trans>Invite your friends</Trans> | ||
| </Text> | ||
| <Text | ||
| style={[ | ||
| a.text_md, | ||
| a.leading_snug, | ||
| a.text_center, | ||
| t.atoms.text_contrast_medium, | ||
| {maxWidth: 340}, | ||
| ]}> | ||
| <Trans> | ||
| You can now invite friends with a link or QR code. Share it | ||
| anywhere or let them scan to join you on Bluesky. | ||
| </Trans> | ||
| </Text> | ||
| </View> | ||
|
|
||
| {!IS_WEB && ( | ||
| <View style={[a.w_full, a.gap_sm]}> | ||
| <Button | ||
| label={l`Try it`} | ||
| size="large" | ||
| color="primary" | ||
| onPress={onPressTryIt} | ||
| style={[a.w_full]}> | ||
| <ButtonText> | ||
| <Trans>Try it</Trans> | ||
| </ButtonText> | ||
| </Button> | ||
| <Button | ||
| label={l`Cancel`} | ||
| size="large" | ||
| color="secondary" | ||
| onPress={() => control.close()} | ||
| style={[a.w_full]}> | ||
| <ButtonText> | ||
| <Trans>Cancel</Trans> | ||
| </ButtonText> | ||
| </Button> | ||
| </View> | ||
| )} | ||
| </View> | ||
|
|
||
| <Dialog.Close /> | ||
| </Dialog.ScrollableInner> | ||
| </Dialog.Outer> | ||
| </> | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,18 +18,31 @@ import { | |
| import {useProfileQuery} from '#/state/queries/profile' | ||
| import {type SessionAccount, useSession} from '#/state/session' | ||
| import {useOnboardingState} from '#/state/shell' | ||
| import * as Dialog from '#/components/Dialog' | ||
| import { | ||
| DraftsAnnouncement, | ||
| enabled as isDraftsAnnouncementEnabled, | ||
| } from '#/components/dialogs/nuxs/DraftsAnnouncement' | ||
| import { | ||
| enabled as isInviteFriendsAnnouncementEnabled, | ||
| InviteFriendsAnnouncement, | ||
| } from '#/components/dialogs/nuxs/InviteFriendsAnnouncement' | ||
| import {isSnoozed, snooze, unsnooze} from '#/components/dialogs/nuxs/snoozing' | ||
| import {type EnabledCheckProps} from '#/components/dialogs/nuxs/utils' | ||
| import {useAnalytics} from '#/analytics' | ||
| import {InviteFriendsDialog} from '#/features/inviteFriends' | ||
| import {useGeolocation} from '#/geolocation' | ||
|
|
||
| type Context = { | ||
| activeNux: Nux | undefined | ||
| dismissActiveNux: () => void | ||
| /** | ||
| * Opens the invite-friends dialog. It is mounted persistently by NuxDialogs | ||
| * (not inside the announcement NUX) so it survives the announcement being | ||
| * dismissed - the native bottom sheet cannot hand off between two sheets | ||
| * mounted in the same subtree. | ||
| */ | ||
| openInviteFriends: () => void | ||
| } | ||
|
|
||
| const queuedNuxs: { | ||
|
|
@@ -40,11 +53,16 @@ const queuedNuxs: { | |
| id: Nux.DraftsAnnouncement, | ||
| enabled: isDraftsAnnouncementEnabled, | ||
| }, | ||
| { | ||
| id: Nux.InviteFriendsAnnouncement, | ||
| enabled: isInviteFriendsAnnouncementEnabled, | ||
| }, | ||
| ] | ||
|
|
||
| const Context = createContext<Context>({ | ||
| activeNux: undefined, | ||
| dismissActiveNux: () => {}, | ||
| openInviteFriends: () => {}, | ||
| }) | ||
| Context.displayName = 'NuxDialogContext' | ||
|
|
||
|
|
@@ -97,6 +115,7 @@ function Inner({ | |
| const [activeNux, setActiveNux] = useState<Nux | undefined>() | ||
| const {mutateAsync: saveNux} = useSaveNux() | ||
| const {mutate: resetNuxs} = useResetNuxs() | ||
| const inviteFriendsControl = Dialog.useDialogControl() | ||
|
|
||
| const snoozeNuxDialog = useCallback(() => { | ||
| snooze() | ||
|
|
@@ -180,13 +199,26 @@ function Inner({ | |
| return { | ||
| activeNux, | ||
| dismissActiveNux, | ||
| openInviteFriends: () => { | ||
| ax.metric('invite:dialog:open', {logContext: 'NuxAnnouncement'}) | ||
| inviteFriendsControl.open() | ||
| }, | ||
| } | ||
| }, [activeNux, dismissActiveNux]) | ||
| }, [ax, activeNux, dismissActiveNux, inviteFriendsControl]) | ||
|
|
||
| return ( | ||
| <Context.Provider value={ctx}> | ||
| {/*For example, activeNux === Nux.NeueTypography && <NeueTypography />*/} | ||
| {activeNux === Nux.DraftsAnnouncement && <DraftsAnnouncement />} | ||
| {activeNux === Nux.InviteFriendsAnnouncement && ( | ||
| <InviteFriendsAnnouncement /> | ||
| )} | ||
| {/* | ||
| Mounted persistently (not inside the announcement) so the invite dialog | ||
| survives the announcement NUX being dismissed during the "Try it" | ||
| handoff. | ||
| */} | ||
| <InviteFriendsDialog control={inviteFriendsControl} /> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| </Context.Provider> | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import * as Dialog from '#/components/Dialog' | ||
| import {InviteFriendsDialogInner} from './InviteFriendsDialogInner' | ||
|
|
||
| export function InviteFriendsDialog({ | ||
| control, | ||
| onClose, | ||
| }: { | ||
| control: Dialog.DialogControlProps | ||
| onClose?: () => void | ||
| }) { | ||
| return ( | ||
| <Dialog.Outer | ||
| control={control} | ||
| onClose={onClose} | ||
| nativeOptions={{preventExpansion: true}}> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fwiw we have a |
||
| <InviteFriendsDialogInner control={control} /> | ||
| </Dialog.Outer> | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import {type DialogControlProps} from '#/components/Dialog' | ||
|
|
||
| /** | ||
| * Web no-op - the invite-friends share sheet is native-only by design. | ||
| * Callers may still create a Dialog control and pass it; opening it does | ||
| * nothing on web. | ||
| */ | ||
| export function InviteFriendsDialog(_props: { | ||
| control: DialogControlProps | ||
| onClose?: () => void | ||
| }) { | ||
| return null | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think the copy could be a bit clearer here. Over to Claude to explain better than I can: