com.facebook.react.uimanager.PixelUtil Java Examples

The following examples show how to use com.facebook.react.uimanager.PixelUtil. 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: RNPublisherBannerViewManager.java    From react-native-admob with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void sendOnSizeChangeEvent() {
    int width;
    int height;
    ReactContext reactContext = (ReactContext) getContext();
    WritableMap event = Arguments.createMap();
    AdSize adSize = this.adView.getAdSize();
    if (adSize == AdSize.SMART_BANNER) {
        width = (int) PixelUtil.toDIPFromPixel(adSize.getWidthInPixels(reactContext));
        height = (int) PixelUtil.toDIPFromPixel(adSize.getHeightInPixels(reactContext));
    } else {
        width = adSize.getWidth();
        height = adSize.getHeight();
    }
    event.putDouble("width", width);
    event.putDouble("height", height);
    sendEvent(RNPublisherBannerViewManager.EVENT_SIZE_CHANGE, event);
}
 
Example #2
Source File: ReactViewManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactPropGroup(
  names = {
    ViewProps.BORDER_WIDTH,
    ViewProps.BORDER_LEFT_WIDTH,
    ViewProps.BORDER_RIGHT_WIDTH,
    ViewProps.BORDER_TOP_WIDTH,
    ViewProps.BORDER_BOTTOM_WIDTH,
    ViewProps.BORDER_START_WIDTH,
    ViewProps.BORDER_END_WIDTH,
  },
  defaultFloat = YogaConstants.UNDEFINED
)
public void setBorderWidth(ReactViewGroup view, int index, float width) {
  if (!YogaConstants.isUndefined(width) && width < 0) {
    width = YogaConstants.UNDEFINED;
  }

  if (!YogaConstants.isUndefined(width)) {
    width = PixelUtil.toPixelFromDIP(width);
  }

  view.setBorderWidth(SPACING_TYPES[index], width);
}
 
Example #3
Source File: ReactDrawerLayoutManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
public void setElevation(ReactDrawerLayout view, float elevation) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    // Facebook is using an older version of the support lib internally that doesn't support
    // setDrawerElevation so we invoke it using reflection.
    // TODO: Call the method directly when this is no longer needed.
    try {
      Method method = ReactDrawerLayout.class.getMethod("setDrawerElevation", float.class);
      method.invoke(view, PixelUtil.toPixelFromDIP(elevation));
    } catch (Exception ex) {
      FLog.w(
          ReactConstants.TAG,
          "setDrawerElevation is not available in this version of the support lib.",
          ex);
    }
  }
}
 
Example #4
Source File: RNAdMobBannerViewManager.java    From react-native-admob with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void sendOnSizeChangeEvent() {
    int width;
    int height;
    ReactContext reactContext = (ReactContext) getContext();
    WritableMap event = Arguments.createMap();
    AdSize adSize = this.adView.getAdSize();
    if (this.adSize == AdSize.SMART_BANNER) {
        width = (int) PixelUtil.toDIPFromPixel(adSize.getWidthInPixels(reactContext));
        height = (int) PixelUtil.toDIPFromPixel(adSize.getHeightInPixels(reactContext));
    } else {
        width = adSize.getWidth();
        height = adSize.getHeight();
    }
    event.putDouble("width", width);
    event.putDouble("height", height);
    sendEvent(RNAdMobBannerViewManager.EVENT_SIZE_CHANGE, event);
}
 
