Skip to content

Flight Mode List Item Widget

Cristina Suciu edited this page Dec 23, 2020 · 2 revisions

Flight Mode List Item Widget is a DUXBetaListItemLabelOnly type of widget which will display the current FlightMode. Following are examples of the widget states:

Disconnected

Sport

Opti

Atti

Usage

To add the flight mode widget to your DUXBetaSmartListModel class, override buildModelLists and include DUXBetaFlightModeListItemWidget.duxbeta_className() or [DUXBetaFlightModeWidget duxbeta_className] in your modelClassnameList:

Swift Example

@objc open class MySmartListModel : DUXBetaSmartListModel {
    @objc open override func buildModelLists() {
        super.buildModelLists()
        self.modelClassnameList.append(DUXBetaFlightModeListItemWidget.duxbeta_className())
    }
}

ObjC Example

@interface DUXBetaTestSmartListModel : DUXBetaSmartListModel
@end

@implementation DUXBetaTestSmartListModel
- (void)buildModelLists {
    [super buildModelLists];
    [self.modelClassnameList append:[DUXBetaFlightModeListItemWidget duxbeta_className]];
}
@end

Customizations

The UI elements can be customized to match the style of the user's application. The widget supports all the customizations that its parent, DUXBetaListItemLabelOnly, supports. An example of a customized flight mode list item widget showing various flight modes could look something like this:

Disconnected

Sport

Opti

Atti

To get this effect we would use the following code:

Swift Example

flightModeListWidget.backgroundColor = .gray
flightModeListWidget.iconImage = UIImage.init(named: "CustomFlightModeIconImage")!
flightModeListWidget.labelTextColorNormal = .green
flightModeListWidget.labelTextColorDisconnected = .red

ObjC Example

flightModeListWidget.backgroundColor = UIColor.grayColor;
flightModeListWidget.iconImage = [UIImage imageNamed:@"CustomFlightModeIconImage"];
flightModeListWidget.labelTextColorNormal = UIColor.greenColor;
flightModeListWidget.labelTextColorDisconnected = UIColor.redColor;

Hooks

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

  1. FlightModeListItemModelState - Provides hooks for events received by the widget from the widget model. It inherits from ListItemLabelButtonModelState and adds the following hooks:
  • + (instancetype)flightModeUpdated:(NSString*)newMode; - Event when the flight mode is updated.
  1. FlightModeListItemUIState - Provides hooks for events received by the widget from the user interface interactions. It inherits from ListItemLabelButtonUIState and adds no other hooks.
Clone this wiki locally