Configure the SDK
The configuration process of the SDK has severable responsibilities:
Validation of the license key
Validating the currently present files
Downloading or updating the files required by the SDK to do recognition
Preparing the files to be used for inference
SDK Configure
useEffect
: Runs theconfigure
function once when the component mounts (because of the empty dependency array[]
).PassioSDK.configure
: Calls the Passio SDK configuration method with a key and options (debugMode
,autoUpdate
).If the SDK is ready (
status.mode === 'isReadyForDetection'
),loadingState
is updated to'ready'
.If there’s an error (
status.mode === 'error'
), the state is set to'error'
.If the status is
'notReady'
, nothing is done.
Error handling: If any error occurs during the configuration, the
catch
block sets theloadingState
to'error'
.
Track the progress of downloading Passio SDK model files
This is a method (from the Passio SDK) that registers callbacks for events related to model downloading: completedDownloadingFile: This callback is triggered when a file finishes downloading. The object passed to it contains filesLeft, which represents how many files are still left to download.
Camera authorization
You can use this hook in any functional component to check whether the app has camera authorization. For example:
How to handle configuration in the UI
In this component, PassioConfigurationView
, you're conditionally rendering different UI elements based on the sdkStatus
and leftFile
values. Here's a breakdown of how this works:
Switch on sdkStatus
:
The component switches between different UI layouts based on the current value of
sdkStatus
:Case
'ready'
: WhensdkStatus
is"ready"
, it displays a UI element that says SDK is Ready.Case
'error'
: IfsdkStatus
is"error"
, it shows an error message SDK is Error.Default case: If
sdkStatus
is anything else (including when it's'init'
or'downloading'
), it shows anActivityIndicator
(a loading spinner) and, ifleftFile
is notnull
, it displays how many files are left to download.
Check out the full code here. FULL CODE
Last updated