Example #5
Source File: ReactTextInputManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
public void onLayout() {
  int contentWidth = mEditText.getWidth();
  int contentHeight = mEditText.getHeight();

  // Use instead size of text content within EditText when available
  if (mEditText.getLayout() != null) {
    contentWidth = mEditText.getCompoundPaddingLeft() + mEditText.getLayout().getWidth() +
      mEditText.getCompoundPaddingRight();
    contentHeight = mEditText.getCompoundPaddingTop() + mEditText.getLayout().getHeight() +
      mEditText.getCompoundPaddingBottom();
  }

  if (contentWidth != mPreviousContentWidth || contentHeight != mPreviousContentHeight) {
    mPreviousContentHeight = contentHeight;
    mPreviousContentWidth = contentWidth;

    mEventDispatcher.dispatchEvent(
      new ReactContentSizeChangedEvent(
        mEditText.getId(),
        PixelUtil.toDIPFromPixel(contentWidth),
        PixelUtil.toDIPFromPixel(contentHeight)));
  }
}
 
Example #6
Source File: ReactTextInputManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactPropGroup(names = {
    ViewProps.BORDER_RADIUS,
    ViewProps.BORDER_TOP_LEFT_RADIUS,
    ViewProps.BORDER_TOP_RIGHT_RADIUS,
    ViewProps.BORDER_BOTTOM_RIGHT_RADIUS,
    ViewProps.BORDER_BOTTOM_LEFT_RADIUS
}, defaultFloat = YogaConstants.UNDEFINED)
public void setBorderRadius(ReactEditText view, int index, float borderRadius) {
  if (!YogaConstants.isUndefined(borderRadius)) {
    borderRadius = PixelUtil.toPixelFromDIP(borderRadius);
  }

  if (index == 0) {
    view.setBorderRadius(borderRadius);
  } else {
    view.setBorderRadius(borderRadius, index - 1);
  }
}
 
Example #7
Source File: ReactAztecManager.java    From react-native-aztec with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onLayout() {
    int contentWidth = mReactAztecText.getWidth();
    int contentHeight = mReactAztecText.getHeight();

    // Use instead size of text content within EditText when available
    if (mReactAztecText.getLayout() != null) {
        contentWidth = mReactAztecText.getCompoundPaddingLeft() + mReactAztecText.getLayout().getWidth() +
                mReactAztecText.getCompoundPaddingRight();
        contentHeight = mReactAztecText.getCompoundPaddingTop() + mReactAztecText.getLayout().getHeight() +
                mReactAztecText.getCompoundPaddingBottom();
    }

    if (contentWidth != mPreviousContentWidth || contentHeight != mPreviousContentHeight) {
        mPreviousContentHeight = contentHeight;
        mPreviousContentWidth = contentWidth;

        // FIXME: Note the 2 hacks here
        mEventDispatcher.dispatchEvent(
                new ReactContentSizeChangedEvent(
                        mReactAztecText.getId(),
                        PixelUtil.toDIPFromPixel(contentWidth),
                        PixelUtil.toDIPFromPixel(contentHeight)));
    }
}
 
Example #8
Source File: RNStaticSafeAreaInsetsModule.java    From react-native-static-safe-area-insets with MIT License 6 votes vote down vote up
private Map<String, Object> _getSafeAreaInsets() {
  final Map<String, Object> constants = new HashMap<>();

  if (getCurrentActivity() != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    final Activity activity = getCurrentActivity();
    final View view = activity.getWindow().getDecorView();
    final WindowInsets insets = view.getRootWindowInsets();

    constants.put("safeAreaInsetsTop", PixelUtil.toDIPFromPixel(insets.getSystemWindowInsetTop()));
    constants.put("safeAreaInsetsBottom", PixelUtil.toDIPFromPixel(insets.getSystemWindowInsetBottom()));
    constants.put("safeAreaInsetsLeft", PixelUtil.toDIPFromPixel(insets.getSystemWindowInsetLeft()));
    constants.put("safeAreaInsetsRight", PixelUtil.toDIPFromPixel(insets.getSystemWindowInsetRight()));
  } else {
    constants.put("safeAreaInsetsTop", 0);
    constants.put("safeAreaInsetsBottom", 0);
    constants.put("safeAreaInsetsLeft", 0);
    constants.put("safeAreaInsetsRight", 0);
  }

  return constants;
}
 
