Java Code Examples for com.facebook.react.bridge.ReadableArray

The following are top voted examples for showing how to use com.facebook.react.bridge.ReadableArray. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: RNLearn_Project1   File: ExceptionsManagerModule.java   View source code 6 votes vote down vote up
private String stackTraceToString(String message, ReadableArray stack) {
  StringBuilder stringBuilder = new StringBuilder(message).append(", stack:\n");
  for (int i = 0; i < stack.size(); i++) {
    ReadableMap frame = stack.getMap(i);
    stringBuilder
        .append(frame.getString("methodName"))
        .append("@")
        .append(stackFrameToModuleId(frame))
        .append(frame.getInt("lineNumber"));
    if (frame.hasKey("column") &&
        !frame.isNull("column") &&
        frame.getType("column") == ReadableType.Number) {
      stringBuilder
          .append(":")
          .append(frame.getInt("column"));
    }
    stringBuilder.append("\n");
  }
  return stringBuilder.toString();
}
 
Example 2
Project: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   View source code 6 votes vote down vote up
public void testArrayWithMaps() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnArrayWithMaps();
  waitForBridgeAndUIIdle();

  List<ReadableArray> calls = mRecordingTestModule.getArrayCalls();
  assertEquals(1, calls.size());
  ReadableArray array = calls.get(0);
  assertEquals(2, array.size());

  assertFalse(array.isNull(0));
  ReadableMap m1 = array.getMap(0);
  ReadableMap m2 = array.getMap(1);

  assertEquals("m1v1", m1.getString("m1k1"));
  assertEquals("m1v2", m1.getString("m1k2"));
  assertEquals("m2v1", m2.getString("m2k1"));
}
 
Example 3
Project: RNLearn_Project1   File: NativeViewHierarchyManager.java   View source code 6 votes vote down vote up
/**
 * Show a {@link PopupMenu}.
 *
 * @param reactTag the tag of the anchor view (the PopupMenu is displayed next to this view); this
 *        needs to be the tag of a native view (shadow views can not be anchors)
 * @param items the menu items as an array of strings
 * @param success will be called with the position of the selected item as the first argument, or
 *        no arguments if the menu is dismissed
 */
public void showPopupMenu(int reactTag, ReadableArray items, Callback success) {
  UiThreadUtil.assertOnUiThread();
  View anchor = mTagsToViews.get(reactTag);
  if (anchor == null) {
    throw new JSApplicationIllegalArgumentException("Could not find view with tag " + reactTag);
  }
  PopupMenu popupMenu = new PopupMenu(getReactContextForView(reactTag), anchor);

  Menu menu = popupMenu.getMenu();
  for (int i = 0; i < items.size(); i++) {
    menu.add(Menu.NONE, Menu.NONE, i, items.getString(i));
  }

  PopupMenuCallbackHandler handler = new PopupMenuCallbackHandler(success);
  popupMenu.setOnMenuItemClickListener(handler);
  popupMenu.setOnDismissListener(handler);

  popupMenu.show();
}
 
Example 4
Project: RNLearn_Project1   File: StackTraceHelper.java   View source code 6 votes vote down vote up
/**
 * Convert a JavaScript stack trace (see {@code parseErrorStack} JS module) to an array of
 * {@link StackFrame}s.
 */
public static StackFrame[] convertJsStackTrace(@Nullable ReadableArray stack) {
  int size = stack != null ? stack.size() : 0;
  StackFrame[] result = new StackFrame[size];
  for (int i = 0; i < size; i++) {
    ReadableMap frame = stack.getMap(i);
    String methodName = frame.getString("methodName");
    String fileName = frame.getString("file");
    int lineNumber = -1;
    if (frame.hasKey(LINE_NUMBER_KEY) && !frame.isNull(LINE_NUMBER_KEY)) {
      lineNumber = frame.getInt(LINE_NUMBER_KEY);
    }
    int columnNumber = -1;
    if (frame.hasKey(COLUMN_KEY) && !frame.isNull(COLUMN_KEY)) {
      columnNumber = frame.getInt(COLUMN_KEY);
    }
    result[i] = new StackFrameImpl(fileName, methodName, lineNumber, columnNumber);
  }
  return result;
}
 
