Composition
In addition to supporting implementation via Activity
(described in quick setup) the SDK also supports implementation via Compose/Composition.
Instantiate the class
First create an instance of the following class:
/**
* A container class that can create a composition that allows a user to capture a face photo.
*
* @property faceCameraListener A [FaceCameraListener] that responds to user actions in the
* composition.
*/
class FaceCamera (
private val faceCameraListener: FaceCameraListener
)
The FaceCameraListener
is an interface that should be implemented by the calling activity, either directly or indirectly.
/**
* A listener for the [FaceCamera] composition.
*/
interface FaceCameraListener {
/**
* Called after a successful capture.
*
* @param faceCameraResult A [FaceCameraResult] that encloses an encrypted blob and an
* unencrypted preview image.
*/
fun onCapture(faceCameraResult: FaceCameraResult)
/**
* Called when an error occurs.
*
* @param error A [SmartCaptureException] that will provide any available info about the error.
*/
fun onError(error: SmartCaptureException)
/**
* Called when the user has canceled. Should navigate away from the composition to the
* relevant screen.
*/
fun onCancel()
}
Start the Camera
First check camera permissions and if not present obtain the camera permission. The camera will error if the camera permission is not present.
After ensuring that the camera permissions are present, start the camera by calling the following Compose
function on the class instance created in the previous step:
faceCameraInstance.FaceCameraView()
Note: This is a Compose
function and therefore must be called from another composition.
Note: This composition when present will assert itself as a BackHandler
and therefore will intercept back pressed events and issue an onCancel
call.