Java Code Examples for com.facebook.infer.annotation.Assertions

The following examples show how to use com.facebook.infer.annotation.Assertions. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@Override
public void receiveCommand(RNAGSMapView mapView, int command, ReadableArray args) {
    Assertions.assertNotNull(mapView);
    Assertions.assertNotNull(args);
    switch (command) {
        case SHOW_CALLOUT: mapView.showCallout(args.getMap(0));return;
        case CENTER_MAP: mapView.centerMap(args.getArray(0));return;
        case ADD_GRAPHICS_OVERLAY: mapView.addGraphicsOverlay(args.getMap(0));return;
        case REMOVE_GRAPHICS_OVERLAY: mapView.removeGraphicsOverlay(args.getString(0));return;
        case ADD_POINTS_TO_OVERLAY: mapView.addPointsToOverlay(args.getMap(0));return;
        case REMOVE_POINTS_FROM_OVERLAY: mapView.removePointsFromOverlay(args.getMap(0));return;
        case UPDATE_POINTS_IN_GRAPHICS_OVERLAY: mapView.updatePointsInGraphicsOverlay(args.getMap(0));return;
        case ROUTE_GRAPHICS_OVERLAY: mapView.routeGraphicsOverlay(args.getMap(0));return;
        case SET_ROUTE_IS_VISIBLE: mapView.setRouteIsVisible(args.getBoolean(0));return;
        case DISPOSE: mapView.onHostDestroy();
    }
}
 
Example 2
Source Project: buck   Source File: NdkCxxPlatforms.java    License: Apache License 2.0 6 votes vote down vote up
private NdkCxxToolchainPaths(
    ProjectFilesystem filesystem,
    Path ndkRoot,
    String ndkVersion,
    NdkCxxPlatformTargetConfiguration targetConfiguration,
    String hostName,
    NdkCxxRuntime cxxRuntime,
    boolean strict,
    boolean unifiedHeaders) {
  this.filesystem = filesystem;
  this.cachedPaths = new HashMap<>();
  this.strict = strict;
  this.unifiedHeaders = unifiedHeaders;

  this.targetConfiguration = targetConfiguration;
  this.hostName = hostName;
  this.cxxRuntime = cxxRuntime;
  this.ndkRoot = ndkRoot;
  this.ndkVersion = ndkVersion;
  this.ndkMajorVersion = getNdkMajorVersion(ndkVersion);

  Assertions.assertCondition(ndkMajorVersion > 0, "Unknown ndk version: " + ndkVersion);
}
 
Example 3
protected int canvasExtent(int dstExtent, int srcExtent, int defaultExtent) {
  if (mResizeCanvasTo == null) {
    return defaultExtent;
  }

  if ("dstImage".equals(mResizeCanvasTo)) {
    return dstExtent;
  }

  if ("srcImage".equals(mResizeCanvasTo)) {
    return srcExtent;
  }

  if ("MIN".equals(mResizeCanvasTo)) {
    return Math.min(dstExtent, srcExtent);
  }

  if ("MAX".equals(mResizeCanvasTo)) {
    return Math.max(dstExtent, srcExtent);
  }

  throw Assertions.assertUnreachable(
    "ImageFilterKit: invalid property 'resizeCanvasTo' - " + mResizeCanvasTo
  );
}
 
Example 4
Source Project: react-native-3d-model-view   Source File: RN3DViewManager.java    License: MIT License 6 votes vote down vote up
@Override
public void receiveCommand(RN3DView view, int commandType, @Nullable ReadableArray args) {
  Assertions.assertNotNull(view);
  Assertions.assertNotNull(args);
  switch (commandType) {
    case COMMAND_START_ANIMATION: {
      view.setPlay(true);
      return;
    }
    case COMMAND_STOP_ANIMATION: {
      view.setPlay(false);
      return;
    }
    case COMMAND_SET_PROGRESS: {
      view.setProgress((float)args.getDouble(0));
      return;
    }
    default:
      throw new IllegalArgumentException(String.format(
              "Unsupported command %d received by %s.",
              commandType,
              getClass().getSimpleName()));
  }
}
 