Example 5
Project: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   View source code 6 votes vote down vote up
public void testArrayWithMaps() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnArrayWithMaps();
  waitForBridgeAndUIIdle();

  List<ReadableArray> calls = mRecordingTestModule.getArrayCalls();
  assertEquals(1, calls.size());
  ReadableArray array = calls.get(0);
  assertEquals(2, array.size());

  assertFalse(array.isNull(0));
  ReadableMap m1 = array.getMap(0);
  ReadableMap m2 = array.getMap(1);

  assertEquals("m1v1", m1.getString("m1k1"));
  assertEquals("m1v2", m1.getString("m1k2"));
  assertEquals("m2v1", m2.getString("m2k1"));
}
 
Example 6
Project: react-native-scandit   File: ReactBridgeHelpers.java   View source code 6 votes vote down vote up
public static JSONArray convertArrayToJson(ReadableArray readableArray) throws JSONException {
    JSONArray array = new JSONArray();
    for (int i = 0; i < readableArray.size(); i++) {
        switch (readableArray.getType(i)) {
            case Null:
                break;
            case Boolean:
                array.put(readableArray.getBoolean(i));
                break;
            case Number:
                array.put(readableArray.getDouble(i));
                break;
            case String:
                array.put(readableArray.getString(i));
                break;
            case Map:
                array.put(convertMapToJson(readableArray.getMap(i)));
                break;
            case Array:
                array.put(convertArrayToJson(readableArray.getArray(i)));
                break;
        }
    }
    return array;
}
 
Example 7
Project: react-native-fast-image   File: FastImageViewModule.java   View source code 6 votes vote down vote up
@ReactMethod
public void preload(final ReadableArray sources) {
    final Activity activity = getCurrentActivity();
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < sources.size(); i++) {
                final ReadableMap source = sources.getMap(i);
                final GlideUrl glideUrl = FastImageViewConverter.glideUrl(source);
                final Priority priority = FastImageViewConverter.priority(source);
                Glide
                        .with(activity.getApplicationContext())
                        .load(glideUrl)
                        .priority(priority)
                        .placeholder(TRANSPARENT_DRAWABLE)
                        .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                        .preload();
            }
        }
    });
}
 
Example 8
Project: RNLearn_Project1   File: NativeViewHierarchyOptimizer.java   View source code 6 votes vote down vote up
/**
 * Handles a setChildren call.  This is a simplification of handleManagerChildren that only adds
 * children in index order of the childrenTags array
 */
public void handleSetChildren(
  ReactShadowNode nodeToManage,
  ReadableArray childrenTags
) {
  if (!ENABLED) {
    mUIViewOperationQueue.enqueueSetChildren(
      nodeToManage.getReactTag(),
      childrenTags);
    return;
  }

  for (int i = 0; i < childrenTags.size(); i++) {
    ReactShadowNode nodeToAdd = mShadowNodeRegistry.getNode(childrenTags.getInt(i));
    addNodeToNode(nodeToManage, nodeToAdd, i);
  }
}
 
Example 9
Project: RNLearn_Project1   File: StackTraceHelper.java   View source code 6 votes vote down vote up
/**
 * Convert a JavaScript stack trace (see {@code parseErrorStack} JS module) to an array of
 * {@link StackFrame}s.
 */
public static StackFrame[] convertJsStackTrace(@Nullable ReadableArray stack) {
  int size = stack != null ? stack.size() : 0;
  StackFrame[] result = new StackFrame[size];
  for (int i = 0; i < size; i++) {
    ReadableMap frame = stack.getMap(i);
    String methodName = frame.getString("methodName");
    String fileName = frame.getString("file");
    int lineNumber = -1;
    if (frame.hasKey(LINE_NUMBER_KEY) && !frame.isNull(LINE_NUMBER_KEY)) {
      lineNumber = frame.getInt(LINE_NUMBER_KEY);
    }
    int columnNumber = -1;
    if (frame.hasKey(COLUMN_KEY) && !frame.isNull(COLUMN_KEY)) {
      columnNumber = frame.getInt(COLUMN_KEY);
    }
    result[i] = new StackFrameImpl(fileName, methodName, lineNumber, columnNumber);
  }
  return result;
}
 