Example #9
Source File: ReactViewManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
public void receiveCommand(ReactViewGroup root, int commandId, @Nullable ReadableArray args) {
  switch (commandId) {
    case CMD_HOTSPOT_UPDATE: {
      if (args == null || args.size() != 2) {
        throw new JSApplicationIllegalArgumentException(
            "Illegal number of arguments for 'updateHotspot' command");
      }
      if (Build.VERSION.SDK_INT >= 21) {
        float x = PixelUtil.toPixelFromDIP(args.getDouble(0));
        float y = PixelUtil.toPixelFromDIP(args.getDouble(1));
        root.drawableHotspotChanged(x, y);
      }
      break;
    }
    case CMD_SET_PRESSED: {
      if (args == null || args.size() != 1) {
        throw new JSApplicationIllegalArgumentException(
            "Illegal number of arguments for 'setPressed' command");
      }
      root.setPressed(args.getBoolean(0));
      break;
    }
  }
}
 
Example #10
Source File: FrescoBasedReactTextInlineImageSpan.java    From react-native-GPay with MIT License 6 votes vote down vote up
public FrescoBasedReactTextInlineImageSpan(
    Resources resources,
    int height,
    int width,
    int tintColor,
    @Nullable Uri uri,
    ReadableMap headers,
    AbstractDraweeControllerBuilder draweeControllerBuilder,
    @Nullable Object callerContext) {
  mDraweeHolder = new DraweeHolder(
      GenericDraweeHierarchyBuilder.newInstance(resources)
          .build()
  );
  mDraweeControllerBuilder = draweeControllerBuilder;
  mCallerContext = callerContext;
  mTintColor = tintColor;
  mUri = (uri != null) ? uri : Uri.EMPTY;
  mHeaders = headers;
  mWidth = (int)(PixelUtil.toPixelFromDIP(width));
  mHeight = (int)(PixelUtil.toPixelFromDIP(height));

}
 
Example #11
Source File: ReactTextAnchorViewManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactPropGroup(
  names = {
    ViewProps.BORDER_RADIUS,
    ViewProps.BORDER_TOP_LEFT_RADIUS,
    ViewProps.BORDER_TOP_RIGHT_RADIUS,
    ViewProps.BORDER_BOTTOM_RIGHT_RADIUS,
    ViewProps.BORDER_BOTTOM_LEFT_RADIUS
  },
  defaultFloat = YogaConstants.UNDEFINED
)
public void setBorderRadius(ReactTextView view, int index, float borderRadius) {
  if (!YogaConstants.isUndefined(borderRadius)) {
    borderRadius = PixelUtil.toPixelFromDIP(borderRadius);
  }

  if (index == 0) {
    view.setBorderRadius(borderRadius);
  } else {
    view.setBorderRadius(borderRadius, index - 1);
  }
}
 
Example #12
Source File: ReactTextAnchorViewManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactPropGroup(
  names = {
    ViewProps.BORDER_WIDTH,
    ViewProps.BORDER_LEFT_WIDTH,
    ViewProps.BORDER_RIGHT_WIDTH,
    ViewProps.BORDER_TOP_WIDTH,
    ViewProps.BORDER_BOTTOM_WIDTH,
  },
  defaultFloat = YogaConstants.UNDEFINED
)
public void setBorderWidth(ReactTextView view, int index, float width) {
  if (!YogaConstants.isUndefined(width)) {
    width = PixelUtil.toPixelFromDIP(width);
  }
  view.setBorderWidth(SPACING_TYPES[index], width);
}
 