Example 5
@Nullable
Postprocessor createSingular(
  @Nullable String name,
  int width,
  int height,
  @Nullable JSONObject config,
  @Nonnull Context context
) {
  @Nullable CreateSingular filter = mSingulars.get(name);

  Assertions.assertCondition(
    filter != null,
    "ImageFilterKit: Can't find '" + name + "' filter in registry."
  );

  return filter != null ? filter.create(width, height, config, context) : null;
}
 
Example 6
Source Project: react-native-image-filter-kit   Source File: ImageFilter.java    License: MIT License 6 votes vote down vote up
public void setConfig(@Nullable String config) {
  try {
    mConfig = config != null ? new JSONObject(config) : null;
  } catch (JSONException exc) {
    Assertions.assertCondition(
      false,
      "ImageFilterKit: Bad config - " + exc.getMessage()
    );
  }

  if (mIsReady) {
    sendJSEvent(ImageFilterEvent.ON_FILTERING_START, null);
    reset();
    runFilterPipeline();
  }
}
 
Example 7
@Override
public void receiveCommand(final ReactAztecText parent, int commandType, @Nullable ReadableArray args) {
    Assertions.assertNotNull(parent);
    if (commandType == COMMAND_NOTIFY_APPLY_FORMAT) {
        final String format = args.getString(0);
        Log.d(TAG, String.format("Apply format: %s", format));
        parent.applyFormat(format);
        return;
    } else if (commandType == mFocusTextInputCommandCode) {
        parent.requestFocusFromJS();
        return;
    } else if (commandType == mBlurTextInputCommandCode) {
        parent.clearFocusFromJS();
        return;
    }
    super.receiveCommand(parent, commandType, args);
}
 
Example 8
protected ReactInstanceManager createReactInstanceManager() {
    ReactInstanceManagerBuilder builder = ReactInstanceManager.builder()
            .setApplication(getApplication())
            .setJSMainModulePath(getJSMainModuleName())
            .setUseDeveloperSupport(getUseDeveloperSupport())
            .setRedBoxHandler(getRedBoxHandler())
            .setJavaScriptExecutorFactory(getJavaScriptExecutorFactory())
            .setUIImplementationProvider(getUIImplementationProvider())
            .setInitialLifecycleState(LifecycleState.BEFORE_CREATE)
            .setJSIModulesPackage(getJSIModulePackage())
            .setDevBundleDownloadListener(getDevBundleDownloadListener());

    for (ReactPackage reactPackage : getPackages()) {
        builder.addPackage(reactPackage);
    }

    String jsBundleFile = getJSBundleFile();
    if (jsBundleFile != null) {
        builder.setJSBundleFile(jsBundleFile);
    } else {
        builder.setBundleAssetName(Assertions.assertNotNull(getBundleAssetName()));
    }
    return builder.build();
}
 
Example 9
Source Project: react-native-GPay   Source File: ReactEditText.java    License: MIT License 6 votes vote down vote up
public ReactEditText(Context context) {
  super(context);
  setFocusableInTouchMode(false);

  mReactBackgroundManager = new ReactViewBackgroundManager(this);
  mInputMethodManager = (InputMethodManager)
      Assertions.assertNotNull(getContext().getSystemService(Context.INPUT_METHOD_SERVICE));
  mDefaultGravityHorizontal =
      getGravity() & (Gravity.HORIZONTAL_GRAVITY_MASK | Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK);
  mDefaultGravityVertical = getGravity() & Gravity.VERTICAL_GRAVITY_MASK;
  mNativeEventCount = 0;
  mMostRecentEventCount = 0;
  mIsSettingTextFromJS = false;
  mIsJSSettingFocus = false;
  mBlurOnSubmit = null;
  mDisableFullscreen = false;
  mListeners = null;
  mTextWatcherDelegator = null;
  mStagedInputType = getInputType();
  mKeyListener = new InternalKeyListener();
  mScrollWatcher = null;
}
 