Example 10
Project: react-native-tabbed-view-pager-android   File: TabbedViewPagerManager.java   View source code 6 votes vote down vote up
@Override public void receiveCommand(TabbedViewPager viewPager, int commandType,
    @Nullable ReadableArray args) {
  Assertions.assertNotNull(viewPager);
  Assertions.assertNotNull(args);
  switch (commandType) {
    case COMMAND_SET_PAGE: {
      viewPager.setCurrentItemFromJs(args.getInt(0), true);
      return;
    }
    case COMMAND_SET_PAGE_WITHOUT_ANIMATION: {
      viewPager.setCurrentItemFromJs(args.getInt(0), false);
      return;
    }
    default:
      throw new IllegalArgumentException(
          String.format("Unsupported command %d received by %s.", commandType,
              getClass().getSimpleName()));
  }
}
 
Example 11
Project: react-native-taptargetview   File: RNTapTargetViewModule.java   View source code 6 votes vote down vote up
@ReactMethod
public void ShowSequence(final ReadableArray views, final ReadableMap props, final Promise promise) {
    final Activity activity = this.getCurrentActivity();
    final List<TapTarget> targetViews = new ArrayList<TapTarget>();

    for (int i = 0;i < views.size();i++) {
        int view = views.getInt(i);
        targetViews.add(this.generateTapTarget(view, props.getMap(String.valueOf(view))));
    }

    this.getCurrentActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            TapTargetSequence tapTargetSequence = new TapTargetSequence(activity).targets(targetViews);
            tapTargetSequence.continueOnCancel(true);
            tapTargetSequence.start();
        }
    });

}
 
Example 12
Project: react-native-sparkbutton   File: RNSparkButtonViewManager.java   View source code 6 votes vote down vote up
@Override
public void receiveCommand(
        final RNSparkButton view,
        int commandType,
        @Nullable ReadableArray args) {
    Assertions.assertNotNull(view);
    Assertions.assertNotNull(args);
    switch (commandType) {
        case COMMAND_PLAY_ANIMATION: {
            view.playAnimation();
            return;
        }

        default:
            throw new IllegalArgumentException(String.format(
                    "Unsupported command %d received by %s.",
                    commandType,
                    getClass().getSimpleName()));
    }
}
 
Example 13
Project: RNLearn_Project1   File: NativeViewHierarchyManager.java   View source code 6 votes vote down vote up
/**
 * Simplified version of manageChildren that only deals with adding children views
 */
public void setChildren(
  int tag,
  ReadableArray childrenTags) {
  ViewGroup viewToManage = (ViewGroup) mTagsToViews.get(tag);
  ViewGroupManager viewManager = (ViewGroupManager) resolveViewManager(tag);

  for (int i = 0; i < childrenTags.size(); i++) {
    View viewToAdd = mTagsToViews.get(childrenTags.getInt(i));
    if (viewToAdd == null) {
      throw new IllegalViewOperationException(
        "Trying to add unknown view tag: "
          + childrenTags.getInt(i) + "\n detail: " +
          constructSetChildrenErrorMessage(
            viewToManage,
            viewManager,
            childrenTags));
    }
    viewManager.addView(viewToManage, viewToAdd, i);
  }
}
 
Example 14
Project: RNLearn_Project1   File: NativeViewHierarchyManager.java   View source code 6 votes vote down vote up
/**
 * Simplified version of constructManageChildrenErrorMessage that only deals with adding children
 * views
 */
private static String constructSetChildrenErrorMessage(
  ViewGroup viewToManage,
  ViewGroupManager viewManager,
  ReadableArray childrenTags) {
  ViewAtIndex[] viewsToAdd = new ViewAtIndex[childrenTags.size()];
  for (int i = 0; i < childrenTags.size(); i++) {
    viewsToAdd[i] = new ViewAtIndex(childrenTags.getInt(i), i);
  }
  return constructManageChildrenErrorMessage(
    viewToManage,
    viewManager,
    null,
    viewsToAdd,
    null
  );
}
 
Example 15
Project: react-native-android-library-humaniq-api   File: ModelConverterUtils.java   View source code 6 votes vote down vote up
private static JSONArray convertArrayToJson(ReadableArray readableArray) throws JSONException {
  JSONArray array = new JSONArray();
  for (int i = 0; i < readableArray.size(); i++) {
    switch (readableArray.getType(i)) {
      case Null:
        break;
      case Boolean:
        array.put(readableArray.getBoolean(i));
        break;
      case Number:
        array.put(readableArray.getDouble(i));
        break;
      case String:
        array.put(readableArray.getString(i));
        break;
      case Map:
        array.put(convertMapToJson(readableArray.getMap(i)));
        break;
      case Array:
        array.put(convertArrayToJson(readableArray.getArray(i)));
        break;
    }
  }
  return array;
}
 
