MCPcopy Create free account
hub / github.com/Snapchat/Valdi / getViewNodePoint

Method getViewNodePoint

valdi/src/valdi/android/NativeBridge.cpp:963–1014  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

961}
962
963jlong ValdiAndroid::NativeBridge::getViewNodePoint( // NOLINT
964 fbjni::alias_ref<fbjni::JClass> /* clazz */, // NOLINT
965 jlong runtimeHandle,
966 jlong viewNodeHandle,
967 jint x,
968 jint y,
969 jint mode,
970 jboolean fromBoundsOrigin) {
971 static constexpr jint kModeDirectionAgnosticRelative = 1;
972 static constexpr jint kModeDirectionAgnosticAbsolute = 2;
973 static constexpr jint kModeVisualRelative = 3;
974 static constexpr jint kModeVisualAbsolute = 4;
975 static constexpr jint kModeViewportRelative = 5;
976 static constexpr jint kModeViewportAbsolute = 6;
977
978 auto* runtimeWrapper = getRuntimeWrapper(runtimeHandle);
979 auto viewNode = getViewNode(viewNodeHandle);
980 if (viewNode == nullptr || runtimeWrapper == nullptr) {
981 return 0;
982 }
983
984 auto pointScale = runtimeWrapper->getPointScale();
985
986 Valdi::Point input = Valdi::Point(Valdi::pixelsToPoints(static_cast<int32_t>(x), pointScale),
987 Valdi::pixelsToPoints(static_cast<int32_t>(y), pointScale));
988
989 if (static_cast<bool>(fromBoundsOrigin)) {
990 input = input.withOffset(viewNode->getBoundsOriginPoint());
991 }
992
993 Valdi::Point output;
994
995 if (mode == kModeDirectionAgnosticRelative) {
996 output = viewNode->convertPointToRelativeDirectionAgnostic(input);
997 } else if (mode == kModeDirectionAgnosticAbsolute) {
998 output = viewNode->convertPointToAbsoluteDirectionAgnostic(input);
999 } else if (mode == kModeVisualRelative) {
1000 output = viewNode->convertSelfVisualToParentVisual(input);
1001 } else if (mode == kModeVisualAbsolute) {
1002 output = viewNode->convertSelfVisualToRootVisual(input);
1003 } else if (mode == kModeViewportRelative) {
1004 output = viewNode->getCalculatedViewport().location();
1005 } else if (mode == kModeViewportAbsolute) {
1006 auto viewportLocation = viewNode->getCalculatedViewport().location();
1007 output = viewNode->convertSelfVisualToRootVisual(viewportLocation);
1008 } else {
1009 ValdiAndroid::JavaEnv::getUnsafeEnv()->ThrowNew(
1010 ValdiAndroid::JavaEnv::getCache().getValdiExceptionClass().getClass(), "Invalid coordinate mode");
1011 }
1012
1013 return Valdi::pointsToPackedPixels(output.x, output.y, pointScale);
1014}
1015
1016jlong ValdiAndroid::NativeBridge::getViewNodeSize( // NOLINT
1017 fbjni::alias_ref<fbjni::JClass> /* clazz */, // NOLINT,

Callers

nothing calls this directly

Calls 14

getRuntimeWrapperFunction · 0.85
getViewNodeFunction · 0.85
pixelsToPointsFunction · 0.85
pointsToPackedPixelsFunction · 0.85
withOffsetMethod · 0.80
getBoundsOriginPointMethod · 0.80
locationMethod · 0.80
PointClass · 0.50
getPointScaleMethod · 0.45

Tested by

no test coverage detected