Example 10
Source Project: react-native-GPay   Source File: EventDispatcher.java    License: MIT License 6 votes vote down vote up
/**
 * Sends the given Event to JS, coalescing eligible events if JS is backed up.
 */
public void dispatchEvent(Event event) {
  Assertions.assertCondition(event.isInitialized(), "Dispatched event hasn't been initialized");

  for (EventDispatcherListener listener : mListeners) {
    listener.onEventDispatch(event);
  }

  synchronized (mEventsStagingLock) {
    mEventStaging.add(event);
    Systrace.startAsyncFlow(
        Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
        event.getEventName(),
        event.getUniqueID());
  }
  if (mReactEventEmitter != null) {
    // If the host activity is paused, the frame callback may not be currently
    // posted. Ensure that it is so that this event gets delivered promptly.
    mCurrentFrameCallback.maybePostFromNonUI();
  } else {
    // No JS application has started yet, or resumed. This can happen when a ReactRootView is
    // added to view hierarchy, but ReactContext creation has not completed yet. In this case, any
    // touch event dispatch will hit this codepath, and we simply queue them so that they
    // are dispatched once ReactContext creation completes and JS app is running.
  }
}
 
Example 11
Source Project: react-native-GPay   Source File: ReactShadowNodeImpl.java    License: MIT License 6 votes vote down vote up
@Override
public void removeAndDisposeAllChildren() {
  if (getChildCount() == 0) {
    return;
  }

  int decrease = 0;
  for (int i = getChildCount() - 1; i >= 0; i--) {
    if (mYogaNode != null && !isYogaLeafNode()) {
      mYogaNode.removeChildAt(i);
    }
    ReactShadowNodeImpl toRemove = getChildAt(i);
    toRemove.mParent = null;
    toRemove.dispose();

    decrease += toRemove.isLayoutOnly() ? toRemove.getTotalNativeChildren() : 1;
  }
  Assertions.assertNotNull(mChildren).clear();
  markUpdated();

  mTotalNativeChildren -= decrease;
  updateNativeChildrenCountInParent(-decrease);
}
 
Example 12
Source Project: react-native-GPay   Source File: UIImplementation.java    License: MIT License 6 votes vote down vote up
private void measureLayoutRelativeToVerifiedAncestor(
    ReactShadowNode node,
    ReactShadowNode ancestor,
    int[] outputBuffer) {
  int offsetX = 0;
  int offsetY = 0;
  if (node != ancestor) {
    offsetX = Math.round(node.getLayoutX());
    offsetY = Math.round(node.getLayoutY());
    ReactShadowNode current = node.getParent();
    while (current != ancestor) {
      Assertions.assertNotNull(current);
      assertNodeDoesNotNeedCustomLayoutForChildren(current);
      offsetX += Math.round(current.getLayoutX());
      offsetY += Math.round(current.getLayoutY());
      current = current.getParent();
    }
    assertNodeDoesNotNeedCustomLayoutForChildren(ancestor);
  }

  outputBuffer[0] = offsetX;
  outputBuffer[1] = offsetY;
  outputBuffer[2] = node.getScreenWidth();
  outputBuffer[3] = node.getScreenHeight();
}
 
Example 13
protected ReactInstanceManager createReactInstanceManager() {
    ReactInstanceManagerBuilder builder = ReactInstanceManager.builder()
            .setApplication(getApplication())
            .setJSMainModulePath(getJSMainModuleName())
            .setUseDeveloperSupport(getUseDeveloperSupport())
            .setRedBoxHandler(getRedBoxHandler())
            .setJavaScriptExecutorFactory(getJavaScriptExecutorFactory())
            .setUIImplementationProvider(getUIImplementationProvider())
            .setInitialLifecycleState(LifecycleState.BEFORE_CREATE)
            .setJSIModulesPackage(getJSIModulePackage())
            .setDevBundleDownloadListener(getDevBundleDownloadListener());

    for (ReactPackage reactPackage : getPackages()) {
        builder.addPackage(reactPackage);
    }

    String jsBundleFile = getJSBundleFile();
    if (jsBundleFile != null) {
        builder.setJSBundleFile(jsBundleFile);
    } else {
        builder.setBundleAssetName(Assertions.assertNotNull(getBundleAssetName()));
    }
    return builder.build();
}
 