Example 16
Project: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   View source code 6 votes vote down vote up
public void testGetWrongTypeFromArray() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class)
      .returnArrayWithStringDoubleIntMapArrayBooleanNull();
  waitForBridgeAndUIIdle();

  List<ReadableArray> calls = mRecordingTestModule.getArrayCalls();
  assertEquals(1, calls.size());
  ReadableArray array = calls.get(0);

  assertUnexpectedTypeExceptionThrown(array, 0, "boolean");
  assertUnexpectedTypeExceptionThrown(array, 1, "string");
  assertUnexpectedTypeExceptionThrown(array, 2, "array");
  assertUnexpectedTypeExceptionThrown(array, 3, "double");
  assertUnexpectedTypeExceptionThrown(array, 4, "map");
  assertUnexpectedTypeExceptionThrown(array, 5, "array");
}
 
Example 17
Project: RNLearn_Project1   File: ReactViewManager.java   View source code 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 18
Project: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   View source code 6 votes vote down vote up
public void testIntOutOfRangeThrown() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnArrayWithLargeInts();
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapWithLargeInts();
  waitForBridgeAndUIIdle();

  assertEquals(1, mRecordingTestModule.getArrayCalls().size());
  assertEquals(1, mRecordingTestModule.getMapCalls().size());

  ReadableArray array = mRecordingTestModule.getArrayCalls().get(0);
  assertNotNull(array);

  ReadableMap map = mRecordingTestModule.getMapCalls().get(0);
  assertNotNull(map);

  assertEquals(ReadableType.Number, array.getType(0));
  assertUnexpectedTypeExceptionThrown(array, 0, "int");
  assertEquals(ReadableType.Number, array.getType(1));
  assertUnexpectedTypeExceptionThrown(array, 1, "int");

  assertEquals(ReadableType.Number, map.getType("first"));
  assertUnexpectedTypeExceptionThrown(map, "first", "int");
  assertEquals(ReadableType.Number, map.getType("second"));
  assertUnexpectedTypeExceptionThrown(map, "second", "int");
}
 
Example 19
Project: RNLearn_Project1   File: FrescoBasedReactTextInlineImageShadowNode.java   View source code 6 votes vote down vote up
@ReactProp(name = "src")
public void setSource(@Nullable ReadableArray sources) {
  final String source =
    (sources == null || sources.size() == 0) ? null : sources.getMap(0).getString("uri");
  Uri uri = null;
  if (source != null) {
    try {
      uri = Uri.parse(source);
      // Verify scheme is set, so that relative uri (used by static resources) are not handled.
      if (uri.getScheme() == null) {
        uri = null;
      }
    } catch (Exception e) {
      // ignore malformed uri, then attempt to extract resource ID.
    }
    if (uri == null) {
      uri = getResourceDrawableUri(getThemedContext(), source);
    }
  }
  if (uri != mUri) {
    markUpdated();
  }
  mUri = uri;
}
 
Example 20
Project: RNLearn_Project1   File: ReactViewPagerManager.java   View source code 6 votes vote down vote up
@Override
public void receiveCommand(
    ReactViewPager viewPager,
    int commandType,
    @Nullable ReadableArray args) {
  Assertions.assertNotNull(viewPager);
  Assertions.assertNotNull(args);
  switch (commandType) {
    case COMMAND_SET_PAGE: {
      viewPager.setCurrentItemFromJs(args.getInt(0), true);
      return;
    }
    case COMMAND_SET_PAGE_WITHOUT_ANIMATION: {
      viewPager.setCurrentItemFromJs(args.getInt(0), false);
      return;
    }
    default:
      throw new IllegalArgumentException(String.format(
          "Unsupported command %d received by %s.",
          commandType,
          getClass().getSimpleName()));
  }
}
 
Example 21
Project: RNLearn_Project1   File: NativeViewHierarchyManager.java   View source code 6 votes vote down vote up
/**
 * Simplified version of constructManageChildrenErrorMessage that only deals with adding children
 * views
 */