Example #13
Source File: ReactBaseTextShadowNode.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactProp(name = PROP_SHADOW_OFFSET)
public void setTextShadowOffset(ReadableMap offsetMap) {
  mTextShadowOffsetDx = 0;
  mTextShadowOffsetDy = 0;

  if (offsetMap != null) {
    if (offsetMap.hasKey(PROP_SHADOW_OFFSET_WIDTH)
        && !offsetMap.isNull(PROP_SHADOW_OFFSET_WIDTH)) {
      mTextShadowOffsetDx =
          PixelUtil.toPixelFromDIP(offsetMap.getDouble(PROP_SHADOW_OFFSET_WIDTH));
    }
    if (offsetMap.hasKey(PROP_SHADOW_OFFSET_HEIGHT)
        && !offsetMap.isNull(PROP_SHADOW_OFFSET_HEIGHT)) {
      mTextShadowOffsetDy =
          PixelUtil.toPixelFromDIP(offsetMap.getDouble(PROP_SHADOW_OFFSET_HEIGHT));
    }
  }

  markUpdated();
}
 
Example #14
Source File: ReactScrollViewManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactPropGroup(names = {
    ViewProps.BORDER_RADIUS,
    ViewProps.BORDER_TOP_LEFT_RADIUS,
    ViewProps.BORDER_TOP_RIGHT_RADIUS,
    ViewProps.BORDER_BOTTOM_RIGHT_RADIUS,
    ViewProps.BORDER_BOTTOM_LEFT_RADIUS
}, defaultFloat = YogaConstants.UNDEFINED)
public void setBorderRadius(ReactScrollView view, int index, float borderRadius) {
  if (!YogaConstants.isUndefined(borderRadius)) {
    borderRadius = PixelUtil.toPixelFromDIP(borderRadius);
  }

  if (index == 0) {
    view.setBorderRadius(borderRadius);
  } else {
    view.setBorderRadius(borderRadius, index - 1);
  }
}
 
Example #15
Source File: ReactRootView.java    From react-native-GPay with MIT License 6 votes vote down vote up
private void checkForKeyboardEvents() {
  getRootView().getWindowVisibleDisplayFrame(mVisibleViewArea);
  final int heightDiff =
    DisplayMetricsHolder.getWindowDisplayMetrics().heightPixels - mVisibleViewArea.bottom;
  if (mKeyboardHeight != heightDiff && heightDiff > mMinKeyboardHeightDetected) {
    // keyboard is now showing, or the keyboard height has changed
    mKeyboardHeight = heightDiff;
    WritableMap params = Arguments.createMap();
    WritableMap coordinates = Arguments.createMap();
    coordinates.putDouble("screenY", PixelUtil.toDIPFromPixel(mVisibleViewArea.bottom));
    coordinates.putDouble("screenX", PixelUtil.toDIPFromPixel(mVisibleViewArea.left));
    coordinates.putDouble("width", PixelUtil.toDIPFromPixel(mVisibleViewArea.width()));
    coordinates.putDouble("height", PixelUtil.toDIPFromPixel(mKeyboardHeight));
    params.putMap("endCoordinates", coordinates);
    sendEvent("keyboardDidShow", params);
  } else if (mKeyboardHeight != 0 && heightDiff <= mMinKeyboardHeightDetected) {
    // keyboard is now hidden
    mKeyboardHeight = 0;
    sendEvent("keyboardDidHide", null);
  }
}
 
Example #16
Source File: ReactDrawerLayoutManager_1d0b39_t.java    From coming with MIT License 6 votes vote down vote up
@Override
public void setElevation(ReactDrawerLayout view, float elevation) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    // Facebook is using an older version of the support lib internally that doesn't support
    // setDrawerElevation so we invoke it using reflection.
    // TODO: Call the method directly when this is no longer needed.
    try {
      Method method = ReactDrawerLayout.class.getMethod("setDrawerElevation", float.class);
      method.invoke(view, PixelUtil.toPixelFromDIP(elevation));
    } catch (Exception ex) {
      FLog.w(
          ReactConstants.TAG,
          "setDrawerElevation is not available in this version of the support lib.",
          ex);
    }
  }
}
 
