Skip to main content

OzoneView

This page contains additional details about how the OzoneView works and how to pass parameters to it. For a basic integration guide, see the quick setup section.

Effects

The OzoneView is designed to work without the implementor needing to program parts themselves. It achieves this by using a variety of effects that occur when the composition is presented on the screen. This section provides a summary of those effects.

OzoneInputData Handling

The composition contains a disposable effect that uses the provided OzoneInputData as a key. This effect initializes Ozone with the provided data. If the input data specifies to prevent screenshots, it will also set the WindowManager.LayoutParams.FLAG_SECURE on the window's flags. When this effect is disposed it will restore the original flags of the window and cancel the current ozone read if one is still in progress.

On Pause

The composition hooks into the Lifecycle.Event.ON_PAUSE event to stop the current Ozone read, if one is in progress. When resumed it will automatically be ready to read again once the user clicks the relevant button.

Back Handling

When on screen, the composition will assert itself as a BackHandler. If an Ozone read is in progress pressing back will gracefully stop the read. If one is not in progress the back button will move a user back through the guidance screens. If on the initial guidance screen, the back handler will invoke the onCancelCallback.

onSuccess and onError Handling

Finally the composition will create two LaunchedEffects which will invoke the onErrorCallback and onSuccessCallback when the conditions for those callbacks are met.

Method Signature

/**
* A [Composable] which performs an Ozone flow. This will manage creating and destroying instances
* of [Ozone] as needed. Simply provide the [OzoneInputData] as well as
* callback functions as listed.
*
* Note: This compose is currently designed to be locked to portrait.
*
* @param inputData An [OzoneInputData] matching the chip to be read.
* @param onSuccessCallback A unit function that will be invoked when a chip is successfully read.
* @param onErrorCallback A unit function that will be invoked when an error is encountered as part
* of the read process.
* @param onCancelCallback A unit function that will be invoked when a user attempts to cancel the
* read process.
*/
@Composable
fun OzoneView(
inputData: OzoneInputData,
onSuccessCallback: (OzoneResultData) -> Unit,
onErrorCallback: (SmartCaptureException) -> Unit,
onCancelCallback: () -> Unit,
modifier: Modifier = Modifier,
viewModel: OzoneViewModel = viewModel()
)

Within the OzoneView the root level composable's modifier will first try to fillMaxSize() and then apply the modifier provided to the OzoneView. The OzoneView is designed to be the only element on the screen. The modifier is provided to work with things like Constraint layouts, but not to be turned into a small element on the screen. Please use the modifier responsibly.

You should never need to specify the viewModel manually, let it use the default value.

Theme

OzoneView is currently designed for use with the SmartCaptureUiTheme included in commons. We strongly recommend using that included theme. If used with any other theme we cannot guarantee readability/good UX. Support for different themes may be added at a later point, but currently the view is only tested with the SmartCaptureUiTheme.