private static String constructSetChildrenErrorMessage(
  ViewGroup viewToManage,
  ViewGroupManager viewManager,
  ReadableArray childrenTags) {
  ViewAtIndex[] viewsToAdd = new ViewAtIndex[childrenTags.size()];
  for (int i = 0; i < childrenTags.size(); i++) {
    viewsToAdd[i] = new ViewAtIndex(childrenTags.getInt(i), i);
  }
  return constructManageChildrenErrorMessage(
    viewToManage,
    viewManager,
    null,
    viewsToAdd,
    null
  );
}
 
Example 22
Project: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   View source code 6 votes vote down vote up
public void testArrayOutOfBoundsExceptionThrown() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnArrayWithBasicTypes();
  waitForBridgeAndUIIdle();

  List<ReadableArray> calls = mRecordingTestModule.getArrayCalls();
  assertEquals(1, calls.size());
  ReadableArray array = calls.get(0);
  assertNotNull(array);

  assertArrayOutOfBoundsExceptionThrown(array, -1, "boolean");
  assertArrayOutOfBoundsExceptionThrown(array, -1, "string");
  assertArrayOutOfBoundsExceptionThrown(array, -1, "double");
  assertArrayOutOfBoundsExceptionThrown(array, -1, "int");
  assertArrayOutOfBoundsExceptionThrown(array, -1, "map");
  assertArrayOutOfBoundsExceptionThrown(array, -1, "array");

  assertArrayOutOfBoundsExceptionThrown(array, 10, "boolean");
  assertArrayOutOfBoundsExceptionThrown(array, 10, "string");
  assertArrayOutOfBoundsExceptionThrown(array, 10, "double");
  assertArrayOutOfBoundsExceptionThrown(array, 10, "int");
  assertArrayOutOfBoundsExceptionThrown(array, 10, "map");
  assertArrayOutOfBoundsExceptionThrown(array, 10, "array");
}
 
Example 23
Project: RNLearn_Project1   File: CatalystNativeJSToJavaParametersTestCase.java   View source code 5 votes vote down vote up
private void assertArrayOutOfBoundsExceptionThrown(
    ReadableArray array,
    int index,
    String typeToAskFor) {
  boolean gotException = false;
  try {
    arrayGetByType(array, index, typeToAskFor);
  } catch (ArrayIndexOutOfBoundsException expected) {
    gotException = true;
  }

  assertTrue(gotException);
}
 
Example 24
Project: RNLearn_Project1   File: InterpolationAnimatedNode.java   View source code 5 votes vote down vote up
private static double[] fromDoubleArray(ReadableArray ary) {
  double[] res = new double[ary.size()];
  for (int i = 0; i < res.length; i++) {
    res[i] = ary.getDouble(i);
  }
  return res;
}
 
Example 25
Project: react-native-mssql   File: ArrayUtil.java   View source code 5 votes vote down vote up
public static Object[] toArray(ReadableArray readableArray) {
  Object[] array = new Object[readableArray.size()];

  for (int i = 0; i < readableArray.size(); i++) {
    ReadableType type = readableArray.getType(i);

    switch (type) {
      case Null:
        array[i] = null;
        break;
      case Boolean:
        array[i] = readableArray.getBoolean(i);
        break;
      case Number:
        array[i] = readableArray.getDouble(i);
        break;
      case String:
        array[i] = readableArray.getString(i);
        break;
      case Map:
        array[i] = MapUtil.toMap(readableArray.getMap(i));
        break;
      case Array:
        array[i] = ArrayUtil.toArray(readableArray.getArray(i));
        break;
    }
  }

  return array;
}
 
Example 26
Project: react-native-nfc-manager   File: JsonConvert.java   View source code 5 votes vote down vote up
public static JSONArray reactToJSON(ReadableArray readableArray) throws JSONException {
    JSONArray jsonArray = new JSONArray();
    for(int i=0; i < readableArray.size(); i++) {
        ReadableType valueType = readableArray.getType(i);
        switch (valueType){
            case Null:
                jsonArray.put(JSONObject.NULL);
                break;
            case Boolean:
                jsonArray.put(readableArray.getBoolean(i));
                break;
            case Number:
                try {
                    jsonArray.put(readableArray.getInt(i));
                } catch(Exception e) {
                    jsonArray.put(readableArray.getDouble(i));
                }
                break;
            case String:
                jsonArray.put(readableArray.getString(i));
                break;
            case Map:
                jsonArray.put(reactToJSON(readableArray.getMap(i)));
                break;
            case Array:
                jsonArray.put(reactToJSON(readableArray.getArray(i)));
                break;
        }
    }
    return jsonArray;
}
 