Example #17
Source File: ReactDrawerLayoutManager_1d0b39_s.java    From coming with MIT License 6 votes vote down vote up
@Override
public void setElevation(ReactDrawerLayout view, float elevation) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    // Facebook is using an older version of the support lib internally that doesn't support
    // setDrawerElevation so we invoke it using reflection.
    // TODO: Call the method directly when this is no longer needed.
    try {
      Method method = ReactDrawerLayout.class.getMethod("setDrawerElevation", float.class);
      method.invoke(view, PixelUtil.toPixelFromDIP(elevation));
    } catch (Exception ex) {
      FLog.w(
          ReactConstants.TAG,
          "setDrawerElevation is not available in this version of the support lib.",
          ex);
    }
  }
}
 
Example #18
Source File: BottomSheetBehaviorView.java    From react-native-bottom-sheet-behavior with MIT License 6 votes vote down vote up
public BottomSheetBehaviorView(Context context) {
    super(context);

    int width  = ViewGroup.LayoutParams.WRAP_CONTENT;
    int height = ViewGroup.LayoutParams.WRAP_CONTENT;

    CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams(width, height);
    params.setBehavior(new RNBottomSheetBehavior(context));

    this.setLayoutParams(params);

    behavior = RNBottomSheetBehavior.from(this);
    behavior.setPeekHeight((int) PixelUtil.toPixelFromDIP(DEFAULT_PEEK_HEIGHT));
    behavior.setAnchorPoint((int) PixelUtil.toPixelFromDIP(DEFAULT_ANCHOR_POINT));
    behavior.setAnchorEnabled(false);
}
 
Example #19
Source File: ReactHorizontalScrollViewTestCase.java    From react-native-GPay with MIT License 6 votes vote down vote up
public void testScrollEvents() {
  HorizontalScrollView scrollView = getViewAtPath(0);

  dragLeft();

  waitForBridgeAndUIIdle();
  mScrollListenerModule.waitForScrollIdle();
  waitForBridgeAndUIIdle();

  ArrayList<Double> xOffsets = mScrollListenerModule.getXOffsets();
  assertFalse("Expected to receive at least one scroll event", xOffsets.isEmpty());
  assertTrue("Expected offset to be greater than 0", xOffsets.get(xOffsets.size() - 1) > 0);
  assertTrue(
      "Expected no item click event fired",
      mScrollListenerModule.getItemsPressed().isEmpty());
  assertEquals(
      "Expected last offset to be offset of scroll view",
      PixelUtil.toDIPFromPixel(scrollView.getScrollX()),
      xOffsets.get(xOffsets.size() - 1).doubleValue(),
      1e-5);
}
 
Example #20
Source File: ReactScrollViewTestCase.java    From react-native-GPay with MIT License 6 votes vote down vote up
public void testScrollEvents() {
  ScrollView scrollView = getViewAtPath(0);

  dragUp();

  waitForBridgeAndUIIdle();
  mScrollListenerModule.waitForScrollIdle();
  waitForBridgeAndUIIdle();

  ArrayList<Double> yOffsets = mScrollListenerModule.getYOffsets();
  assertFalse("Expected to receive at least one scroll event", yOffsets.isEmpty());
  assertTrue("Expected offset to be greater than 0", yOffsets.get(yOffsets.size() - 1) > 0);
  assertTrue(
      "Expected no item click event fired",
      mScrollListenerModule.getItemsPressed().isEmpty());
  assertEquals(
      "Expected last offset to be offset of scroll view",
      PixelUtil.toDIPFromPixel(scrollView.getScrollY()),
      yOffsets.get(yOffsets.size() - 1).doubleValue(),
      1e-5);
  assertTrue("Begin and End Drag should be called", mScrollListenerModule.dragEventsMatch());
}
 
Example #21
Source File: TextInputTestCase.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * Test that the actual height of the text input is not dependant on the font size of the text
 * within.
 */
