# Trip recording widget

## **Principle**

The widget is a button that let the user control the trip recording. Possible actions are:

* Start a trip recording
* Check that the current trip is being recorded
* Stop a trip recording
* Cancel a trip recording.

## How to display the trip recording widget?

To integrate the trip recording widget into your application, simply add the code below:

```swift
let startStopTripButton = DriveKitTripAnalysisUI.shared.getTripRecordingButton(presentedIn: viewController)
```

The given `viewController` is used to present the stop trip confirmation dialog when the user taps the button in *trip in progress* state.&#x20;

{% hint style="info" %}
The given `viewController` is stored **weakly** by the button so you don’t need to worry about any retain cycle. Just pass the `viewController` that displays the button and you should be fine.
{% endhint %}

It can also be used when you call the `DKTripRecordingButton` public method `showConfirmationDialog()` on your button instance. This is useful if you need to programmatically display the dialog (for example, when the user taps a start trip notification).

{% hint style="warning" %}
**Warning**: This dialog won’t appear if the `DKTripRecordingUserMode` doesn’t allow the user to end a trip.
{% endhint %}

## Trip recording widget configurations

The button has 4 configurations to cover all possible scenarios, and its display can be adjusted using the `tripRecordingUserMode` parameter.

1. `.none`: The button is hidden and the trip recording is fully automatic. This is the simplest mode, and the one we prefer.<br>
2. `.startStop`: The button is displayed and the user has total control over the trip recording cycle: start, stop and cancel. In this configuration, autostart remains active.
3. `.startOnly`: The user can start a trip manually but cannot stop or cancel it under any circumstances. Recording stops automatically. In this configuration, autostart remains active.
4. `.stopOnly`: The user cannot start a trip manually. The start of a trip is detected automatically. The user can only stop the trip to get his results or cancel the recording if he is not the driver, for example.<br>

The default value is `.startStop`.

To set the button mode, call the following method before displaying the button:

```swift
DriveKitTripAnalysisUI.shared.tripRecordingUserMode = .startStop
```