Example 14
Source Project: react-native-GPay   Source File: ReactViewGroup.java    License: MIT License 6 votes vote down vote up
void removeViewWithSubviewClippingEnabled(View view) {
  Assertions.assertCondition(mRemoveClippedSubviews);
  Assertions.assertNotNull(mClippingRect);
  Assertions.assertNotNull(mAllChildren);
  view.removeOnLayoutChangeListener(mChildrenLayoutChangeListener);
  int index = indexOfChildInAllChildren(view);
  if (isChildInViewGroup(mAllChildren[index])) {
    int childIndexOffset = 0;
    for (int i = 0; i < index; i++) {
      if (!isChildInViewGroup(mAllChildren[i])) {
        childIndexOffset++;
      }
    }
    super.removeViewsInLayout(index - childIndexOffset, 1);
  }
  removeFromArray(index);
}
 
Example 15
Source Project: react-native-GPay   Source File: ReactViewGroup.java    License: MIT License 6 votes vote down vote up
private void addInArray(View child, int index) {
  View[] children = Assertions.assertNotNull(mAllChildren);
  final int count = mAllChildrenCount;
  final int size = children.length;
  if (index == count) {
    if (size == count) {
      mAllChildren = new View[size + ARRAY_CAPACITY_INCREMENT];
      System.arraycopy(children, 0, mAllChildren, 0, size);
      children = mAllChildren;
    }
    children[mAllChildrenCount++] = child;
  } else if (index < count) {
    if (size == count) {
      mAllChildren = new View[size + ARRAY_CAPACITY_INCREMENT];
      System.arraycopy(children, 0, mAllChildren, 0, index);
      System.arraycopy(children, index, mAllChildren, index + 1, count - index);
      children = mAllChildren;
    } else {
      System.arraycopy(children, index, children, index + 1, count - index);
    }
    children[index] = child;
    mAllChildrenCount++;
  } else {
    throw new IndexOutOfBoundsException("index=" + index + " count=" + count);
  }
}
 
Example 16
protected ReactInstanceManager createReactInstanceManager() {
    ReactInstanceManagerBuilder builder = ReactInstanceManager.builder()
            .setApplication(getApplication())
            .setJSMainModulePath(getJSMainModuleName())
            .setUseDeveloperSupport(getUseDeveloperSupport())
            .setRedBoxHandler(getRedBoxHandler())
            .setJavaScriptExecutorFactory(getJavaScriptExecutorFactory())
            .setUIImplementationProvider(getUIImplementationProvider())
            .setInitialLifecycleState(LifecycleState.BEFORE_CREATE)
            .setJSIModulesProvider(getJSIModulesProvider())
            .setDevBundleDownloadListener(getDevBundleDownloadListener());

    for (ReactPackage reactPackage : getPackages()) {
        builder.addPackage(reactPackage);
    }

    String jsBundleFile = getJSBundleFile();
    if (jsBundleFile != null) {
        builder.setJSBundleFile(jsBundleFile);
    } else {
        builder.setBundleAssetName(Assertions.assertNotNull(getBundleAssetName()));
    }
    return builder.build();
}
 
Example 17
Source Project: react-native-GPay   Source File: UIImplementation.java    License: MIT License 6 votes vote down vote up
/**
 * Invoked by React to create a new node with a given tag, class name and properties.
 */