public void testTextInputMeasurements() {
  View textInputViewHeightSet = getViewByTestId("textInput1");
  EditText textInputViewNoHeight = getViewByTestId("textInput2");

  int expectedHeight = Math.round(PixelUtil.toPixelFromDIP(30));
  assertEquals(expectedHeight, textInputViewHeightSet.getHeight());

  EditText editText = new EditText(textInputViewNoHeight.getContext());
  editText.setTextSize(
      TypedValue.COMPLEX_UNIT_PX,
      (float) Math.ceil(PixelUtil.toPixelFromSP(21.f)));
  editText.setPadding(0, 0, 0, 0);
  int measureSpec = View.MeasureSpec.makeMeasureSpec(
      ViewGroup.LayoutParams.WRAP_CONTENT,
      View.MeasureSpec.UNSPECIFIED);
  editText.measure(measureSpec, measureSpec);

  assertEquals(editText.getMeasuredHeight(), textInputViewNoHeight.getHeight());
}
 
Example #22
Source File: ViewRenderingTestCase.java    From react-native-GPay with MIT License 6 votes vote down vote up
public void testTransformations() {
  mCatalystInstance.getJSModule(ViewRenderingTestModule.class)
      .renderTransformApplication(mRootTag);
  waitForBridgeAndUIIdle();

  View view = getViewAtPath(mRootView);

  float expectedTranslateX = PixelUtil.toPixelFromDIP(20);
  float expectedTranslateY = PixelUtil.toPixelFromDIP(25);

  assertEquals(5f, view.getScaleX());
  assertEquals(10f, view.getScaleY());
  assertEquals(15f, view.getRotation());
  assertEquals(expectedTranslateX, view.getTranslationX());
  assertEquals(expectedTranslateY, view.getTranslationY());
}
 
Example #23
Source File: ViewRenderingTestCase.java    From react-native-GPay with MIT License 6 votes vote down vote up
public void testMarginUpdateDoesntForgetPreviousValue() {
  mCatalystInstance.getJSModule(ViewRenderingTestModule.class).renderMarginApplication(mRootTag);
  waitForBridgeAndUIIdle();

  View view = getViewAtPath(mRootView);

  // before: margin: 10, marginLeft: 20
  mCatalystInstance.getJSModule(ViewRenderingTestModule.class).updateMargins();
  waitForBridgeAndUIIdle();
  // after: margin: 15; it should not forget marginLeft was set to 20

  int expectedMargin = Math.round(PixelUtil.toPixelFromDIP(15));
  int expectedMarginLeft = Math.round(PixelUtil.toPixelFromDIP(20));

  assertEquals(expectedMarginLeft, (int) view.getX());
  assertEquals(expectedMargin, (int) view.getY());
}
 
Example #24
Source File: TextImagePostProcessor.java    From react-native-image-filter-kit with MIT License 6 votes vote down vote up
@Override
public void processGenerated(@Nonnull Paint paint, @Nonnull Canvas canvas) {
  paint.setTypeface(mTypeface);
  paint.setAntiAlias(true);
  paint.setColor(mColor);
  paint.setTextAlign(Paint.Align.LEFT);
  paint.setTextSize(PixelUtil.toPixelFromDIP(mFontSize));

  Rect bounds = new Rect();
  paint.getTextBounds(mText, 0, mText.length(), bounds);

  canvas.drawText(
    mText,
    mWidth / 2.0f - bounds.width() / 2.0f - bounds.left,
    mHeight / 2.0f + bounds.height() / 2.0f - bounds.bottom,
    paint
  );
}
 