Example 27
Project: RNLearn_Project1   File: AdditionAnimatedNode.java   View source code 5 votes vote down vote up
public AdditionAnimatedNode(
    ReadableMap config,
    NativeAnimatedNodesManager nativeAnimatedNodesManager) {
  mNativeAnimatedNodesManager = nativeAnimatedNodesManager;
  ReadableArray inputNodes = config.getArray("input");
  mInputNodes = new int[inputNodes.size()];
  for (int i = 0; i < mInputNodes.length; i++) {
    mInputNodes[i] = inputNodes.getInt(i);
  }
}
 
Example 28
Project: RNLearn_Project1   File: UIViewOperationQueue.java   View source code 5 votes vote down vote up
public ShowPopupMenuOperation(
    int tag,
    ReadableArray items,
    Callback success) {
  super(tag);
  mItems = items;
  mSuccess = success;
}
 
Example 29
Project: RNLearn_Project1   File: UIViewOperationQueue.java   View source code 5 votes vote down vote up
public void enqueueShowPopupMenu(
    int reactTag,
    ReadableArray items,
    Callback error,
    Callback success) {
  mOperations.add(new ShowPopupMenuOperation(reactTag, items, success));
}
 
Example 30
Project: RNLearn_Project1   File: NativeViewHierarchyManager.java   View source code 5 votes vote down vote up
public void dispatchCommand(int reactTag, int commandId, @Nullable ReadableArray args) {
  UiThreadUtil.assertOnUiThread();
  View view = mTagsToViews.get(reactTag);
  if (view == null) {
    throw new IllegalViewOperationException("Trying to send command to a non-existing view " +
        "with tag " + reactTag);
  }

  ViewManager viewManager = resolveViewManager(reactTag);
  viewManager.receiveCommand(view, commandId, args);
}
 
Example 31
Project: react-native-tensorflow   File: ArrayConverter.java   View source code 5 votes vote down vote up
public static long[] readableArrayToLongArray(ReadableArray readableArray) {
    long[] arr = new long[readableArray.size()];
    for (int i = 0; i < readableArray.size(); i++) {
        arr[i] = (long)readableArray.getDouble(i);
    }

    return arr;
}
 
Example 32
Project: react-native-tensorflow   File: ArrayConverter.java   View source code 5 votes vote down vote up
public static int[] readableArrayToIntArray(ReadableArray readableArray) {
    int[] arr = new int[readableArray.size()];
    for (int i = 0; i < readableArray.size(); i++) {
        arr[i] = readableArray.getInt(i);
    }

    return arr;
}
 
Example 33
Project: RNLearn_Project1   File: FlatUIViewOperationQueue.java   View source code 5 votes vote down vote up
public ViewManagerCommand(
    int reactTag,
    int command,
    @Nullable ReadableArray args) {
  mReactTag = reactTag;
  mCommand = command;
  mArgs = args;
}
 
Example 34
Project: RNLearn_Project1   File: UIManagerModule.java   View source code 5 votes vote down vote up
/**
 * Find the touch target child native view in  the supplied root view hierarchy, given a react
 * target location.
 *
 * This method is currently used only by Element Inspector DevTool.
 *
 * @param reactTag the tag of the root view to traverse
 * @param point an array containing both X and Y target location
 * @param callback will be called if with the identified child view react ID, and measurement
 *        info. If no view was found, callback will be invoked with no data.
 */
@ReactMethod
public void findSubviewIn(
    final int reactTag,
    final ReadableArray point,
    final Callback callback) {
  mUIImplementation.findSubviewIn(
    reactTag,
    Math.round(PixelUtil.toPixelFromDIP(point.getDouble(0))),
    Math.round(PixelUtil.toPixelFromDIP(point.getDouble(1))),
    callback);
}
 
Example 35
Project: RNLearn_Project1   File: UIManagerModule.java   View source code 5 votes vote down vote up
/**
 * Interface for fast tracking the initial adding of views.  Children view tags are assumed to be
 * in order
 *
 * @param viewTag the view tag of the parent view
 * @param childrenTags An array of tags to add to the parent in order
 */
