Skip to content

Return Home

Cristina Suciu edited this page Dec 23, 2020 · 1 revision

A button that performs actions related to returning home. There are two primary states for the widget: ready to return home, and returning home in progress. Clicking the button when the aircraft is ready to return home will open a dialog to confirm returning to home.

Return Home Widget states

Image State Description Dialog shown when tapped
Ready to Return Home The aircraft is flying. Tapping will show a dialog to confirm return home
Returning Home The aircraft is returning home N/A
Forced Returning Home In Progress The aircraft is returning home and it cannot be canceled N/A
Hidden Disconnected The aircraft is disconnected N/A
Hidden Landing In Progress The aircraft is landing. Use the Take Off Widget to allow the user to cancel this action. N/A

When the slider is dragged to the right edge of the dialog, the aircraft starts returning home and the dialog is dismissed. If the cancel button is pressed, no action is done and the dialog is dismissed.

Usage

If creating the return home widget through code it can be added using the convenience method:

- (void)installInViewController:(nullable UIViewController *)viewController

this adds the widget as a subview of the viewController passed as an argument. Then you need to add constraints to the widget using its widgetSizeHint property to determine width, height and aspect ratio constraints.

To create the widget from a storyboard, use the object library to drag a container view controller into the desired view controller like so:

Make sure to change the child view controller class name to DUXBetaReturnHomeWidget. From here you can create the constraints on the container view using widgetSizeHint property.

The ideal dimension ratio for this widget is 1:1.

Customizations

The UI elements can be customized to match the style of the user's application. The customizations can be done using the public API designed in this widget.

The code for this customization is the following:

Swift Example

widget.returnHomeActionImage = UIImage.duxbeta_image(withAssetNamed: "ic_flight_returnhome_white")

Objective-C Example

widget.returnHomeActionImage = [UIImage duxbeta_imageWithAssetNamed:@"ic_flight_returnhome_white"];

The code for this customization is the following:

Swift Example

widget.returnHomeAlertImage = UIImage.duxbeta_image(withAssetNamed: "ic_flight_returnhome_black")
widget.alertAppearance.titleColor = UIColor.duxbeta_black()
widget.alertAppearance.titleFont = UIFont.boldSystemFont(ofSize: 15.0)
widget.alertAppearance.messageColor = UIColor.duxbeta_black()
widget.alertAppearance.checkboxTextColor = UIColor.duxbeta_black()
widget.alertAppearance.checkboxTintColor = UIColor.duxbeta_black()
widget.alertAppearance.slideMessageTextColor = UIColor.duxbeta_black()
widget.alertAppearance.separatorColor = UIColor.duxbeta_black()
widget.alertAppearance.backgroundColor = UIColor.duxbeta_white()
widget.alertAppearance.slideOnTintColor = UIColor.duxbeta_blue()
widget.alertAppearance.slideOffTintColor = UIColor.duxbeta_gray()
widget.alertAppearance.slideIconTintColor = UIColor.duxbeta_pink()
widget.alertAppearance.slideMessageTextColor = UIColor.duxbeta_pink()
widget.alertCancelActionAppearance.actionColor = UIColor.duxbeta_black()
widget.alertAppearance.slideIconImage = UIImage.duxbeta_image(withAssetNamed: "ic_chevron_right_pink")

Objective-C Example

widget.returnHomeAlertImage = [UIImage duxbeta_imageWithAssetNamed:@"ic_flight_returnhome_black"];
widget.alertAppearance.titleColor = [UIColor duxbeta_blackColor];
widget.alertAppearance.titleFont = [UIFont boldSystemFontOfSize:15.0];
widget.alertAppearance.messageColor = [UIColor duxbeta_blackColor];
widget.alertAppearance.checkboxTextColor = [UIColor duxbeta_blackColor];
widget.alertAppearance.checkboxTintColor = [UIColor duxbeta_blackColor];
widget.alertAppearance.slideMessageTextColor = [UIColor duxbeta_blackColor];
widget.alertAppearance.separatorColor = [UIColor duxbeta_blackColor];
widget.alertAppearance.backgroundColor = [UIColor duxbeta_whiteColor];
widget.alertAppearance.slideOnTintColor = [UIColor duxbeta_blueColor];
widget.alertAppearance.slideOffTintColor = [UIColor duxbeta_grayColor];
widget.alertAppearance.slideIconTintColor = [UIColor duxbeta_pinkColor];
widget.alertAppearance.slideMessageTextColor = [UIColor duxbeta_pinkColor];
widget.alertAppearance.slideIconImage = [UIImage duxbeta_imageWithAssetNamed:@"ic_chevron_right_pink"];
widget.alertCancelActionAppearance.actionColor = [UIColor duxbeta_blackColor];