Example #25
Source File: ReactImageManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactPropGroup(names = {
    ViewProps.BORDER_RADIUS,
    ViewProps.BORDER_TOP_LEFT_RADIUS,
    ViewProps.BORDER_TOP_RIGHT_RADIUS,
    ViewProps.BORDER_BOTTOM_RIGHT_RADIUS,
    ViewProps.BORDER_BOTTOM_LEFT_RADIUS
}, defaultFloat = YogaConstants.UNDEFINED)
public void setBorderRadius(ReactImageView view, int index, float borderRadius) {
  if (!YogaConstants.isUndefined(borderRadius)) {
    borderRadius = PixelUtil.toPixelFromDIP(borderRadius);
  }

  if (index == 0) {
    view.setBorderRadius(borderRadius);
  } else {
    view.setBorderRadius(borderRadius, index - 1);
  }
}
 
Example #26
Source File: ReactHorizontalScrollViewManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactPropGroup(names = {
    ViewProps.BORDER_RADIUS,
    ViewProps.BORDER_TOP_LEFT_RADIUS,
    ViewProps.BORDER_TOP_RIGHT_RADIUS,
    ViewProps.BORDER_BOTTOM_RIGHT_RADIUS,
    ViewProps.BORDER_BOTTOM_LEFT_RADIUS
}, defaultFloat = YogaConstants.UNDEFINED)
public void setBorderRadius(ReactHorizontalScrollView view, int index, float borderRadius) {
  if (!YogaConstants.isUndefined(borderRadius)) {
    borderRadius = PixelUtil.toPixelFromDIP(borderRadius);
  }

  if (index == 0) {
    view.setBorderRadius(borderRadius);
  } else {
    view.setBorderRadius(borderRadius, index - 1);
  }
}
 
Example #27
Source File: ViewRenderingTestCase.java    From react-native-GPay with MIT License 5 votes vote down vote up
public void testBordersApplied() {
  mCatalystInstance.getJSModule(ViewRenderingTestModule.class).renderBorderApplication(mRootTag);
  waitForBridgeAndUIIdle();

  View view = getViewAtPath(mRootView);
  View child = ((ViewGroup) view).getChildAt(0);

  int expectedBorderX = Math.round(PixelUtil.toPixelFromDIP(20));
  int expectedBorderY = Math.round(PixelUtil.toPixelFromDIP(5));

  assertEquals(expectedBorderX, (int) child.getX());
  assertEquals(expectedBorderY, (int) child.getY());
}
 
Example #28
Source File: ViewRenderingTestCase.java    From react-native-GPay with MIT License 5 votes vote down vote up
public void testMarginsApplied() {
  mCatalystInstance.getJSModule(ViewRenderingTestModule.class).renderMarginApplication(mRootTag);
  waitForBridgeAndUIIdle();

  View view = getViewAtPath(mRootView);

  int expectedMargin = Math.round(PixelUtil.toPixelFromDIP(10));
  int expectedMarginLeft = Math.round(PixelUtil.toPixelFromDIP(20));

  assertEquals(expectedMarginLeft, (int) view.getX());
  assertEquals(expectedMargin, (int) view.getY());
}
 
Example #29
Source File: ReactViewManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
@ReactProp(name = "hitSlop")
public void setHitSlop(final ReactViewGroup view, @Nullable ReadableMap hitSlop) {
  if (hitSlop == null) {
    view.setHitSlopRect(null);
  } else {
    view.setHitSlopRect(new Rect(
        hitSlop.hasKey("left") ? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("left")) : 0,
        hitSlop.hasKey("top") ? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("top")) : 0,
        hitSlop.hasKey("right") ? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("right")) : 0,
        hitSlop.hasKey("bottom") ? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("bottom")) : 0
    ));
  }
}
 
Example #30
Source File: CatalystSubviewsClippingTestCase.java    From react-native-GPay with MIT License 5 votes vote down vote up
private void scrollToDpInUIThread(final int yPositionInDP) throws Throwable {
  final ScrollView mainScrollView = getViewByTestId("scroll_view");
  runTestOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          mainScrollView.scrollTo(0, (int) PixelUtil.toPixelFromDIP(yPositionInDP));
        }
      });
  waitForBridgeAndUIIdle();
}