@ReactMethod
public void setChildren(
  int viewTag,
  ReadableArray childrenTags) {
  if (DEBUG) {
    FLog.d(
        ReactConstants.TAG,
        "(UIManager.setChildren) tag: " + viewTag + ", children: " + childrenTags);
  }
  mUIImplementation.setChildren(viewTag, childrenTags);
}
 
Example 36
Project: react-native-geo-fence   File: RNGeoFenceModule.java   View source code 5 votes vote down vote up
/**
 * Adds a list of geofence coordinates to a list to be used for geofencing
 *
 * @param readableArray The array containing the list of geofence readableMaps to be
 *               added to geofence list
 *
 * @param geofenceRadiusInMetres geofence radius in metres
 *
 *
 * @param geofenceExpirationInMilliseconds geofence expiration time in milliseconds
 *
 */
@ReactMethod
@SuppressWarnings("unused")
public void populateGeofenceList(ReadableArray readableArray,
                                 int geofenceRadiusInMetres,
                                 int geofenceExpirationInMilliseconds) {
    if (readableArray != null) {
        for (int i = 0; i < readableArray.size(); i++) {
            ReadableMap geofence = readableArray.getMap(i);
            GlobalReadableMap.add(geofence);
            mGeofenceList.add(new Geofence.Builder()
                    // Set the request ID of the geofence. This is a string to identify this
                    // geofence.
                    .setRequestId(geofence.getString("key"))

                    // Set the circular region of this geofence.
                    .setCircularRegion(
                            geofence.getDouble("latitude"),
                            geofence.getDouble("longitude"),
                            geofenceRadiusInMetres
                    )

                    .setNotificationResponsiveness(20)

                    // Set the expiration duration of the geofence. This geofence gets automatically
                    // removed after this period of time.
                    .setExpirationDuration(geofenceExpirationInMilliseconds)

                    // Set the transition types of interest. Alerts are only generated for these transition
                    .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER |
                            Geofence.GEOFENCE_TRANSITION_EXIT)

                    // Create the geofence.
                    .build());
        }
    }
}
 
Example 37
Project: react-native-tensorflow   File: ArrayConverter.java   View source code 5 votes vote down vote up
public static ReadableArray intArrayToReadableArray(int[] arr) {
    WritableArray writableArray = new WritableNativeArray();
    for (int i : arr) {
        writableArray.pushInt(i);
    }

    return writableArray;
}
 
Example 38
Project: RNLearn_Project1   File: DebugComponentOwnershipModule.java   View source code 5 votes vote down vote up
@ReactMethod
public synchronized void receiveOwnershipHierarchy(
    int requestId,
    int tag,
    @Nullable ReadableArray owners) {
  OwnerHierarchyCallback callback = mRequestIdToCallback.get(requestId);
  if (callback == null) {
    throw new JSApplicationCausedNativeException(
        "Got receiveOwnershipHierarchy for invalid request id: " + requestId);
  }
  mRequestIdToCallback.delete(requestId);
  callback.onOwnerHierarchyLoaded(tag, owners);
}
 
Example 39
Project: react-native-ir-manager   File: RNIRManagerModule.java   View source code 5 votes vote down vote up
@ReactMethod
public void transmit(Integer carrierFrequency, ReadableArray burstsPattern, Promise promise) {
    int[] pattern = new int[burstsPattern.size()];

    for (int i = 0; i < burstsPattern.size(); i++) {
        pattern[i] = burstsPattern.getInt(i);
    }

    try {
        manager.transmit(carrierFrequency, pattern);
        promise.resolve(true);
    } catch (Exception e) {
        promise.reject(e);
    }
}
 
Example 40
Project: RNLearn_Project1   File: AsyncLocalStorageUtil.java   View source code 5 votes vote down vote up
/**
 * Build the String[] arguments needed for an SQL selection, i.e.:
 *  {a, b, c}
 * to be used in the SQL select statement: WHERE key in (?, ?, ?)
 */
/* package */ static String[] buildKeySelectionArgs(ReadableArray keys, int start, int count) {
  String[] selectionArgs = new String[count];
  for (int keyIndex = 0; keyIndex < count; keyIndex++) {
    selectionArgs[keyIndex] = keys.getString(start + keyIndex);
  }
  return selectionArgs;
}