From 5bc0bc3baf9e920cd2c8e8456b2a55502e087084 Mon Sep 17 00:00:00 2001 From: needJobCoder <97464694+needJobCoder@users.noreply.github.com> Date: Sat, 4 Jan 2025 23:56:52 +0530 Subject: [PATCH] added generate qr code in the profile menu ... dropdown --- .../Profile/Header/ProfileHeaderStandard.tsx | 97 ++----------------- src/screens/Profile/Header/QRModal.tsx | 73 ++++++++++++++ src/view/com/profile/ProfileMenu.tsx | 13 +++ 3 files changed, 93 insertions(+), 90 deletions(-) create mode 100644 src/screens/Profile/Header/QRModal.tsx diff --git a/src/screens/Profile/Header/ProfileHeaderStandard.tsx b/src/screens/Profile/Header/ProfileHeaderStandard.tsx index f196f679ef..ee5f7f42b6 100644 --- a/src/screens/Profile/Header/ProfileHeaderStandard.tsx +++ b/src/screens/Profile/Header/ProfileHeaderStandard.tsx @@ -1,7 +1,5 @@ import React, {memo, useMemo} from 'react' -import {Modal, Pressable, View} from 'react-native' -// @ts-expect-error missing types -import QRCodeStyled from 'react-native-qrcode-styled' +import {View} from 'react-native' import { AppBskyActorDefs, moderateProfile, @@ -11,7 +9,6 @@ import { import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {makeProfileLink} from '#/lib/routes/links' import {sanitizeDisplayName} from '#/lib/strings/display-names' import {logger} from '#/logger' import {isIOS, isWeb} from '#/platform/detection' @@ -41,6 +38,7 @@ import {ProfileHeaderDisplayName} from './DisplayName' import {EditProfileDialog} from './EditProfileDialog' import {ProfileHeaderHandle} from './Handle' import {ProfileHeaderMetrics} from './Metrics' +import QRCodeModal from './QRModal' import {ProfileHeaderShell} from './Shell' interface Props { profile: AppBskyActorDefs.ProfileViewDetailed @@ -150,9 +148,6 @@ let ProfileHeaderStandard = ({ ) const [qrModalVisible, setQRModalVisible] = React.useState(false) - const setQRModalVisibleTrue = () => { - setQRModalVisible(true) - } return ( ) : null} - - - - - + void // Receive the function to set visibility as a prop -} - -const QRCodeModal: React.FC = ({ - profile_, - visible, - setVisible, -}) => { - return ( - setVisible(false)} // Close modal when back button is pressed (for Android) - > - - - - - - {/* Pressable to close the modal */} - setVisible(false)} - style={{ - marginTop: 20, - backgroundColor: 'transparent', - padding: 10, - borderRadius: 5, - borderColor: 'white', - borderWidth: 1, - }}> - - Close - - - - - ) -} diff --git a/src/screens/Profile/Header/QRModal.tsx b/src/screens/Profile/Header/QRModal.tsx new file mode 100644 index 0000000000..ec0ce1663a --- /dev/null +++ b/src/screens/Profile/Header/QRModal.tsx @@ -0,0 +1,73 @@ +import React from 'react' +import {Modal, Pressable,View} from 'react-native' +// @ts-expect-error missing types +import QRCodeStyled from 'react-native-qrcode-styled' +import {AppBskyActorDefs} from '@atproto/api' +import {Trans} from '@lingui/macro' + +import {makeProfileLink} from '#/lib/routes/links' +import {ButtonText} from '#/components/Button' + +interface QRCodeModalProps { + profile_: AppBskyActorDefs.ProfileViewDetailed // Define the type of profile + visible: boolean // Receive the visibility status as a prop + setVisible: (visible: boolean) => void // Receive the function to set visibility as a prop +} + +const QRCodeModal: React.FC = ({ + profile_, + visible, + setVisible, +}) => { + return ( + setVisible(false)} // Close modal when back button is pressed (for Android) + > + + + + + + {/* Pressable to close the modal */} + setVisible(false)} + style={{ + marginTop: 20, + backgroundColor: 'transparent', + padding: 10, + borderRadius: 5, + borderColor: 'white', + borderWidth: 1, + }}> + + Close + + + + + ) +} + +export default QRCodeModal diff --git a/src/view/com/profile/ProfileMenu.tsx b/src/view/com/profile/ProfileMenu.tsx index f01fb5e172..95fbedf772 100644 --- a/src/view/com/profile/ProfileMenu.tsx +++ b/src/view/com/profile/ProfileMenu.tsx @@ -39,8 +39,12 @@ import {ReportDialog, useReportDialogControl} from '#/components/ReportDialog' let ProfileMenu = ({ profile, + isQRCodeModalVisible, + setIsQRCodeModalVisible, }: { profile: Shadow + isQRCodeModalVisible: boolean + setIsQRCodeModalVisible: React.Dispatch> }): React.ReactNode => { const {_} = useLingui() const {currentAccount, hasSession} = useSession() @@ -207,6 +211,15 @@ let ProfileMenu = ({ + setIsQRCodeModalVisible(!isQRCodeModalVisible)}> + + Generate QR Code + + + {hasSession && ( <>