public void createView(int tag, String className, int rootViewTag, ReadableMap props) {
  ReactShadowNode cssNode = createShadowNode(className);
  ReactShadowNode rootNode = mShadowNodeRegistry.getNode(rootViewTag);
  Assertions.assertNotNull(rootNode, "Root node with tag " + rootViewTag + " doesn't exist");
  cssNode.setReactTag(tag);
  cssNode.setViewClassName(className);
  cssNode.setRootTag(rootNode.getReactTag());
  cssNode.setThemedContext(rootNode.getThemedContext());

  mShadowNodeRegistry.addNode(cssNode);

  ReactStylesDiffMap styles = null;
  if (props != null) {
    styles = new ReactStylesDiffMap(props);
    cssNode.updateProperties(styles);
  }

  handleCreateView(cssNode, rootViewTag, styles);
}
 
Example 18
Source Project: react-native-GPay   Source File: UIImplementation.java    License: MIT License 6 votes vote down vote up
private void assertNodeDoesNotNeedCustomLayoutForChildren(ReactShadowNode node) {
  ViewManager viewManager = Assertions.assertNotNull(mViewManagers.get(node.getViewClass()));
  ViewGroupManager viewGroupManager;
  if (viewManager instanceof ViewGroupManager) {
    viewGroupManager = (ViewGroupManager) viewManager;
  } else {
    throw new IllegalViewOperationException("Trying to use view " + node.getViewClass() +
        " as a parent, but its Manager doesn't extends ViewGroupManager");
  }
  if (viewGroupManager != null && viewGroupManager.needsCustomLayoutForChildren()) {
    throw new IllegalViewOperationException(
        "Trying to measure a view using measureLayout/measureLayoutRelativeToParent relative to" +
            " an ancestor that requires custom layout for it's children (" + node.getViewClass() +
            "). Use measure instead.");
  }
}
 
Example 19
Source Project: react-native-sketch-view   Source File: RNSketchViewManager.java    License: MIT License 6 votes vote down vote up
@Override
public void receiveCommand(SketchViewContainer root, int commandId, @Nullable ReadableArray args) {
  Assertions.assertNotNull(root);

  switch (commandId) {
    case COMMAND_CLEAR_SKETCH:
      root.sketchView.clear();
      return;
    case COMMAND_CHANGE_TOOL:
      Assertions.assertNotNull(args);
      int toolId = args.getInt(0);
      root.sketchView.setToolType(toolId);
      return;
    case COMMAND_SAVE_SKETCH:
      try {
        SketchFile sketchFile = root.saveToLocalCache();
        onSaveSketch(root, sketchFile);
        return;
      } catch (IOException e) {
        e.printStackTrace();
      }
    default:
      throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Unsupported command %d.", commandId));
  }
}
 
Example 20
Source Project: react-native-GPay   Source File: ReactShadowNodeImpl.java    License: MIT License 6 votes vote down vote up
@Override
public ReactShadowNodeImpl mutableCopy(long instanceHandle) {
  ReactShadowNodeImpl copy = copy();
  Assertions.assertCondition(
      getClass() == copy.getClass(),
      "Copied shadow node must use the same class");
  copy.mInstanceHandle = instanceHandle;
  if (mYogaNode != null) {
    copy.mYogaNode = mYogaNode.clone();
    copy.mYogaNode.setData(copy);
  } else {
    // Virtual ReactShadowNode do not have a YogaNode associated
    copy.mYogaNode = null;
  }
  copy.mTotalNativeChildren = mTotalNativeChildren;
  copy.mNativeChildren = copyChildren(mNativeChildren);
  copy.mChildren = copyChildren(mChildren);

  return copy;
}
 
Example 21
Source Project: react-native-shake   Source File: CustomShakeDetector.java    License: MIT License 6 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
  if (sensorEvent.timestamp - mLastTimestamp < MIN_TIME_BETWEEN_SAMPLES_NS) {
    return;
  }

  Assertions.assertNotNull(mTimestamps);
  Assertions.assertNotNull(mMagnitudes);

  float ax = sensorEvent.values[0];
  float ay = sensorEvent.values[1];
  float az = sensorEvent.values[2];

  mLastTimestamp = sensorEvent.timestamp;
  mTimestamps[mCurrentIndex] = sensorEvent.timestamp;
  mMagnitudes[mCurrentIndex] = Math.sqrt(ax * ax + ay * ay + az * az);

  maybeDispatchShake(sensorEvent.timestamp);

  mCurrentIndex = (mCurrentIndex + 1) % MAX_SAMPLES;
}
 
