List Item Switch Widget - dji-sdk/Mobile-UXSDK-Beta-iOS GitHub Wiki

The widget is an extension of the List Item Title Widget. The primary purpose of this widget is to provide an on/off switch for settings.

An example of the widget is the Novice Mode Widget.

Widget Specific APIs

The widget supplies two APIs for handling the state changes of the switch. The first is used to install an action handler when the switch changes state and the second is used to notify the UI if the switch had changed via code so the switch UI can be updated appropriately.

The method switchEnabledStateChange should be called when the switch control in the property onOffSwitch is directly changed via code.

Swift

func void setSwitchAction( (Bool)->() )
func void switchEnabledStateChange()

Objective-C

typedef void (^SwitchChangedActionBlock)(BOOL newSwitchValue);

- (void)setSwitchAction:(SwitchChangedActionBlock)newBlock;
- (void)switchEnabledStateChanged;

APIs

Poperties specific to the switch widget for customization. Other customizations are available in List Item Title Widget.

List of the customization APIs
  • switchTintColor - The UIColor property which defines the background color of the switch when in the ON state.
  • switchOffTintColor - The UIColor property which defines the background color of the switch when in the OFF state. iOS 13+ only.
  • switchTrackColor - The UIColor property which defines the background color of the track/right around the switch. iOS 13+ only.

Hooks

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

The List Item Switch Widget provides the following hooks:

ListItemSwitchUIState - Provides hooks in events received by the widget from the user interface interactions. It inherits ListItemTitleUIState and it adds:

  • (instancetype)switchedChanged:(BOOL)isOn; Event when the switch value changes. Sends a boolean as an NSNumber, YES for on, NO for off.
⚠️ **GitHub.com Fallback** ⚠️