Search in sources :

Example 1 with ScrollHandler

use of com.android.tools.idea.uibuilder.api.ScrollHandler in project android by JetBrains.

the class ScrollInteraction method createScrollInteraction.

/**
   * Creates a new {@link ScrollInteraction} if any of the components in the component hierarchy can handle scrolling.
   * @return the {@link ScrollInteraction} or null if none of the components handle the scrolling
   */
@Nullable
public static ScrollInteraction createScrollInteraction(@NonNull ScreenView screenView, @NonNull NlComponent component) {
    NlComponent currentComponent = component;
    ScrollHandler scrollHandler = null;
    ViewEditor editor = new ViewEditorImpl(screenView);
    // Find the component that is the lowest in the hierarchy and can take the scrolling events
    while (currentComponent != null) {
        ViewGroupHandler viewGroupHandler = currentComponent.getViewGroupHandler();
        scrollHandler = viewGroupHandler != null ? viewGroupHandler.createScrollHandler(editor, currentComponent) : null;
        if (scrollHandler != null) {
            break;
        }
        currentComponent = currentComponent.getParent();
    }
    if (scrollHandler == null) {
        return null;
    }
    return new ScrollInteraction(screenView, scrollHandler);
}
Also used : ScrollHandler(com.android.tools.idea.uibuilder.api.ScrollHandler) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ViewEditor(com.android.tools.idea.uibuilder.api.ViewEditor) ViewGroupHandler(com.android.tools.idea.uibuilder.api.ViewGroupHandler) ViewEditorImpl(com.android.tools.idea.uibuilder.handlers.ViewEditorImpl) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ScrollHandler (com.android.tools.idea.uibuilder.api.ScrollHandler)1 ViewEditor (com.android.tools.idea.uibuilder.api.ViewEditor)1 ViewGroupHandler (com.android.tools.idea.uibuilder.api.ViewGroupHandler)1 ViewEditorImpl (com.android.tools.idea.uibuilder.handlers.ViewEditorImpl)1 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)1 Nullable (org.jetbrains.annotations.Nullable)1