Example 22
Source Project: react-native-GPay   Source File: HeadlessJsTaskContext.java    License: MIT License 6 votes vote down vote up
/**
 * Finish a JS task. Doesn't actually stop the task on the JS side, only removes it from the list
 * of active tasks and notifies listeners. A task can only be finished once.
 *
 * @param taskId the unique id returned by {@link #startTask}.
 */
public synchronized void finishTask(final int taskId) {
  Assertions.assertCondition(
    mActiveTasks.remove(taskId),
    "Tried to finish non-existent task with id " + taskId + ".");
  Runnable timeout = mTaskTimeouts.get(taskId);
  if (timeout != null) {
    mHandler.removeCallbacks(timeout);
    mTaskTimeouts.remove(taskId);
  }
  UiThreadUtil.runOnUiThread(new Runnable() {
    @Override
    public void run() {
      for (HeadlessJsTaskEventListener listener : mHeadlessJsTaskEventListeners) {
        listener.onHeadlessJsTaskFinish(taskId);
      }
    }
  });
}
 
Example 23
@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 24
Source Project: react-native-GPay   Source File: CatalystInstanceImpl.java    License: MIT License 6 votes vote down vote up
/**
 * Initialize all the native modules
 */
@VisibleForTesting
@Override
public void initialize() {
  Log.d(ReactConstants.TAG, "CatalystInstanceImpl.initialize()");
  Assertions.assertCondition(
      !mInitialized,
      "This catalyst instance has already been initialized");
  // We assume that the instance manager blocks on running the JS bundle. If
  // that changes, then we need to set mAcceptCalls just after posting the
  // task that will run the js bundle.
  Assertions.assertCondition(
      mAcceptCalls,
      "RunJSBundle hasn't completed.");
  mInitialized = true;
  mNativeModulesQueueThread.runOnQueue(new Runnable() {
    @Override
    public void run() {
      mNativeModuleRegistry.notifyJSInstanceInitialized();
    }
  });
}
 
Example 25
Source Project: react-native-GPay   Source File: JSTouchDispatcher.java    License: MIT License 6 votes vote down vote up
private void dispatchCancelEvent(MotionEvent androidEvent, EventDispatcher eventDispatcher) {
  // This means the gesture has already ended, via some other CANCEL or UP event. This is not
  // expected to happen very often as it would mean some child View has decided to intercept the
  // touch stream and start a native gesture only upon receiving the UP/CANCEL event.
  if (mTargetTag == -1) {
    FLog.w(
      ReactConstants.TAG,
      "Can't cancel already finished gesture. Is a child View trying to start a gesture from " +
        "an UP/CANCEL event?");
    return;
  }

  Assertions.assertCondition(
    !mChildIsHandlingNativeGesture,
    "Expected to not have already sent a cancel for this gesture");
  Assertions.assertNotNull(eventDispatcher).dispatchEvent(
    TouchEvent.obtain(
      mTargetTag,
      TouchEventType.CANCEL,
      androidEvent,
      mGestureStartTime,
      mTargetCoordinates[0],
      mTargetCoordinates[1],
      mTouchEventCoalescingKeyHelper));
}
 
Example 26
Source Project: react-native-GPay   Source File: ReadableNativeMap.java    License: MIT License 6 votes vote down vote up
private HashMap<String,Object> getLocalMap() {
  // Fast return for the common case
  if (mLocalMap != null) {
    return mLocalMap;
  }
  // Check and when necessary get keys atomicaly
  synchronized (this) {
    if (mKeys == null) {
      mKeys = Assertions.assertNotNull(importKeys());
      mJniCallCounter++;
    }
    if (mLocalMap == null) {
      Object[] values = Assertions.assertNotNull(importValues());
      mJniCallCounter++;
      mLocalMap = new HashMap<>();
      for(int i = 0; i< mKeys.length; i++) {
        mLocalMap.put(mKeys[i], values[i]);
      }
    }
  }
  return mLocalMap;
}
 
