com.facebook.react.views.scroll.ScrollEventType Java Examples

The following examples show how to use com.facebook.react.views.scroll.ScrollEventType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactAztecManager.java    From react-native-aztec with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onScrollChanged(int horiz, int vert, int oldHoriz, int oldVert) {
    if (mPreviousHoriz != horiz || mPreviousVert != vert) {
        ScrollEvent event = ScrollEvent.obtain(
                mReactAztecText.getId(),
                ScrollEventType.SCROLL,
                horiz,
                vert,
                0f, // can't get x velocity
                0f, // can't get y velocity
                0, // can't get content width
                0, // can't get content height
                mReactAztecText.getWidth(),
                mReactAztecText.getHeight());

        mEventDispatcher.dispatchEvent(event);

        mPreviousHoriz = horiz;
        mPreviousVert = vert;
    }
}
 
Example #2
Source File: Web3WebviewManager.java    From react-native-web3-webview with MIT License 6 votes vote down vote up
protected void onScrollChanged(int x, int y, int oldX, int oldY) {
    super.onScrollChanged(x, y, oldX, oldY);
    if (mOnScrollDispatchHelper.onScrollChanged(x, y)) {
        ScrollEvent event = ScrollEvent.obtain(
        this.getId(),
        ScrollEventType.SCROLL,
        x,
        y,
        mOnScrollDispatchHelper.getXFlingVelocity(),
        mOnScrollDispatchHelper.getYFlingVelocity(),
        this.computeHorizontalScrollRange(),
        this.computeVerticalScrollRange(),
        this.getWidth(),
        this.getHeight());
        dispatchEvent(this, event);
    }
}
 
Example #3
Source File: ReactTextInputManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
public void onScrollChanged(int horiz, int vert, int oldHoriz, int oldVert) {
  if (mPreviousHoriz != horiz || mPreviousVert != vert) {
    ScrollEvent event = ScrollEvent.obtain(
      mReactEditText.getId(),
      ScrollEventType.SCROLL,
      horiz,
      vert,
      0f, // can't get x velocity
      0f, // can't get y velocity
      0, // can't get content width
      0, // can't get content height
      mReactEditText.getWidth(),
      mReactEditText.getHeight());

    mEventDispatcher.dispatchEvent(event);

    mPreviousHoriz = horiz;
    mPreviousVert = vert;
  }
}
 
Example #4
Source File: DirectedScrollView.java    From react-native-directed-scrollview with MIT License 6 votes vote down vote up
private void onActionMove(MotionEvent motionEvent) {
  NativeGestureUtil.notifyNativeGestureStarted(this, motionEvent);

  if (isScaleInProgress) return;

  isScrollInProgress = true;

  float deltaX = motionEvent.getX() - startTouchX;
  float deltaY = motionEvent.getY() - startTouchY;

  scrollX = startScrollX + deltaX;
  scrollY = startScrollY + deltaY;

  if (bounces) {
    clampAndTranslateChildren(false, getMaxScrollY() <= 0 && !alwaysBounceVertical, getMaxScrollX() <= 0 && !alwaysBounceHorizontal);
  } else {
    clampAndTranslateChildren(false);
  }

  this.emitScrollEvent(ScrollEventType.SCROLL, deltaX * -1, deltaY * -1);
}
 
Example #5
Source File: DirectedScrollView.java    From react-native-directed-scrollview with MIT License 6 votes vote down vote up
private void onActionUp() {
  if (isScrollInProgress) {
    emitScrollEvent(ScrollEventType.END_DRAG, 0, 0);
    isScrollInProgress = false;
  }

  if (bounces) {
    clampAndTranslateChildren(true);
  }

  if (bouncesZoom) {
    clampAndScaleChildren(true);
  }

  isScaleInProgress = false;
}
 
Example #6
Source File: DirectedScrollView.java    From react-native-directed-scrollview with MIT License 6 votes vote down vote up
private void emitScrollEvent(
  ScrollEventType scrollEventType,
  float xVelocity,
  float yVelocity) {
  reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
    ScrollEvent.obtain(
      getId(),
      scrollEventType,
      Math.round(scrollX * -1),
      Math.round(scrollY * -1),
      xVelocity,
      yVelocity,
      Math.round(getContentContainerWidth()),
      Math.round(getContentContainerHeight()),
      getWidth(),
      getHeight()));
}
 
Example #7
Source File: ReactTextInputManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Nullable
@Override
public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
  return MapBuilder.<String, Object>builder()
      .put(ScrollEventType.getJSEventName(ScrollEventType.SCROLL), MapBuilder.of("registrationName", "onScroll"))
      .build();
}
 
Example #8
Source File: DirectedScrollViewManager.java    From react-native-directed-scrollview with MIT License 5 votes vote down vote up
public static Map createExportedCustomDirectEventTypeConstants() {
  return MapBuilder.builder()
      .put(ScrollEventType.getJSEventName(ScrollEventType.SCROLL), MapBuilder.of("registrationName", "onScroll"))
      .put(ScrollEventType.getJSEventName(ScrollEventType.BEGIN_DRAG), MapBuilder.of("registrationName", "onScrollBeginDrag"))
      .put(ScrollEventType.getJSEventName(ScrollEventType.END_DRAG), MapBuilder.of("registrationName", "onScrollEndDrag"))
      .put(ScrollEventType.getJSEventName(ScrollEventType.MOMENTUM_BEGIN), MapBuilder.of("registrationName", "onMomentumScrollBegin"))
      .put(ScrollEventType.getJSEventName(ScrollEventType.MOMENTUM_END), MapBuilder.of("registrationName", "onMomentumScrollEnd"))
      .build();
}
 
Example #9
Source File: DirectedScrollView.java    From react-native-directed-scrollview with MIT License 4 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(final MotionEvent motionEvent) {
  if (!scrollEnabled) {
    return false;
  }

  emitScrollEvent(ScrollEventType.BEGIN_DRAG, 0, 0);

  int action = motionEvent.getAction();
  if (action == MotionEvent.ACTION_UP | action == MotionEvent.ACTION_CANCEL) {
    isScrollInProgress = false;
    isScaleInProgress = false;
    return false;
  }

  if (action == MotionEvent.ACTION_MOVE & isDragging) {
    return true;
  }

  if (super.onInterceptTouchEvent(motionEvent)) {
    return true;
  }

  switch (action) {
    case MotionEvent.ACTION_DOWN:
      lastPositionX = motionEvent.getX();
      lastPositionY = motionEvent.getY();
      onActionDown(motionEvent);
      break;
    case MotionEvent.ACTION_POINTER_DOWN:
      onActionPointerDown();
      break;
    case MotionEvent.ACTION_MOVE:
      float diffX = Math.abs(motionEvent.getX() - lastPositionX);
      float diffY = Math.abs(motionEvent.getY() - lastPositionY);
      if (isScaleInProgress || diffX > touchSlop || diffY > touchSlop) {
        lastPositionX = motionEvent.getX();
        lastPositionY = motionEvent.getY();
        disallowInterceptTouchEventsForParent();
        return true;
      }
      break;
  }


  return false;
}