APIs

List of the customization APIs
  • public var widgetModel: ReturnHomeWidgetModel - The widget model that contains the underlying logic and communication.
  • public var returnHomeActionImage: UIImage - The image for the return to home action.
  • public var cancelReturnHomeActionImage: UIImage - The image for the cancel return to home action.
  • public var cancelReturnHomeActionDisabledImage: UIImage - The image for the disabled cancel return to home action.
  • public var backgroundColor: UIColor - The background color of the control, by default clear.
  • public var returnHomeActionTintColor: UIColor - The image tint color for the return to home action, by default white.
  • public var cancelReturnHomeActionTintColor: UIColor - The image tint color for the cancel return to home action, by default clear.
  • public var cancelReturnHomeActionDisabledTintColor: UIColor - The image tint color for the disabled cancel return to home action, by default gray.
  • public var returnHomeAlertImage: UIImage - The image for the return to home alert.
  • public var returnHomeAlertTintColor: UIColor - The image tint color for the return to home alert, by default yellow.
  • public var alertAppearance: DUXBetaAlertViewAppearance - The customization instance that controls the appearance of the alert.
  • public var alertCancelActionAppearance: DUXBetaAlertActionAppearance - The customization instance that controls the appearance of the dialog cancel action.
  • enabledAlpha : CGFloat - The alpha of the image when the widget is enabled, by default 1.
  • disabledAlpha : CGFloat - The alpha of the image when the widget is disabled, by default 0.38.
  • public override var widgetSizeHint: DUXBetaWidgetSizeHint - The standard widgetSizeHint indicating the minimum size for this widget and preferred aspect ratio.

See Alerts wiki page for all the customizable properties exposed by an alert.

Hooks

The widget provides hooks for users to add functionality based on state changes in the widget. The DUXBetaReturnHomeWidget provides the following hooks

  1. ReturnHomeModelState - Provides hooks for events received by the widget from the widget model.
  • @objc public static func productConnected(_ isConnected: Bool) -> ReturnHomeModelState - Sends a boolean value as an NSNumber when product connection state changes.
  • @objc public static func returnHomeStateUpdated(_ state: ReturnHomeState) -> ReturnHomeModelState - Sends an NSNumber value when widget state is updated.
  • @objc public static func returnHomeStartSucceeded() -> ReturnHomeModelState - Sends true as an NSNumber value when return home started successfully.
  • @objc public static func returnHomeStartedFailed(_ error: Error) -> ReturnHomeModelState - Sends an NSError as an object when return home has not started due to an error.
  • @objc public static func returnHomeCancelSucceeded() -> ReturnHomeModelState - Sends true as an NSNumber value when return home cancellation started successfully.
  • @objc public static func returnHomeCanceledFailed(_ error: Error) -> ReturnHomeModelState - Sends an NSError as an object when return home cancellation has not started due to an error.
  1. ReturnHomeUIState - Provides hooks for events related to user interaction with the widget.
  • @objc public static func widgetTapped() -> ReturnHomeUIState - Sends true as an NSNumber when the widget is tapped.
  • @objc public static func dialogDisplayed(_ dialogType: DUXBetaReturnHomeWidgetDialogType) -> ReturnHomeUIState - Sends dialogType as an NSNumber when dialog is shown.
  • @objc public static func dialogDismissed(_ dialogType: DUXBetaReturnHomeWidgetDialogType) -> ReturnHomeUIState - Sends dialogType as an NSNumber when dialog is canceled.
  • @objc public static func dialogActionConfirmed(_ dialogType: DUXBetaReturnHomeWidgetDialogType) -> ReturnHomeUIState - Sends dialogType as an NSNumber when dialog OK/Confirmed button is pressed.
  • @objc public static func dialogActionCanceled(_ dialogType: DUXBetaReturnHomeWidgetDialogType) -> ReturnHomeUIState - Sends dialogType as an NSNumber when dialog Cancel button is pressed.
Clone this wiki locally