dji-sdk / Mobile-UXSDK-iOS

DJI Mobile UXSDK is a suite of product agnostic UI objects that fast tracks the development of iOS applications using the DJI Mobile SDK.
Other
73 stars 43 forks source link

DUXLeadingBarViewController external accessory widgets not accessible #81

Closed adolfo closed 2 years ago

adolfo commented 4 years ago

It is not possible to access the external accessories (DUXSpeakerWidget, DUXSpotlightWidget, etc.) from the DUXLeadingBarViewController. When attempting to fetch these widgets using the following method, the result is always nil:

let leadingBar = DUXLeadingBarViewController()
let speakerWidget = leadingBar.widget(with: DUXSpeakerWidget.self)
// speakerWidget == nil

The expectation is that the widget(with: AnyClass) would return the nested widget.

The only workaround I've found is to iterate through the child views of the non-public DUXExternalAccessoryWidgetBase widget:

if let externalAccessoryClass = NSClassFromString("DUXExternalAccessoryWidgetBase") {
    if let externalAccessory = leadingBar.widget(with: externalAccessoryClass) {
        for subview in externalAccessory.subviews {
            if let speakerWidget = subview as? DUXSpeakerWidget {
                speakerWidget.action = { /* do something useful */ }
            }
            if let spotlightWidget = subview as? DUXSpotlightWidget {
                spotlightWidget.action = { /* do something useful */ }
            }
        }
    }
}

Perhaps this is a bug or there is a better way to acquire a reference to the accessory widgets.

dji-dev commented 4 years ago

Dear Customer,

Thank you for contacting DJI. To help us collect questions in detail, please fill in the form below and we will handle this ticket once we have received it. https://formcrafts.com/a/dji-developer-feedback-en