Example 27
Source Project: react-native-GPay   Source File: ReadableNativeMap.java    License: MIT License 6 votes vote down vote up
private HashMap<String,ReadableType> getLocalTypeMap() {
  // Fast and non-blocking return for common case
  if (mLocalTypeMap != null) {
    return mLocalTypeMap;
  }
  // Check and when necessary get keys
  synchronized (this) {
    if (mKeys == null) {
      mKeys = Assertions.assertNotNull(importKeys());
      mJniCallCounter++;
    }
    // check that no other thread has already updated
    if (mLocalTypeMap == null) {
      Object[] types = Assertions.assertNotNull(importTypes());
      mJniCallCounter++;
      mLocalTypeMap = new HashMap<>();
      for(int i = 0; i< mKeys.length; i++) {
        mLocalTypeMap.put(mKeys[i], (ReadableType) types[i]);
      }
    }
  }
  return mLocalTypeMap;
}
 
Example 28
Source Project: react-native-GPay   Source File: ReactShadowNodeImpl.java    License: MIT License 6 votes vote down vote up
@Override
public ReactShadowNodeImpl mutableCopyWithNewChildren(long instanceHandle) {
  ReactShadowNodeImpl copy = copy();
  copy.mInstanceHandle = instanceHandle;
  Assertions.assertCondition(
      getClass() == copy.getClass(),
      "Copied shadow node must use the same class");
  if (mYogaNode != null) {
    copy.mYogaNode = mYogaNode.cloneWithNewChildren();
    copy.mYogaNode.setData(copy);
  } else {
    // Virtual ReactShadowNode do not have a YogaNode associated
    copy.mYogaNode = null;
  }
  copy.mNativeChildren = null;
  copy.mChildren = null;
  copy.mTotalNativeChildren = 0;
  return copy;
}
 
Example 29
Source Project: react-native-GPay   Source File: HeadlessJsTaskContext.java    License: MIT License 6 votes vote down vote up
/**
 * Start a JS task. Handles invoking {@link AppRegistry#startHeadlessTask} and notifying
 * listeners.
 *
 * @return a unique id representing this task instance.
 */
public synchronized int startTask(final HeadlessJsTaskConfig taskConfig) {
  UiThreadUtil.assertOnUiThread();
  ReactContext reactContext = Assertions.assertNotNull(
    mReactContext.get(),
    "Tried to start a task on a react context that has already been destroyed");
  if (reactContext.getLifecycleState() == LifecycleState.RESUMED &&
    !taskConfig.isAllowedInForeground()) {
    throw new IllegalStateException(
      "Tried to start task " + taskConfig.getTaskKey() +
        " while in foreground, but this is not allowed.");
  }
  final int taskId = mLastTaskId.incrementAndGet();
  mActiveTasks.add(taskId);
  reactContext.getJSModule(AppRegistry.class)
    .startHeadlessTask(taskId, taskConfig.getTaskKey(), taskConfig.getData());
  if (taskConfig.getTimeout() > 0) {
    scheduleTaskTimeout(taskId, taskConfig.getTimeout());
  }
  for (HeadlessJsTaskEventListener listener : mHeadlessJsTaskEventListeners) {
    listener.onHeadlessJsTaskStart(taskId);
  }
  return taskId;
}
 
Example 30
Source Project: react-native-GPay   Source File: TouchEvent.java    License: MIT License 6 votes vote down vote up
@Override
public boolean canCoalesce() {
  // We can coalesce move events but not start/end events. Coalescing move events should probably
  // append historical move data like MotionEvent batching does. This is left as an exercise for
  // the reader.
  switch (Assertions.assertNotNull(mTouchEventType)) {
    case START:
    case END:
    case CANCEL:
      return false;
    case MOVE:
      return true;
    default:
      throw new RuntimeException("Unknown touch event type: " + mTouchEventType);
  }
}