-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(IT Wallet): [SIW-675] Add QR Code screen during proximity flow (#…
…5238) ## Short description This PR adds the QRCode screen during proximity flow (for testing purposes the qr-code content is mocked with a fake mDoc payload). Having created the proximity package that uses an event manager on the UX/UI side, messages can be conveyed based on the progress of the presentation. I therefore used a loading message, a message that can vary based on the progress of the presentation. https://github.com/pagopa/io-app/assets/49342144/f55ffed6-0562-4bf1-880c-da7efc72eb2d ## List of changes proposed in this pull request - Add ItwPresentationQrCodeScreen.tsx ## How to test Open the credential details and tap "Show QR Code". The new screen should appear. --------- Co-authored-by: LazyAfternoons <[email protected]>
- Loading branch information
1 parent
485bc99
commit b732ece
Showing
8 changed files
with
124 additions
and
2 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
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
103 changes: 103 additions & 0 deletions
103
ts/features/it-wallet/screens/presentation/ItwPrProximityQrCodeScreen.tsx
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 |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import * as React from "react"; | ||
import { Image, SafeAreaView, View } from "react-native"; | ||
import RNQRGenerator from "rn-qr-generator"; | ||
import { IOStyles, LabelSmall, VSpacer } from "@pagopa/io-app-design-system"; | ||
import { useNavigation } from "@react-navigation/native"; | ||
import ItwLoadingSpinner from "../../components/ItwLoadingSpinner"; | ||
import { useOnFirstRender } from "../../../../utils/hooks/useOnFirstRender"; | ||
import { IOStackNavigationProp } from "../../../../navigation/params/AppParamsList"; | ||
import { ItwParamsList } from "../../navigation/ItwParamsList"; | ||
import I18n from "../../../../i18n"; | ||
import BaseScreenComponent from "../../../../components/screens/BaseScreenComponent"; | ||
import ItwKoView from "../../components/ItwKoView"; | ||
import { getItwGenericMappedError } from "../../utils/errors/itwErrorsMapping"; | ||
|
||
// A mocked QR code to be used in the proximity flow | ||
// TODO: remove this mocked QR code after the proximity flow is implemented [SIW-688] | ||
const mockedQrCode = | ||
"mdoc:owBjMS4wAYIB2BhYS6QBAiABIVggUCnUgO0nCmTWOkqZLpQJh1uO2Q0YCTbYtUowBJU6ltEiWCBPkYpJZpEY4emfmR_2eFS5XQN68wihmgEoiMVEf8M3_gKBgwIBowD0AfULUJr9sL_rAkZCk114baNK4rY"; | ||
|
||
/** | ||
* A screen that shows a QR code to be scanned by the other device | ||
* in order to start the proximity flow. | ||
*/ | ||
const ItwPrProximityQrCodeScreen = () => { | ||
const [qrCodeUri, setQrCodeUri] = React.useState(""); | ||
const [isLoading, setIsLoading] = React.useState(false); | ||
const [isError, setIsError] = React.useState(false); | ||
const navigation = useNavigation<IOStackNavigationProp<ItwParamsList>>(); | ||
useOnFirstRender(() => { | ||
RNQRGenerator.generate({ | ||
value: mockedQrCode, | ||
height: 300, | ||
width: 300, | ||
correctionLevel: "H" | ||
}) | ||
.then(({ uri }) => { | ||
setQrCodeUri(uri); | ||
setIsLoading(true); | ||
}) | ||
.catch(_ => { | ||
setIsError(true); | ||
}); | ||
}); | ||
|
||
/** | ||
* This component is used to display a loading spinner and a text. | ||
* It is used during proximity flow. After proximity integration [SIW-688] this | ||
* component could show a message to the user related to the several steps | ||
* of the proximity flow. | ||
* @returns a loading component which displays a loading spinner and a text. | ||
*/ | ||
const LoadingComponent = () => ( | ||
<View style={IOStyles.alignCenter}> | ||
<ItwLoadingSpinner /> | ||
<VSpacer size={8} /> | ||
<LabelSmall color={"black"} weight="Regular"> | ||
{I18n.t("features.itWallet.presentation.qrCodeScreen.loading")} | ||
</LabelSmall> | ||
</View> | ||
); | ||
|
||
/** | ||
* Error view component which currently displays a generic error. | ||
*/ | ||
const ErrorView = () => { | ||
const mappedError = getItwGenericMappedError(() => navigation.goBack()); | ||
return <ItwKoView {...mappedError} />; | ||
}; | ||
|
||
if (isError) { | ||
return <ErrorView />; | ||
} | ||
|
||
return ( | ||
<BaseScreenComponent goBack={true}> | ||
<SafeAreaView style={(IOStyles.flex, IOStyles.alignCenter)}> | ||
<View | ||
style={{ | ||
marginTop: 48, | ||
alignItems: "center" | ||
}} | ||
> | ||
{qrCodeUri !== "" && ( | ||
<> | ||
<LabelSmall color={"black"}> | ||
{"Il tuo codice QR personale"} | ||
</LabelSmall> | ||
<VSpacer size={16} /> | ||
<Image | ||
style={{ width: 300, height: 300 }} | ||
source={{ uri: qrCodeUri }} | ||
/> | ||
<VSpacer size={32} /> | ||
{isLoading && <LoadingComponent />} | ||
</> | ||
)} | ||
</View> | ||
</SafeAreaView> | ||
</BaseScreenComponent> | ||
); | ||
}; | ||
|
||
export default ItwPrProximityQrCodeScreen; |