OH_ArkUI_AddSupportedUIStates

Function OH_ArkUI_AddSupportedUIStates 

Source
pub unsafe extern "C" fn OH_ArkUI_AddSupportedUIStates(
    node: ArkUI_NodeHandle,
    uiStates: i32,
    statesChangeHandler: Option<unsafe extern "C" fn(currentStates: i32, userData: *mut c_void)>,
    excludeInner: bool,
    userData: *mut c_void,
) -> ArkUiResult
Available on crate features api-12 and api-20 only.
Expand description

Adds the UI state style supported by the component. To handle states change efficiently, need to specify the states of interest and the corresponding handler. When a state of interest occurs, the handler will be executed.

  • You can adjust the UI style based on the current state within the callback. If this API is called multiple times on the same node, the last set of states and handler will take precedence.
  • Some component types have default system handling for certain states. For example, the Button component has a default style effect for the PRESSED state. When custom state handling is implemented on such components, the default style effect will be applied first, followed by the custom style changes, resulting in a combined effect. To disable the default style effects, set excludeInner to true, if this is allowed by the system implementation.
  • And when this API is called, the provided handler function will be executed immediately.
  • There is no need to explicitly register a listener for the NORMAL state. Once a non-NORMAL state is registered, the system will automatically notify your application when the state changes back to NORMAL.

§Arguments

  • node - Target node.

  • uiStates - Target UI states to be handled on the node. The combined result of all target UI states can be calculated using the | operator. Example: targetUIStates = ArkUI_UIState::PRESSED | ArkUI_UIState::FOCUSED.

  • statesChangeHandler - Handler for UI state changes. It rturns the current UI status. The value is the result of combining all current state enum values using the | operator. You can determine the state using the & operator. Example: if (currentStates & ArkUI_UIState::PRESSED == ArkUI_UIState::PRESSED). However, for checking the normal state, use the equality operator directly. Example: if (currentStates == ArkUI_UIState::NORMAL).

  • excludeInner - Whether to disable the default state styles.

  • userData - Custom data used in the statesChangeHandler callback.

§Returns

  • Returns the result code. Returns [ARKUI_ERROR_CODE_NO_ERROR] if the operation is successful. Returns [ARKUI_ERROR_CODE_PARAM_INVALID] if a parameter error occurs.

Available since API-level: 20